aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjaseg <git@jaseg.net>2017-11-26 12:26:06 +0100
committerjaseg <git@jaseg.net>2017-11-26 12:58:57 +0100
commite864cde5968ea9c35bf521358a74b20385ac8567 (patch)
tree8034f5d3f29043319b6565438e6cc43e9ef1827e
parentb0df323c11667444e7b630610c282b42a93d71ca (diff)
downloadgerbolyze-e864cde5968ea9c35bf521358a74b20385ac8567.tar.gz
gerbolyze-e864cde5968ea9c35bf521358a74b20385ac8567.tar.bz2
gerbolyze-e864cde5968ea9c35bf521358a74b20385ac8567.zip
Make backup file logic smarter
Automatically re-use an existing target layer backup file in subsequent runs instead of using a previous run's output. I.e., if the target extension is set to ".GTO" and both "foo.GTO" and "foo.GTO.bak" exist, automatically use "foo.GTO.bak" and write to "foo.GTO". This behavior can be overridden by stating an explicit filename.
-rwxr-xr-xgerbimg.py18
1 files changed, 12 insertions, 6 deletions
diff --git a/gerbimg.py b/gerbimg.py
index 4bfdac4..d3ed7f9 100755
--- a/gerbimg.py
+++ b/gerbimg.py
@@ -58,7 +58,7 @@ def paste_image(
status_print(' * target layer')
ctx.render_layer(target, settings=fg, bgsettings=bg)
for fn, sub in subtract_gerber:
- status_print(' * extra layer', fn)
+ status_print(' * extra layer', os.path.basename(fn))
layer = gerber.loads(sub)
ctx.render_layer(layer, settings=fg, bgsettings=bg)
status_print('Rendering keepout composite')
@@ -210,14 +210,20 @@ def replace_file_in_zip(zip_path, filename, contents):
def paste_image_file(zip_or_dir, target, outline, source_img, subtract=[], status_print=lambda *args:None, debugdir=None):
if path.isdir(zip_or_dir):
tname, target = find_gerber_in_dir(zip_or_dir, target)
- _fn, outline = find_gerber_in_dir(zip_or_dir, outline)
+ status_print('Target layer file {}'.format(os.path.basename(tname)))
+ oname, outline = find_gerber_in_dir(zip_or_dir, outline)
+ status_print('Outline layer file {}'.format(os.path.basename(oname)))
subtract = [ (fn, layer) for fn, layer in (find_gerber_in_dir(zip_or_dir, elem) for elem in subtract) ]
out = paste_image(target, outline, source_img, subtract, debugdir=debugdir, status_print=status_print)
- shutil.copy(tname, tname+'.bak')
- with open(tname, 'w') as f:
- f.write(out)
+ if not tname.endswith('.bak'):
+ shutil.copy(tname, tname+'.bak')
+ with open(tname, 'w') as f:
+ f.write(out)
+ else:
+ with open(tname[:-4], 'w') as f:
+ f.write(out)
elif zipfile.is_zipfile(zip_or_dir):
_fn, outline = find_gerber_in_zip(zip_or_dir, outline)
subtract = [ (fn, layer) for fn, layer in (find_gerber_in_zip(zip_or_dir, elem) for elem in subtract) ]
@@ -243,7 +249,7 @@ if __name__ == '__main__':
args = parser.parse_args()
if not args.target:
- args.target = '.GBO' if args.bottom else '.GTO'
+ args.target = '.GBO.bak,.GBO' if args.bottom else '.GTO.bak,.GTO'
if not args.subtract:
args.subtract = ['.GBS', '.TXT'] if args.bottom else ['.GTS', '.TXT']