Skip to content

Commit

Permalink
change: Use template for filename
Browse files Browse the repository at this point in the history
  • Loading branch information
bofh69 committed Mar 14, 2024
1 parent e76d695 commit 5b3bb09
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
20 changes: 12 additions & 8 deletions spoolman2slicer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

from jinja2 import Environment, FileSystemLoader, TemplateNotFound
import requests

from websockets.client import connect

DEFAULT_TEMPLATE = "default.template"
FILENAME_TEMPLATE = "filename.template"

ORCASLICER = "orcaslicer"
PRUSASLICER = "prusaslicer"
Expand Down Expand Up @@ -108,7 +108,8 @@ def load_filaments(url: str):

def get_filament_filename(filament):
"""Returns the filament's config filename"""
return f"{args.dir}/{filament['vendor']['name']}-{filament['name']}.{get_config_suffix()}"
template = templates.get_template(FILENAME_TEMPLATE)
return args.dir + "/" + template.render(filament)


def delete_filament(filament):
Expand All @@ -130,6 +131,15 @@ def delete_all_filaments():

def write_filament(filament):
"""Output the filament to the right file"""

sm2s = {
"name": parser.prog,
"version": VERSION,
"now": time.asctime(),
"slicer_suffix": get_config_suffix(),
}
filament["sm2s"] = sm2s

filename = get_filament_filename(filament)

filament_id_to_filename[filament["id"]] = filename
Expand All @@ -148,12 +158,6 @@ def write_filament(filament):
if args.verbose:
print("Using the default template")

sm2s = {
"name": parser.prog,
"version": VERSION,
"now": time.asctime(),
}
filament["sm2s"] = sm2s
print(f"Writing to: {filename}")

if args.verbose:
Expand Down
1 change: 1 addition & 0 deletions templates-orcaslicer/filename.template
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{vendor.name}} - {{name}}.{{sm2s.slicer_suffix}}
1 change: 1 addition & 0 deletions templates-superslicer/filename.template
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{vendor.name}} - {{name}}.{{sm2s.slicer_suffix}}

0 comments on commit 5b3bb09

Please sign in to comment.