diff options
author | Michael Schwarz <michi.schwarz@gmail.com> | 2017-09-20 20:33:29 +0200 |
---|---|---|
committer | Michael Schwarz <michi.schwarz@gmail.com> | 2017-09-20 20:33:29 +0200 |
commit | 3566dbc9438935d7cc6951a882a9d2ca148fb58d (patch) | |
tree | 6680102d912bed0e2eb528c06e09fecc876fd96b /support/openscad | |
parent | 673a546066aed704d7087740a4190a023a7c9220 (diff) | |
download | pogojig-3566dbc9438935d7cc6951a882a9d2ca148fb58d.tar.gz pogojig-3566dbc9438935d7cc6951a882a9d2ca148fb58d.tar.bz2 pogojig-3566dbc9438935d7cc6951a882a9d2ca148fb58d.zip |
PEP8
Diffstat (limited to 'support/openscad')
-rw-r--r-- | support/openscad/__main__.py | 70 |
1 files changed, 37 insertions, 33 deletions
diff --git a/support/openscad/__main__.py b/support/openscad/__main__.py index 7aeaa31..85f8b99 100644 --- a/support/openscad/__main__.py +++ b/support/openscad/__main__.py @@ -1,42 +1,46 @@ import os + from lib import util, make def _openscad(in_path, out_path, deps_path): - util.command([os.environ['OPENSCAD'], '-o', out_path, '-d', deps_path, in_path]) + util.command([os.environ['OPENSCAD'], '-o', out_path, '-d', deps_path, in_path]) @util.main def main(in_path, out_path): - cwd = os.getcwd() - - def relpath(path): - return os.path.relpath(path, cwd) - - with util.TemporaryDirectory() as temp_dir: - temp_deps_path = os.path.join(temp_dir, 'deps') - temp_mk_path = os.path.join(temp_dir, 'mk') - temp_files_path = os.path.join(temp_dir, 'files') - - _, out_ext = os.path.splitext(out_path) - - # OpenSCAD requires the output file name to end in .stl or .dxf. - temp_out_path = os.path.join(temp_dir, 'out' + out_ext) - - _openscad(in_path, temp_out_path, temp_deps_path) - - mk_content = '%:; echo "$@" >> {}'.format(util.bash_escape_string(temp_files_path)) - - # Use make to parse the dependency makefile written by OpenSCAD. - util.write_file(temp_mk_path, mk_content.encode()) - util.command(['make', '-s', '-B', '-f', temp_mk_path, '-f', temp_deps_path], remove_env = ['MAKELEVEL', 'MAKEFLAGS']) - - # All dependencies as paths relative to the project root. - deps = set(map(relpath, util.read_file(temp_files_path).decode().splitlines())) - - # Relative paths to all files that should not appear in the dependency makefile. - ignored_files = set(map(relpath, [in_path, temp_deps_path, temp_mk_path, temp_out_path])) - - # Write output files. - make.write_dependencies(out_path + '.d', out_path, deps - ignored_files) - util.rename_atomic(temp_out_path, out_path) + cwd = os.getcwd() + + def relpath(path): + return os.path.relpath(path, cwd) + + with util.TemporaryDirectory() as temp_dir: + temp_deps_path = os.path.join(temp_dir, 'deps') + temp_mk_path = os.path.join(temp_dir, 'mk') + temp_files_path = os.path.join(temp_dir, 'files') + + _, out_ext = os.path.splitext(out_path) + + # OpenSCAD requires the output file name to end in .stl or .dxf. + temp_out_path = os.path.join(temp_dir, 'out' + out_ext) + + _openscad(in_path, temp_out_path, temp_deps_path) + + mk_content = '%:; echo "$@" >> {}'.format(util.bash_escape_string(temp_files_path)) + + # Use make to parse the dependency makefile written by OpenSCAD. + util.write_file(temp_mk_path, mk_content.encode()) + util.command( + ['make', '-s', '-B', '-f', temp_mk_path, '-f', temp_deps_path], + remove_env=['MAKELEVEL', 'MAKEFLAGS']) + + # All dependencies as paths relative to the project root. + deps = set(map(relpath, util.read_file(temp_files_path).decode().splitlines())) + + # Relative paths to all files that should not appear in the + # dependency makefile. + ignored_files = set(map(relpath, [in_path, temp_deps_path, temp_mk_path, temp_out_path])) + + # Write output files. + make.write_dependencies(out_path + '.d', out_path, deps - ignored_files) + util.rename_atomic(temp_out_path, out_path) |