Skip to content

Commit

Permalink
Start to support more slicers
Browse files Browse the repository at this point in the history
  • Loading branch information
bofh69 committed Mar 4, 2024
1 parent 79ec8ed commit 498bd4d
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 18 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Spoolman to Superslicer filament transfer
# Spoolman to slicer filament transfer
Create [SuperSlicer](https://github.com/supermerill/SuperSlicer) filament configuration from the filaments in [Spoolman](https://github.com/Donkie/Spoolman).

## Prepare for running
Expand All @@ -11,15 +11,15 @@ pip install -r requirements.txt
```

## Config file templates
spoolman2superslicer uses [Jinja2](https://palletsprojects.com/p/jinja/) templates for the configuration files
spoolman2slicer uses [Jinja2](https://palletsprojects.com/p/jinja/) templates for the configuration files
it creates. They are stored with the filaments' material's name in
`templates/`. If the material's template isn't found,
`default.template` is used.

## Run

```sh
./spoolman2superslicer.py -d ~/.config/SuperSlicer/filament/
./spoolman2slicer.py -d ~/.config/SuperSlicer/filament/
```

If `-D` is given, all ini files are removed in the directory before
Expand Down
55 changes: 40 additions & 15 deletions spoolman2superslicer.py → spoolman2slicer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,47 +18,72 @@

DEFAULT_TEMPLATE = "default.template"

id_to_filename = {}
ORCASLICER = "orcaslicer"
PRUSASLICER = "prusaslicer"
SLICER = "sl1cer"
SUPERSLICER = "superslicer"

loader = FileSystemLoader("templates")
env = Environment(loader=loader)
id_to_filename = {}

parser = argparse.ArgumentParser(
description="Fetches filaments from Spoolman and creates SuperSlicer filament configs.",
)

parser.add_argument("--version", action="version", version="%(prog)s 0.0.1")
parser.add_argument(
"-d",
"--dir",
metavar="DIR",
required=True,
help="the filament config dir",
)

parser.add_argument(
"-s",
"--slicer",
default=SUPERSLICER,
choices=[ORCASLICER, PRUSASLICER, SLICER, SUPERSLICER],
help="the slicer",
)

parser.add_argument(
"-u",
"--url",
metavar="URL",
default="http://mainsailos.local:7912",
help="URL for the Spoolman installation",
)
parser.add_argument(
"-d",
"--dir",
metavar="DIR",
required=True,
help="SuperSlicer's filament config dir",
)

parser.add_argument(
"-U",
"--updates",
action="store_true",
help="Keep running and update filament configs if they're updated in Spoolman",
help="keep running and update filament configs if they're updated in Spoolman",
)

parser.add_argument(
"-D",
"--delete-all",
action="store_true",
help="Delete all filaments before adding existing ones",
help="delete all filament configs before adding existing ones",
)

args = parser.parse_args()

loader = FileSystemLoader("templates-" + args.slicer)
env = Environment(loader=loader)


def get_config_suffix():
"""Returns the slicer's config file prefix"""
if args.slicer == SUPERSLICER:
return "ini"
elif args.slicer == ORCASLICER:
return "json"
else:
# I don't know...
print("That slicer is not yet supported")


def load_filaments(url: str):
"""Load filaments json data from Spoolman"""
Expand All @@ -68,7 +93,7 @@ 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']}.ini"
return f"{args.dir}/{filament['vendor']['name']}-{filament['name']}.{get_config_suffix()}"


def delete_filament(filament):
Expand All @@ -80,9 +105,9 @@ def delete_filament(filament):


def delete_all_filaments():
"""Delete all .ini files in the filament dir"""
"""Delete all config files in the filament dir"""
for filename in os.listdir(args.dir):
if filename.endswith(".ini"):
if filename.endswith("." + get_config_suffix()):
filename = args.dir + "/" + filename
print(f"Deleting: {filename}")
os.remove(filename)
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 498bd4d

Please sign in to comment.