From 6571061ef336c85ee31e1468cef63930523ff381 Mon Sep 17 00:00:00 2001 From: Juliean Date: Sun, 6 Jan 2019 11:20:10 -0500 Subject: [PATCH 1/3] Updated for Python 3.6.5 on Win10 --- scripts/adda.py | 4 +-- scripts/animate.py | 20 +++++++------- scripts/assemblies.py | 12 ++++----- scripts/build.py | 14 +++++----- scripts/c14n_stl.py | 2 +- scripts/catalogue.py | 20 +++++++------- scripts/cut.py | 10 +++---- scripts/guides.py | 18 ++++++------- scripts/jsontools.py | 2 +- scripts/machines.py | 10 +++---- scripts/openscad.py | 4 +-- scripts/parse.py | 56 ++++++++++++++++++++-------------------- scripts/printed.py | 20 +++++++------- scripts/slic3r.py | 2 +- scripts/startaproject.py | 8 +++--- scripts/static.py | 2 +- scripts/syntax.py | 6 ++--- scripts/views.py | 25 +++++++++++++----- scripts/vitamins.py | 10 +++---- 19 files changed, 128 insertions(+), 117 deletions(-) diff --git a/scripts/adda.py b/scripts/adda.py index e59641d..8858807 100755 --- a/scripts/adda.py +++ b/scripts/adda.py @@ -77,7 +77,7 @@ def adda(t, n, d): o.write("include <"+incFile+">\n") else: - print(templateFile + " template is missing") + print((templateFile + " template is missing")) # Sandbox templateFile = os.path.join(config.paths['template'],"sandbox","sandbox.scad") @@ -93,7 +93,7 @@ def adda(t, n, d): o.write(s) else: - print(templateFile + " template is missing") + print((templateFile + " template is missing")) if __name__ == '__main__': diff --git a/scripts/animate.py b/scripts/animate.py index dfea814..0e62e07 100755 --- a/scripts/animate.py +++ b/scripts/animate.py @@ -57,8 +57,8 @@ def animateAssembly(mname, aname, prefix, framesPerStep): # locate required machine for m in jso: - if type(m) is DictType and m['type'] == 'machine' and m['title'] == mname: - print("Found machine: "+m['title']) + if type(m) is dict and m['type'] == 'machine' and m['title'] == mname: + print(("Found machine: "+m['title'])) al = m['assemblies'] @@ -70,7 +70,7 @@ def animateAssembly(mname, aname, prefix, framesPerStep): # locate required assembly for a in al: if a['title'] == aname: - print("Found assembly: "+a['title']) + print(("Found assembly: "+a['title'])) fn = config.paths['root'] + a['file'] if (os.path.isfile(fn)): @@ -94,7 +94,7 @@ def animateAssembly(mname, aname, prefix, framesPerStep): } firstView = True for step in a['steps']: - print("Step: "+str(step['num'])) + print(("Step: "+str(step['num']))) # generate a transition move? if len(step['views']) > 0: @@ -177,7 +177,7 @@ def animateAssembly(mname, aname, prefix, framesPerStep): views.PolishTransparentBackground = False views.PolishCrop = False fn = view_dir + "/" +prefix + format(frameNum, '03') + "_" +view['title']+".png" - print("Rendering: "+fn) + print(("Rendering: "+fn)) views.render_view_using_file(prefix + format(frameNum, '03'), config.paths['tempscad'], view_dir, view, hashchanged, h) frameNum = frameNum + 1 @@ -199,7 +199,7 @@ def animateAssembly(mname, aname, prefix, framesPerStep): alpha = extra / (1.0*framesPerStep) if (alpha > 1.0): alpha = 1.0 - print("Blending: "+str(alpha) +", "+str(frameNum)) + print(("Blending: "+str(alpha) +", "+str(frameNum))) imgNew = Image.blend(imgPrev,img,alpha) draw = ImageDraw.Draw(imgNew, "RGBA") @@ -219,7 +219,7 @@ def animateAssembly(mname, aname, prefix, framesPerStep): fn = view_dir + "/" +prefix + format(frameNum, '03') + "_" +view['title']+".png" frameNum = frameNum + 1 - print("Saving: "+fn) + print(("Saving: "+fn)) imgNew.save(fn) lfn = fn @@ -262,12 +262,12 @@ def animateAssembly(mname, aname, prefix, framesPerStep): # build video cmd = "ffmpeg -r "+str(framesPerStep)+" -y -i "+view_dir + "/" + prefix+"%03d_"+view['title']+".png -vcodec libx264 -pix_fmt yuv420p "+view_dir + "/" + prefix+".mp4" - print("Encoding video with: "+cmd) + print(("Encoding video with: "+cmd)) os.system(cmd) # build animated gif cmd = "convert "+view_dir + "/" + prefix+".mp4 "+view_dir + "/" + prefix+".gif" - print("Creating GIF with: "+cmd) + print(("Creating GIF with: "+cmd)) os.system(cmd) # clean up temporary images @@ -283,7 +283,7 @@ def animateAssembly(mname, aname, prefix, framesPerStep): print("Exception running osascript") else: - print(" Error: scad file not found: "+a['file']) + print((" Error: scad file not found: "+a['file'])) return 0 diff --git a/scripts/assemblies.py b/scripts/assemblies.py index e99d676..a671771 100644 --- a/scripts/assemblies.py +++ b/scripts/assemblies.py @@ -34,8 +34,8 @@ def assemblies(): # for each machine for m in jso: - if type(m) is DictType and m['type'] == 'machine': - print(m['title']) + if type(m) is dict and m['type'] == 'machine': + print((m['title'])) al = m['assemblies'] @@ -46,7 +46,7 @@ def assemblies(): # for each assembly for a in al: - print(" "+a['title']) + print((" "+a['title'])) fn = config.paths['root'] + a['file'] if (os.path.isfile(fn)): @@ -73,18 +73,18 @@ def assemblies(): f.close() # Views - print(" Step "+str(step['num'])) + print((" Step "+str(step['num']))) for view in step['views']: render_view_using_file(a['title']+'_step'+str(step['num']), config.paths['tempscad'], view_dir, view, hashchanged, h) # for each animation for anim in a['animations']: - print(" Animation: "+anim['title']+", framesPerStep="+str(anim['framesPerStep'])) + print((" Animation: "+anim['title']+", framesPerStep="+str(anim['framesPerStep']))) animateAssembly(m['title'], a['title'], anim['title'], anim['framesPerStep']) else: - print(" Error: scad file not found: "+a['file']) + print((" Error: scad file not found: "+a['file'])) # Save changes to json diff --git a/scripts/build.py b/scripts/build.py index d5e88cd..10435f1 100755 --- a/scripts/build.py +++ b/scripts/build.py @@ -22,15 +22,15 @@ def build(argv): try: opts, args = getopt.getopt(argv,"hcq",[]) except getopt.GetoptError: - print 'build.py -h -c -q' - print '' + print('build.py -h -c -q') + print( '') sys.exit(2) for opt, arg in opts: if opt == '-h': - print 'Usage: -h -c -q' - print '' - print ' -c Skip catalogue' - print ' -q Quick build - skip assemblies, guide and catalogue' + print('Usage: -h -c -q') + print('') + print(' -c Skip catalogue') + print( ' -q Quick build - skip assemblies, guide and catalogue') sys.exit() if opt in ("-c"): doCatalogue = False @@ -82,7 +82,7 @@ def build(argv): print("Build Complete") if errorlevel > 0: - print("Error: " + str(errorlevel)) + print(("Error: " + str(errorlevel))) return errorlevel diff --git a/scripts/c14n_stl.py b/scripts/c14n_stl.py index 1295e23..0ac9959 100644 --- a/scripts/c14n_stl.py +++ b/scripts/c14n_stl.py @@ -6,7 +6,7 @@ # This has no effect on the model but makes the STL consistent. I.e. it makes a canonical form. # -from __future__ import print_function + import sys import math diff --git a/scripts/catalogue.py b/scripts/catalogue.py index f98ad44..25b9731 100755 --- a/scripts/catalogue.py +++ b/scripts/catalogue.py @@ -36,7 +36,7 @@ def output_vitamin(v): # per view for view in t['children']: - if type(view) is DictType and view['type'] == 'view': + if type(view) is dict and view['type'] == 'view': md += '!['+t['title']+']('+view['png_name']+')\n' md += '\n' @@ -68,7 +68,7 @@ def compile_vitamin(v, dom): os.makedirs(config.paths['vitaminsimages']) # Compile - print(" "+v['title']) + print((" "+v['title'])) fn = '../' + v['file'] if (os.path.isfile(fn)): @@ -84,8 +84,8 @@ def compile_vitamin(v, dom): # Views print(" Views") for view in v['children']: - if type(view) is DictType and view['type'] == 'view': - print(" "+view['title']) + if type(view) is dict and view['type'] == 'view': + print((" "+view['title'])) render_view(v['title'], v['call'], config.paths['vitaminsimages'], view, hashchanged, h, [fn], False, useVitaminSTL=False) @@ -96,14 +96,14 @@ def compile_vitamin(v, dom): else: - print(" Error: scad file not found: "+v['file']) + print((" Error: scad file not found: "+v['file'])) def parse_vitamin(vitaminscad, use_catalogue_call=False): vitamincall = vitaminscad[:-5]; - print(" Calling: "+ vitamincall + "();") + print((" Calling: "+ vitamincall + "();")) # Generate a wrapper scad file for the vitamin file with open(config.paths['tempscad'], "w") as f: @@ -157,7 +157,7 @@ def parse_vitamin(vitaminscad, use_catalogue_call=False): js = json.dumps(jso, sort_keys=False, indent=4, separators=(',', ': ')) except Exception as e: - print(" "+e) + print((" "+e)) # Stop malformed machine json screwing up everything else! js = '' @@ -185,7 +185,7 @@ def catalogue(): for filename in os.listdir(config.paths['vitamins']): if filename[-5:] == '.scad': - print(" Parsing: "+filename) + print((" Parsing: "+filename)) s = '' @@ -225,12 +225,12 @@ def catalogue(): try: jso = json.loads(js) - print("Parsed "+str(files)+" vitamin files") + print(("Parsed "+str(files)+" vitamin files")) dom = {'vitamins':[]} for v in jso: - if type(v) is DictType and v['type'] == 'vitamin': + if type(v) is dict and v['type'] == 'vitamin': try: compile_vitamin(v, dom) except Exception as e: diff --git a/scripts/cut.py b/scripts/cut.py index f62ab42..102f385 100755 --- a/scripts/cut.py +++ b/scripts/cut.py @@ -33,8 +33,8 @@ def cut(): # for each machine for m in jso: - if type(m) is DictType and m['type'] == 'machine': - print(m['title']) + if type(m) is dict and m['type'] == 'machine': + print((m['title'])) al = m['cut'] @@ -43,7 +43,7 @@ def cut(): os.makedirs(config.paths['cutpartsimages']) for a in al: - print(" "+a['title']) + print((" "+a['title'])) fn = config.paths['root'] + a['file'] if (os.path.isfile(fn)): @@ -81,13 +81,13 @@ def cut(): f.close() # Views - print(" Step "+str(step['num'])) + print((" Step "+str(step['num']))) for view in step['views']: render_view_using_file(a['title']+'_step'+str(step['num']), config.paths['tempscad'], config.paths['cutpartsimages'], view, hashchanged, h) else: - print(" Error: scad file not found: "+a['file']) + print((" Error: scad file not found: "+a['file'])) # Save changes to json diff --git a/scripts/guides.py b/scripts/guides.py index 1855b83..090d19a 100755 --- a/scripts/guides.py +++ b/scripts/guides.py @@ -215,7 +215,7 @@ def assembly_level(a): def gen_assembly_guide(m, guide_template): - print(m['title']) + print((m['title'])) md = '' @@ -224,7 +224,7 @@ def gen_assembly_guide(m, guide_template): # machine views for c in m['children']: - if type(c) is DictType and c['type'] == 'view' and 'filepath' in c: + if type(c) is dict and c['type'] == 'view' and 'filepath' in c: view = c md += '!['+view['caption']+']('+ view['filepath'][3:] +')\n\n' @@ -273,7 +273,7 @@ def gen_assembly_guide(m, guide_template): def gen_printing_guide(m, guide_template): - print(m['title']) + print((m['title'])) if len(m['printed']) == 0: return {}; @@ -347,19 +347,19 @@ def gen_printing_guide(m, guide_template): def load_sources(): - print "Loading sourcing info..." + print("Loading sourcing info...") load_source(config.paths['sourcingcsv']) for filename in os.listdir(config.paths['vitamins']): if filename[-4:] == '.csv': - print(" Parsing: "+filename) + print((" Parsing: "+filename)) csvfn = os.path.join(src_dir, filename) load_source(csvfn) def load_source(csvfn): if os.path.isfile(csvfn): - with open(csvfn, 'rb') as csvfile: + with open(csvfn, 'r') as csvfile: rdr = csv.DictReader(csvfile) for row in rdr: vn = row['Vitamin'] @@ -369,7 +369,7 @@ def load_source(csvfn): def gen_sourcing_guide(m, guide_template): - print(m['title']) + print((m['title'])) if len(m['vitamins']) == 0: return {}; @@ -469,7 +469,7 @@ def gen_index(jso, index_file, index_template): # build object indexObj = { 'machines': [], 'project':'' }; for m in jso: - if type(m) is DictType and m['type'] == 'machine': + if type(m) is dict and m['type'] == 'machine': # tack in a view filename m['viewFilename'] = views.view_filename(m['title'] + '_view') @@ -527,7 +527,7 @@ def guides(): # for each machine for m in jso: - if type(m) is DictType and m['type'] == 'machine': + if type(m) is dict and m['type'] == 'machine': if 'guides' not in m: m['guides'] = [] diff --git a/scripts/jsontools.py b/scripts/jsontools.py index 2bf6f38..8caef02 100644 --- a/scripts/jsontools.py +++ b/scripts/jsontools.py @@ -11,7 +11,7 @@ def json_merge_missing_keys(j1, j2, overwrite=False, exclude=[]): def get_child_by_key_values(j1, kvs={}): if 'children' in j1: for c in j1['children']: - if type(c) is DictType: + if type(c) is dict: match = True for kv in kvs: if not (kv in c and c[kv] == kvs[kv]): diff --git a/scripts/machines.py b/scripts/machines.py index 112ce8d..241b11a 100644 --- a/scripts/machines.py +++ b/scripts/machines.py @@ -33,8 +33,8 @@ def machines(): # for each machine for m in jso: - if type(m) is DictType and m['type'] == 'machine': - print(m['title']) + if type(m) is dict and m['type'] == 'machine': + print((m['title'])) fn = config.paths['root'] + m['file'] @@ -52,15 +52,15 @@ def machines(): # Views print(" Views") for c in m['children']: - if type(c) is DictType and c['type'] == 'view': + if type(c) is dict and c['type'] == 'view': view = c - print(" "+view['title']) + print((" "+view['title'])) render_view_using_file(m['title'], fn, config.paths['machineimages'], view, hashchanged, h) else: - print(" Error: scad file not found: "+v['file']) + print((" Error: scad file not found: "+v['file'])) # Save changes to json diff --git a/scripts/openscad.py b/scripts/openscad.py index 1f20091..6cc6b8d 100644 --- a/scripts/openscad.py +++ b/scripts/openscad.py @@ -1,4 +1,4 @@ -from __future__ import print_function + import config import subprocess @@ -77,7 +77,7 @@ def is_exe(fpath): def run_silent(*args): log = open(config.paths['openscadlog'], "w") - programs = ['OpenSCAD', 'openscad'] + programs = ['OpenSCAD', 'openscad', 'openscad.com'] for locate_prog in programs: prog = which(locate_prog) if prog != None: diff --git a/scripts/parse.py b/scripts/parse.py index 6800d4d..f4efbfc 100755 --- a/scripts/parse.py +++ b/scripts/parse.py @@ -38,7 +38,7 @@ def parse_machines(): for filename in os.listdir(config.paths['root']): if filename[-5:] == '.scad': - print(" Parsing: "+filename) + print((" Parsing: "+filename)) scadfile = os.path.join(config.paths['root'], filename) if (files > 0): @@ -69,7 +69,7 @@ def parse_machines(): try: jso = json.loads(js) - print(" Parsed "+str(files)+" machine files") + print((" Parsed "+str(files)+" machine files")) summarise_files(jso, oldjso) @@ -138,7 +138,7 @@ def parse_machine(scadfile): except Exception as e: print(e) - print("See "+config.paths['errors']+" for malformed json") + print(("See "+config.paths['errors']+" for malformed json")) with open(config.paths['errors'], 'w') as f: f.write(js) # Stop malformed machine json screwing up everything else! @@ -164,7 +164,7 @@ def add_file(fn, fs): fs.append({ 'type':'file', 'file':fn }) def add_file_for(jso, fs): - if type(jso) is DictType: + if type(jso) is dict: if 'file' in jso: add_file(jso['file'], fs) @@ -184,7 +184,7 @@ def summarise_files(jso, oldjso): for m in jso: add_file_for(m, fs) - print(" Found "+str(len(fs))+" files") + print((" Found "+str(len(fs))+" files")) # Part Summarisation @@ -203,7 +203,7 @@ def add_view(jso, o): def add_views_for(jso, o): # check for views in children for c in jso['children']: - if type(c) is DictType and c['type'] == 'view': + if type(c) is dict and c['type'] == 'view': add_view(c, o) def add_animation(jso, o): @@ -219,7 +219,7 @@ def add_animation(jso, o): def add_animations_for(jso, o): # check for animations in children for c in jso['children']: - if type(c) is DictType and c['type'] == 'animation': + if type(c) is dict and c['type'] == 'animation': add_animation(c, o) def add_markdown(jso, o): @@ -237,7 +237,7 @@ def add_markdown(jso, o): def add_markdown_for(jso, o): # check for markdown in children for c in jso['children']: - if type(c) is DictType and c['type'] == 'markdown': + if type(c) is dict and c['type'] == 'markdown': add_markdown(c, o) def add_part(jso, o): @@ -253,7 +253,7 @@ def add_part(jso, o): def add_parts_for(jso, o): # check for parts in children for c in jso['children']: - if type(c) is DictType and c['type'] == 'part': + if type(c) is dict and c['type'] == 'part': add_part(c, o) @@ -274,7 +274,7 @@ def add_step(jso, o): def add_steps_for(jso, o): # check for steps in children for c in jso['children']: - if type(c) is DictType and c['type'] == 'step': + if type(c) is dict and c['type'] == 'step': add_step(c, o) @@ -348,7 +348,7 @@ def add_cut(jso, cl, addSteps=True, addViews=True, addChildren=True): # Collate immediate children, and sub-assemblies nested in steps! if addChildren and 'children' in jso: for c in jso['children']: - if type(c) is DictType: + if type(c) is dict: tn = c['type'] if tn == 'vitamin': @@ -356,7 +356,7 @@ def add_cut(jso, cl, addSteps=True, addViews=True, addChildren=True): if tn == 'step': for sc in c['children']: - if type(sc) is DictType: + if type(sc) is dict: tn2 = sc['type'] if tn2 == 'vitamin': @@ -400,7 +400,7 @@ def add_assembly(jso, al, pl, vl, cl, addSteps=True, addViews=True, addChildren= nextlevel = level + 1 if addChildren and 'children' in jso: for c in jso['children']: - if type(c) is DictType: + if type(c) is dict: tn = c['type'] if tn == 'vitamin': @@ -417,7 +417,7 @@ def add_assembly(jso, al, pl, vl, cl, addSteps=True, addViews=True, addChildren= if tn == 'step': for sc in c['children']: - if type(sc) is DictType: + if type(sc) is dict: tn2 = sc['type'] if tn2 == 'vitamin': @@ -437,7 +437,7 @@ def add_assembly(jso, al, pl, vl, cl, addSteps=True, addViews=True, addChildren= def summarise_parts_for(jso, al, pl, vl, cl, level=0): # print("sum_parts_for "+str(level)) - if type(jso) is DictType: + if type(jso) is dict: tn = jso['type'] if tn == 'vitamin': @@ -460,8 +460,8 @@ def summarise_parts(jso, oldjso): print("Summarising parts for each machine...") for m in jso: - if type(m) is DictType and m['type'] == 'machine': - print(" "+m['title']+"...") + if type(m) is dict and m['type'] == 'machine': + print((" "+m['title']+"...")) al = m['assemblies'] = [] cl = m['cut'] = [] @@ -472,10 +472,10 @@ def summarise_parts(jso, oldjso): summarise_parts_for(c, al, pl, vl, cl, 0) print(" Found:") - print(" "+str(len(al))+" assemblies") - print(" "+str(len(cl))+" cut parts") - print(" "+str(len(pl))+" printed parts") - print(" "+str(len(vl))+" vitamins") + print((" "+str(len(al))+" assemblies")) + print((" "+str(len(cl))+" cut parts")) + print((" "+str(len(pl))+" printed parts")) + print((" "+str(len(vl))+" vitamins")) # Update Cache @@ -487,13 +487,13 @@ def update_cache_info_for(vl, ovl): return for v in vl: - if type(v) is DictType and 'title' in v: - print(" "+v['title']) + if type(v) is dict and 'title' in v: + print((" "+v['title'])) # find match in ovl oldv = None for ov in ovl: - if type(ov) is DictType and 'title' in ov and ov['title'] == v['title']: + if type(ov) is dict and 'title' in ov and ov['title'] == v['title']: oldv = ov continue @@ -517,13 +517,13 @@ def update_cache_info(jso, oldjso): return for m in jso: - if type(m) is DictType and m['type'] == 'machine': - print(" "+m['title']+"...") + if type(m) is dict and m['type'] == 'machine': + print((" "+m['title']+"...")) # find matching machine in oldjso oldm = None for om in oldjso: - if type(om) is DictType and om['type'] == 'machine' and 'title' in om and om['title'] == m['title']: + if type(om) is dict and om['type'] == 'machine' and 'title' in om and om['title'] == m['title']: oldm = om continue @@ -554,4 +554,4 @@ def update_cache_info(jso, oldjso): if __name__ == '__main__': - print("Parse complete, errorlevel="+str(parse_machines())) + print(("Parse complete, errorlevel="+str(parse_machines()))) diff --git a/scripts/printed.py b/scripts/printed.py index c5f283e..18a2075 100644 --- a/scripts/printed.py +++ b/scripts/printed.py @@ -40,13 +40,13 @@ def printed(): # for each machine for m in jso: - if type(m) is DictType and m['type'] == 'machine': - print(m['title']) + if type(m) is dict and m['type'] == 'machine': + print((m['title'])) pl = m['printed'] for p in pl: - print(" "+p['title']) + print((" "+p['title'])) fn = config.paths['root'] + p['file'] if (os.path.isfile(fn)): @@ -94,7 +94,7 @@ def printed(): print(" views") # Views for view in p['views']: - print(" "+view['title']) + print((" "+view['title'])) render_view(p['title'], p['call'], config.paths['printedpartsimages'], view, hashchanged, h) @@ -103,7 +103,7 @@ def printed(): stlList.append(md5path) else: - print(" Error: scad file not found: "+p['file']) + print((" Error: scad file not found: "+p['file'])) # Save changes to json @@ -111,16 +111,16 @@ def printed(): f.write(json.dumps(jso, sort_keys=False, indent=4, separators=(',', ': '))) # clean-up orphaned stls and checksums - print "Checking for outdated STLs..." + print("Checking for outdated STLs...") for f in os.listdir(config.paths['printedpartsstl']): fp = os.path.join(config.paths['printedpartsstl'], f) try: if os.path.isfile(fp) and (fp not in stlList): - print "Removing: "+fp + print(( "Removing: "+fp)) os.remove(fp) - except Exception, e: - print e - print " Done" + except Exception as e: + print(e) + print(" Done") return 0 diff --git a/scripts/slic3r.py b/scripts/slic3r.py index b455ec0..0e8b30e 100644 --- a/scripts/slic3r.py +++ b/scripts/slic3r.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -from __future__ import print_function + import sys from subprocess import call, check_output diff --git a/scripts/startaproject.py b/scripts/startaproject.py index 5c9ef64..24e04ef 100755 --- a/scripts/startaproject.py +++ b/scripts/startaproject.py @@ -29,14 +29,14 @@ def startaproject(proj_parent_path, proj_name): proj_path = os.path.join(proj_parent_path, proj_name) if (os.path.isdir(proj_parent_path) is not True): - print("Error: Parent directory does not exist: "+proj_parent_path) + print(("Error: Parent directory does not exist: "+proj_parent_path)) sys.exit() if (os.path.isdir(proj_path)): - print("Error: Project directory already exists: "+proj_path) + print(("Error: Project directory already exists: "+proj_path)) sys.exit() else: - print("Creating project directory: "+proj_path) + print(("Creating project directory: "+proj_path)) os.mkdir(proj_path) print("Create directory structure") @@ -76,7 +76,7 @@ def startaproject(proj_parent_path, proj_name): with open(outFile,'w') as o: o.write(s) else: - print(templateFile + " root template is missing") + print((templateFile + " root template is missing")) print("Init git") with cd(os.path.join(proj_path)): diff --git a/scripts/static.py b/scripts/static.py index cc0de30..e0a5e5e 100644 --- a/scripts/static.py +++ b/scripts/static.py @@ -2,7 +2,7 @@ # Perform static code analysis -from __future__ import print_function + import os import sys diff --git a/scripts/syntax.py b/scripts/syntax.py index 953e87e..9f1bfa0 100644 --- a/scripts/syntax.py +++ b/scripts/syntax.py @@ -55,7 +55,7 @@ def check_syntax(filename, level=0): if errorlevel > 0: res['errorLevel'] = errorlevel res['errorMessage'] = "Syntax error near line "+str(errorlevel) - print("Syntax error near line "+str(errorlevel)+" in "+filename) + print(("Syntax error near line "+str(errorlevel)+" in "+filename)) # if error, do the same for all included files if errorlevel > 0: @@ -66,12 +66,12 @@ def check_syntax(filename, level=0): else: res['errorLevel'] = 1 res['errorMessage'] = 'File not found' - print("File not found: "+filename) + print(("File not found: "+filename)) # Print warnings if level == 0: for w in res['warnings']: - print("Warning: "+w) + print(("Warning: "+w)) return res diff --git a/scripts/views.py b/scripts/views.py index 0310f99..83e4a62 100644 --- a/scripts/views.py +++ b/scripts/views.py @@ -58,12 +58,17 @@ def polish(filename, w, h, hash="", viewhash=""): y1 = img.size[1] y2 = 0 + #Added by JG to fix type error: + w=int(w) + + h=int(h) + # Set background to white and transparent - for y in xrange(img.size[1]): + for y in range(img.size[1]): solidx = 0 solidy = 0 - for x in xrange(img.size[0]): + for x in range(img.size[0]): if pixdata[x, y] == bkc: pixdata[x, y] = (255, 255, 255, 0 if PolishTransparentBackground else 255) else: @@ -81,6 +86,7 @@ def polish(filename, w, h, hash="", viewhash=""): x2 += 2 y2 += 2 + # downsample (half the res) img = img.resize((w, h), Image.ANTIALIAS) @@ -88,6 +94,7 @@ def polish(filename, w, h, hash="", viewhash=""): if (x1 < x2 and y1 < y2 and PolishCrop): img = img.crop((x1/2,y1/2,x2/2,y2/2)) + # add hash to meta data meta = PngImagePlugin.PngInfo() @@ -99,9 +106,13 @@ def polish(filename, w, h, hash="", viewhash=""): # Save it img.save(filename, "PNG", pnginfo=meta) + img.close() - except: - print(" Exception error", sys.exc_info()[0]) + except Exception as e: + print((" Exception error", sys.exc_info()[0])) + #print(type(e)) + #print(e.args) + #print(e) def render_view_using_file(obj_title, scadfile, dir, view, hashchanged, hash=""): @@ -111,11 +122,11 @@ def render_view_using_file(obj_title, scadfile, dir, view, hashchanged, hash="") oldhashes = read_hashes_from_png(png_name) - viewstr = str(view['size']) + str(view['translate']) + str(view['rotate']) + str(view['dist']) + viewstr = (str(view['size']) + str(view['translate']) + str(view['rotate']) + str(view['dist'])).encode('utf-8') viewhash = hashlib.md5(viewstr).hexdigest(); if (not os.path.isfile(png_name) or (hash != oldhashes['csghash']) or (viewhash != oldhashes['viewhash'])): - print(" Updating: "+png_name) + print((" Updating: "+png_name)) # Up-sample images w = view['size'][0] * 2 @@ -141,7 +152,7 @@ def render_view_using_file(obj_title, scadfile, dir, view, hashchanged, hash="") polish(png_name, w/2, h/2, hash, viewhash) - print + print() else: print(" View up to date") diff --git a/scripts/vitamins.py b/scripts/vitamins.py index 180cc20..0946edc 100755 --- a/scripts/vitamins.py +++ b/scripts/vitamins.py @@ -28,7 +28,7 @@ def compile_vitamin(v): os.makedirs(config.paths['vitaminsimages2']) # Compile - print(" "+v['title']) + print((" "+v['title'])) fn = os.path.join('..', v['file']) if (os.path.isfile(fn)): @@ -55,13 +55,13 @@ def compile_vitamin(v): # Views print(" Views") for view in v['views']: - print(" "+view['title']) + print((" "+view['title'])) render_view(v['title'], v['call'], config.paths['vitaminsimages2'], view, hashchanged, h) else: - print(" Error: scad file not found: "+v['file']) + print((" Error: scad file not found: "+v['file'])) def vitamins(): print("Vitamins") @@ -74,8 +74,8 @@ def vitamins(): # for each machine for m in jso: - if type(m) is DictType and m['type'] == 'machine': - print(m['title']) + if type(m) is dict and m['type'] == 'machine': + print((m['title'])) vl = m['vitamins'] From b05f0da73a1ae03748072c4c26c451f003f8cb7d Mon Sep 17 00:00:00 2001 From: Juliean Date: Sun, 6 Jan 2019 11:26:26 -0500 Subject: [PATCH 2/3] Updated READEM.md to reflect purpose of this fork --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index a412c0c..e9b00a2 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,11 @@ +# Changes on this fork + +This framework is an awesome project from Axford, but it appears to have been abandoned, at least it's not been worked on since 2016 or so (it's now Jan 2019). Original was written for Python 2, and assumed Unix (or Mac?) conventions. I've updated it to work with Python 3 (only tested with 3.6.5) and made some changes to make it work on Windows. + +**Note**: I have not tested this extensively. I've only used it with Python 3.6.5 on Win10, and don't know if I broke anything for other platforms. I'm also quite new to using it, so there may be use cases that don't currently work (sadly, the tutorial only has part 1) If you find any bugs, please open an issue, I'll try to take a look. + +Everythng below is from the original project. + # OpenSCAD for Machine Design framework ## Overview From dc95c4e3585cb14d74c0041934af3b40271da6ec Mon Sep 17 00:00:00 2001 From: Juliean Date: Sun, 20 Jan 2019 17:34:33 -0500 Subject: [PATCH 3/3] Additional fix to guides.py --- scripts/guides.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/guides.py b/scripts/guides.py index 090d19a..d1d3825 100755 --- a/scripts/guides.py +++ b/scripts/guides.py @@ -362,10 +362,10 @@ def load_source(csvfn): with open(csvfn, 'r') as csvfile: rdr = csv.DictReader(csvfile) for row in rdr: - vn = row['Vitamin'] + vn = row.get('Vitamin'); if vn not in sourcing: sourcing[vn] = [] - sourcing[vn].append({"Cost":row['Cost'], "Source":row['Source'], 'Notes':row['Notes']}); + sourcing[vn].append({"Cost":row.get('Cost'), "Source":row.get('Source'), 'Notes':row.get('Notes')}); def gen_sourcing_guide(m, guide_template):