-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add mkdocs eva badge plugin, add eva macros, add stl unpacker
- Loading branch information
Showing
7 changed files
with
318 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = '0.1.0' | ||
__version__ = "0.1.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,51 @@ | ||
import csv | ||
from pathlib import Path | ||
import shutil | ||
import zipfile | ||
|
||
import click | ||
|
||
|
||
@click.group() | ||
def main(): | ||
pass | ||
|
||
|
||
@main.command() | ||
@click.argument('bom-file', type=click.File('rb')) | ||
def parse_bom(bom_file): | ||
@click.argument("bom-file", type=click.File("r")) | ||
@click.argument("zip-file", type=click.Path(exists=True)) | ||
@click.argument("stl-out-dir", type=click.Path()) | ||
def unpack_stls(bom_file, zip_file, stl_out_dir): | ||
files = set() | ||
reader = csv.DictReader(bom_file, delimiter=",", quotechar='"') | ||
for row in reader: | ||
if "Material" not in row: | ||
raise Exception("export a BOM with a material column") | ||
if "Name" not in row: | ||
raise Exception("export a BOM with a name column") | ||
if row["Material"].upper() == "PETG": | ||
files.add(f"{row['Name']}.stl") | ||
|
||
stl_out_dir = Path(stl_out_dir) | ||
# if Path(stl_out_dir).exists(): | ||
# shutil.rmtree(stl_out_dir) | ||
stl_out_dir.mkdir(exist_ok=True) | ||
|
||
with zipfile.ZipFile(zip_file, 'r') as zip_ref: | ||
for file_name in zip_ref.namelist(): | ||
for target_file in files: | ||
if target_file in file_name: | ||
zip_ref.extract(file_name, stl_out_dir) | ||
|
||
for stl_file in stl_out_dir.iterdir(): | ||
try: | ||
new_name = stl_file.name.split(" - ")[1] | ||
except IndexError: | ||
continue | ||
stl_file.rename(Path(stl_file.parent, new_name)) | ||
|
||
print("works!") | ||
|
||
|
||
if __name__ == '__main__': | ||
main(prog_name='python -m eva-3d') | ||
if __name__ == "__main__": | ||
main(prog_name="python -m eva-3d") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from mkdocs.plugins import BasePlugin | ||
|
||
|
||
class EVAPlugin(BasePlugin): | ||
def on_page_markdown(self, markdown, page, config, files): | ||
for badge in page.meta.get("badges", []): | ||
markdown = f'<button class="badge md-button md-button-small md-button--primary">{badge}</button>\n{markdown}' | ||
return markdown |
Oops, something went wrong.