diff options
author | Michael Schwarz <michi.schwarz@gmail.com> | 2014-12-10 22:18:14 +0100 |
---|---|---|
committer | Michael Schwarz <michi.schwarz@gmail.com> | 2014-12-10 22:18:14 +0100 |
commit | 60b25ad13d0fdee926006bc728b031c4da1fb931 (patch) | |
tree | f3c7a1ca6be13e16ab60c991bd536dd025ed0e7d | |
parent | 8e5a1520cd5e901f514c382ad17e77d64727896a (diff) | |
download | pogojig-60b25ad13d0fdee926006bc728b031c4da1fb931.tar.gz pogojig-60b25ad13d0fdee926006bc728b031c4da1fb931.tar.bz2 pogojig-60b25ad13d0fdee926006bc728b031c4da1fb931.zip |
Extracted common functions to separate module.
-rw-r--r-- | support/dxf_export/__main__.py | 26 | ||||
-rw-r--r-- | support/lib/__init__.py | 0 | ||||
-rw-r--r-- | support/lib/util.py | 18 |
3 files changed, 23 insertions, 21 deletions
diff --git a/support/dxf_export/__main__.py b/support/dxf_export/__main__.py index ea6c7ad..76c2121 100644 --- a/support/dxf_export/__main__.py +++ b/support/dxf_export/__main__.py @@ -1,15 +1,6 @@ -import sys, os, xml.etree.ElementTree, subprocess, tempfile, contextlib, shutil -import better_dxf_outlines - - -@contextlib.contextmanager -def TemporaryDirectory(): - dir = tempfile.mkdtemp() - - try: - yield dir - finally: - shutil.rmtree(dir) +import sys, os, xml.etree.ElementTree, shutil +from lib import util +from . import better_dxf_outlines def _export_dxf(in_path, out_path): @@ -28,13 +19,6 @@ def _get_inkscape_layer_count(svg_path): return len(layers) -def _command(args): - process = subprocess.Popen(args) - process.wait() - - assert not process.returncode - - def _inkscape(svg_path, verbs): def iter_args(): yield os.environ['INKSCAPE'] @@ -45,7 +29,7 @@ def _inkscape(svg_path, verbs): yield svg_path - _command(list(iter_args())) + util.command(list(iter_args())) def _unfuck_svg_document(temp_svg_path): @@ -82,7 +66,7 @@ def _unfuck_svg_document(temp_svg_path): def main(in_path, out_path): - with TemporaryDirectory() as temp_dir: + with util.TemporaryDirectory() as temp_dir: temp_svg_path = os.path.join(temp_dir, 'temp.svg') shutil.copyfile(in_path, temp_svg_path) diff --git a/support/lib/__init__.py b/support/lib/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/support/lib/__init__.py diff --git a/support/lib/util.py b/support/lib/util.py new file mode 100644 index 0000000..a3bc3dc --- /dev/null +++ b/support/lib/util.py @@ -0,0 +1,18 @@ +import contextlib, subprocess, tempfile, shutil + + +@contextlib.contextmanager +def TemporaryDirectory(): + dir = tempfile.mkdtemp() + + try: + yield dir + finally: + shutil.rmtree(dir) + + +def command(args): + process = subprocess.Popen(args) + process.wait() + + assert not process.returncode |