def write_output(self, out_path, **kwargs): args = self.validate_arguments(kwargs, ["target_license", "version"], {"stable": False, "expand": False}) self.clear_output_dir(out_path) # copy files bolts_fid = open(join(out_path, "BOLTS.scad"), "w", "utf8") # copy common files if not license.is_combinable_with("LGPL 2.1+", args["target_license"]): raise IncompatibleLicenseError( "OpenSCAD common files are LGPL 2.1+, which is not compatible with %s" % args["target_license"] ) makedirs(join(out_path, "common")) for filename in listdir(join(self.repo.path, "backends", "openscad")): if not filename.endswith(".scad"): continue copy(join(self.repo.path, "backends", "openscad", filename), join(out_path, "common", filename)) if not args["expand"]: bolts_fid.write("include <common/%s>\n" % filename) else: bolts_fid.write(open(join(out_path, "common", filename)).read()) # create version file version_fid = open(join(out_path, "common", "version.scad"), "w", "utf8") if args["stable"]: major, minor = str(args["version"]).split(".") version_fid.write('function BOLTS_version() = [%s, %s, "%s"];\n' % (major, minor, target_license)) else: version_fid.write('function BOLTS_version() = "%s";\n' % args["version"]) date = datetime.now() version_fid.write("function BOLTS_date() = [%d,%d,%d];\n" % (date.year, date.month, date.day)) version_fid.write('function BOLTS_license() = "%s";\n' % args["target_license"]) version_fid.close() if not args["expand"]: bolts_fid.write("include <common/version.scad>\n") else: bolts_fid.write(open(join(out_path, "common", "version.scad")).read()) makedirs(join(out_path, "base")) makedirs(join(out_path, "classes")) for (scadfile,) in self.dbs["openscad"].iterscadfiles(): if not license.is_combinable_with(scadfile.license_name, args["target_license"]): continue # copy base files makedirs(join(out_path, "base", dirname(scadfile.path))) copy(join(self.dbs["openscad"].backend_root, scadfile.path), join(out_path, "base", scadfile.path)) # include files if not args["expand"]: bolts_fid.write("include <base/%s>\n" % scadfile.path) else: bolts_fid.write(open(join(out_path, "base", scadfile.path)).read()) # process classes for cl, module in self.dbs["openscad"].iterclasses(["class", "module"], filter_scadfile=scadfile): with open(join(out_path, "classes", "%s.scad" % cl.id), "w") as cl_fid: self.write_classfile(cl_fid, cl, module) if not args["expand"]: bolts_fid.write("include <classes/%s.scad>\n" % cl.id) else: bolts_fid.write(open(join(out_path, "classes", "%s.scad" % cl.id)).read())
def write_output(self,out_path,**kwargs): args = self.validate_arguments(kwargs,["target_license","version"]) self.clear_output_dir(out_path) bolts_path = join(out_path,"BOLTS") #generate macro start_macro = open(join(out_path,"start_bolts.FCMacro"),"w") start_macro.write("import BOLTS\n") start_macro.write("BOLTS.show_widget()\n") start_macro.close() #copy files #bolttools if not license.is_combinable_with("LGPL 2.1+",args["target_license"]): raise IncompatibleLicenseError( "bolttools is LGPL 2.1+, which is not compatible with %s" % args["target_license"]) copytree(join(self.repo.path,"bolttools"),join(bolts_path,"bolttools")) #remove the test suite and documentation, to save space rmtree(join(bolts_path,"bolttools","test_blt")) #generate version file date = datetime.now() version_file = open(join(bolts_path,"VERSION"),"w") version_file.write("%s\n%d-%d-%d\n%s\n" % (args["version"], date.year, date.month, date.day, args["target_license"])) version_file.close() #freecad gui code if not license.is_combinable_with("LGPL 2.1+",args["target_license"]): raise IncompatibleLicenseError( "FreeCAD gui files are LGPL 2.1+, which is not compatible with %s" % args["target_license"]) if not exists(join(bolts_path,"freecad")): makedirs(join(bolts_path,"freecad")) if not exists(join(bolts_path,"data")): makedirs(join(bolts_path,"data")) open(join(bolts_path,"freecad","__init__.py"),"w").close() copytree(join(self.repo.path,"backends","freecad","gui"),join(bolts_path,"gui")) copytree(join(self.repo.path,"backends","freecad","assets"),join(bolts_path,"assets")) copytree(join(self.repo.path,"icons"),join(bolts_path,"icons")) copyfile(join(self.repo.path,"backends","freecad","init.py"),join(bolts_path,"__init__.py")) open(join(bolts_path,"gui","__init__.py"),"w").close() #compile ui files uic.compileUiDir(join(bolts_path,"gui")) for coll, in self.repo.itercollections(): if not license.is_combinable_with(coll.license_name,args["target_license"]): continue copy(join(self.repo.path,"data","%s.blt" % coll.id), join(bolts_path,"data","%s.blt" % coll.id)) if not exists(join(bolts_path,"freecad",coll.id)): makedirs(join(bolts_path,"freecad",coll.id)) if not exists(join(self.repo.path,"freecad",coll.id,"%s.base" % coll.id)): continue copy(join(self.repo.path,"freecad",coll.id,"%s.base" % coll.id), join(bolts_path,"freecad",coll.id,"%s.base" % coll.id)) open(join(bolts_path,"freecad",coll.id,"__init__.py"),"w").close() for base, in self.dbs["freecad"].iterbases(filter_collection=coll): if not base.license_name in license.LICENSES: continue if not license.is_combinable_with(base.license_name,args["target_license"]): continue copy(join(self.repo.path,"freecad",coll.id,basename(base.filename)), join(bolts_path,"freecad",coll.id,basename(base.filename)))
def write_output(self, out_path, target_license, version, stable=False): oscad = self.openscad self.clear_output_dir(out_path) #copy files bolts_fid = open(join(out_path, "BOLTS.scad"), "w", "utf8") standard_fids = {} for std in self.repo.standard_bodies: standard_fids[std] = open(join(out_path, "BOLTS_%s.scad" % std), "w", "utf8") makedirs(join(out_path, "tables")) #copy common files if not license.is_combinable_with("LGPL 2.1+", target_license): raise IncompatibleLicenseError( "OpenSCAD common files are licensed under LGPL 2.1+, which is not compatible with %s" % target_license) makedirs(join(out_path, "common")) for filename in listdir(join(self.repo.path, "backends", "openscad")): if not filename.endswith(".scad"): continue copy(join(self.repo.path, "backends", "openscad", filename), join(out_path, "common", filename)) bolts_fid.write("include <common/%s>\n" % filename) for std in standard_fids: standard_fids[std].write("include <common/%s>\n" % filename) #create version file version_fid = open(join(out_path, "common", "version.scad"), "w", "utf8") if stable: major, minor = str(version).split('.') version_fid.write('function BOLTS_version() = [%s, %s, %s];\n' % (major, minor, target_license)) else: version_fid.write('function BOLTS_version() = "%s";\n' % version) date = datetime.now() version_fid.write('function BOLTS_date() = [%d,%d,%d];\n' % (date.year, date.month, date.day)) version_fid.write('function BOLTS_license() = "%s";\n' % target_license) version_fid.close() bolts_fid.write("include <common/version.scad>\n") for std in standard_fids: standard_fids[std].write("include <common/version.scad>\n") #copy base files copied = [] makedirs(join(out_path, "base")) for id in oscad.getbase: base = oscad.getbase[id] if not license.is_combinable_with(base.license_name, target_license): continue for path in base.get_copy_files(): if path in copied: continue copy(join(oscad.backend_root, path), join(out_path, "base", basename(path))) copied.append(path) #include files included = [] for id in oscad.getbase: base = oscad.getbase[id] if not license.is_combinable_with(base.license_name, target_license): continue for path in base.get_include_files(): if path in included: continue bolts_fid.write("include <base/%s>\n" % path) for std in standard_fids: standard_fids[std].write("include <base/%s>\n" % path) included.append(path) #write tables table_cache = [] for collection in self.repo.collections: if not license.is_combinable_with(collection.license_name, target_license): continue for cl in collection.classes: if not cl.id in oscad.getbase: continue if not cl.id in table_cache: base = oscad.getbase[cl.id] if not license.is_combinable_with(base.license_name, target_license): continue table_path = join("tables", "%s_table.scad" % cl.id) table_filename = join(out_path, table_path) fid = open(table_filename, "w", "utf8") self.write_table(fid, collection, cl) fid.close() table_cache.append(cl.id) bolts_fid.write("include <%s>\n" % table_path) for std in standard_fids: if cl in self.repo.standardized[std]: standard_fids[std].write("include <%s>\n" % table_path) bolts_fid.write("\n\n") #write stubs for collection in self.repo.collections: if not license.is_combinable_with(collection.license_name, target_license): continue for cl in collection.classes: if not cl.id in oscad.getbase: continue base = oscad.getbase[cl.id] if not license.is_combinable_with(base.license_name, target_license): continue self.write_stub(bolts_fid, cl) self.write_dim_accessor(bolts_fid, cl) for std in standard_fids: if cl in self.repo.standardized[std]: self.write_stub(standard_fids[std], cl) self.write_dim_accessor(standard_fids[std], cl) bolts_fid.close() for std in standard_fids: standard_fids[std].close()
def write_output(self,out_path,target_license,version,stable=False): self.clear_output_dir(out_path) bolts_path = join(out_path,"BOLTS") #generate macro start_macro = open(join(out_path,"start_bolts.FCMacro"),"w") start_macro.write("import BOLTS\n") start_macro.write("BOLTS.show_widget()\n") start_macro.close() #copy files #bolttools if not license.is_combinable_with("LGPL 2.1+",target_license): raise IncompatibleLicenseError( "bolttools is LGPL 2.1+, which is not compatible with %s" % target_license) copytree(join(self.repo.path,"bolttools"),join(bolts_path,"bolttools")) #remove the test suite and documentation, to save space rmtree(join(bolts_path,"bolttools","test")) rmtree(join(bolts_path,"bolttools","doc")) #generate version file date = datetime.now() version_file = open(join(bolts_path,"VERSION"),"w") version_file.write("%s\n%d-%d-%d\n%s\n" % (version, date.year, date.month, date.day, target_license)) version_file.close() #freecad gui code if not license.is_combinable_with("LGPL 2.1+",target_license): raise IncompatibleLicenseError( "FreeCAD gui files are LGPL 2.1+, which is not compatible with %s" % target_license) if not exists(join(bolts_path,"freecad")): makedirs(join(bolts_path,"freecad")) if not exists(join(bolts_path,"data")): makedirs(join(bolts_path,"data")) open(join(bolts_path,"freecad","__init__.py"),"w").close() copytree(join(self.repo.path,"backends","freecad","gui"),join(bolts_path,"gui")) copytree(join(self.repo.path,"backends","freecad","assets"),join(bolts_path,"assets")) copytree(join(self.repo.path,"icons"),join(bolts_path,"icons")) copyfile(join(self.repo.path,"backends","freecad","init.py"),join(bolts_path,"__init__.py")) open(join(bolts_path,"gui","__init__.py"),"w").close() #compile ui files uic.compileUiDir(join(bolts_path,"gui")) for coll in self.repo.collections: if not license.is_combinable_with(coll.license_name,target_license): continue copy(join(self.repo.path,"data","%s.blt" % coll.id), join(bolts_path,"data","%s.blt" % coll.id)) if not exists(join(bolts_path,"freecad",coll.id)): makedirs(join(bolts_path,"freecad",coll.id)) if not exists(join(self.repo.path,"freecad",coll.id,"%s.base" % coll.id)): continue copy(join(self.repo.path,"freecad",coll.id,"%s.base" % coll.id), join(bolts_path,"freecad",coll.id,"%s.base" % coll.id)) open(join(bolts_path,"freecad",coll.id,"__init__.py"),"w").close() for cl in coll.classes: if not cl.id in self.freecad.getbase: continue base = self.freecad.getbase[cl.id] if not base.license_name in license.LICENSES: continue if not license.is_combinable_with(base.license_name,target_license): continue copy(join(self.repo.path,"freecad",coll.id,basename(base.filename)), join(bolts_path,"freecad",coll.id,basename(base.filename)))
def write_output(self,out_path,target_license,version,stable=False): oscad = self.openscad self.clear_output_dir(out_path) #copy files bolts_fid = open(join(out_path,"BOLTS.scad"),"w","utf8") standard_fids = {} for std in self.repo.standard_bodies: standard_fids[std] = open(join(out_path,"BOLTS_%s.scad" % std),"w","utf8") makedirs(join(out_path,"tables")) #copy common files if not license.is_combinable_with("LGPL 2.1+",target_license): raise IncompatibleLicenseError( "OpenSCAD common files are LGPL 2.1+, which is not compatible with %s" % target_license) makedirs(join(out_path,"common")) for filename in listdir(join(self.repo.path,"backends","openscad")): if not filename.endswith(".scad"): continue copy(join(self.repo.path,"backends","openscad",filename), join(out_path,"common",filename)) bolts_fid.write("include <common/%s>\n" % filename) for std in standard_fids: standard_fids[std].write("include <common/%s>\n" % filename) #create version file version_fid = open(join(out_path,"common","version.scad"),"w","utf8") if stable: major, minor = str(version).split('.') version_fid.write('function BOLTS_version() = [%s, %s, "%s"];\n' % (major, minor, target_license)) else: version_fid.write('function BOLTS_version() = "%s";\n' % version) date = datetime.now() version_fid.write('function BOLTS_date() = [%d,%d,%d];\n' % (date.year, date.month, date.day)) version_fid.write('function BOLTS_license() = "%s";\n' % target_license) version_fid.close() bolts_fid.write("include <common/version.scad>\n") for std in standard_fids: standard_fids[std].write("include <common/version.scad>\n") #copy base files copied = [] makedirs(join(out_path,"base")) for id in oscad.getbase: base = oscad.getbase[id] if not license.is_combinable_with(base.license_name,target_license): continue for path in base.get_copy_files(): if path in copied: continue copy(join(oscad.backend_root,path),join(out_path,"base",basename(path))) copied.append(path) #include files included = [] for id in oscad.getbase: base = oscad.getbase[id] if not license.is_combinable_with(base.license_name,target_license): continue for path in base.get_include_files(): if path in included: continue bolts_fid.write("include <base/%s>\n" % path) for std in standard_fids: standard_fids[std].write("include <base/%s>\n" % path) included.append(path) #write tables for collection in self.repo.collections: if not license.is_combinable_with(collection.license_name,target_license): continue for cl in collection.classes_by_ids(): if not cl.id in oscad.getbase: continue base = oscad.getbase[cl.id] if not license.is_combinable_with(base.license_name,target_license): continue table_path = join("tables","%s_table.scad" % cl.id) table_filename = join(out_path,table_path) fid = open(table_filename,"w","utf8") self.write_table(fid,collection,cl) fid.close() bolts_fid.write("include <%s>\n" % table_path) for std in standard_fids: if cl in self.repo.standardized[std]: standard_fids[std].write("include <%s>\n" % table_path) bolts_fid.write("\n\n") #write stubs for collection in self.repo.collections: if not license.is_combinable_with(collection.license_name,target_license): continue for cl in collection.classes: if not cl.id in oscad.getbase: continue base = oscad.getbase[cl.id] if not license.is_combinable_with(base.license_name,target_license): continue self.write_stub(bolts_fid,cl) self.write_dim_accessor(bolts_fid,cl) self.write_connectors_accessor(bolts_fid,cl) for std in standard_fids: if cl in self.repo.standardized[std]: self.write_stub(standard_fids[std],cl) self.write_dim_accessor(standard_fids[std],cl) bolts_fid.close() for std in standard_fids: standard_fids[std].close()
def write_output(self,out_path,**kwargs): args = self.validate_arguments(kwargs,["target_license","version"],{"stable" : False,"expand" : False}) self.clear_output_dir(out_path) #copy files bolts_fid = open(join(out_path,"BOLTS.scad"),"w","utf8") #copy common files if not license.is_combinable_with("LGPL 2.1+",args["target_license"]): raise IncompatibleLicenseError( "OpenSCAD common files are LGPL 2.1+, which is not compatible with %s" % args["target_license"]) makedirs(join(out_path,"common")) for filename in listdir(join(self.repo.path,"backends","openscad")): if not filename.endswith(".scad"): continue copy(join(self.repo.path,"backends","openscad",filename), join(out_path,"common",filename)) if not args["expand"]: bolts_fid.write("include <common/%s>\n" % filename) else: bolts_fid.write(open(join(out_path,"common",filename)).read()) #create version file version_fid = open(join(out_path,"common","version.scad"),"w","utf8") if args["stable"]: major, minor = str(args["version"]).split('.') version_fid.write('function BOLTS_version() = [%s, %s, "%s"];\n' % (major, minor, target_license)) else: version_fid.write('function BOLTS_version() = "%s";\n' % args["version"]) date = datetime.now() version_fid.write('function BOLTS_date() = [%d,%d,%d];\n' % (date.year, date.month, date.day)) version_fid.write('function BOLTS_license() = "%s";\n' % args["target_license"]) version_fid.close() if not args["expand"]: bolts_fid.write("include <common/version.scad>\n") else: bolts_fid.write(open(join(out_path,"common","version.scad")).read()) makedirs(join(out_path,"base")) makedirs(join(out_path,"classes")) for scadfile, in self.dbs["openscad"].iterscadfiles(): if not license.is_combinable_with(scadfile.license_name,args["target_license"]): continue #copy base files makedirs(join(out_path,"base",dirname(scadfile.path))) copy(join(self.dbs["openscad"].backend_root,scadfile.path),join(out_path,"base",scadfile.path)) #include files if not args["expand"]: bolts_fid.write("include <base/%s>\n" % scadfile.path) else: bolts_fid.write(open(join(out_path,"base",scadfile.path)).read()) #process classes for cl, module in self.dbs["openscad"].iterclasses(["class","module"],filter_scadfile = scadfile): with open(join(out_path,"classes","%s.scad" % cl.id),"w") as cl_fid: self.write_classfile(cl_fid,cl,module) if not args["expand"]: bolts_fid.write("include <classes/%s.scad>\n" % cl.id) else: bolts_fid.write(open(join(out_path,"classes","%s.scad" % cl.id)).read())
def write_output(self, out_path, **kwargs): args = self.validate_arguments(kwargs, ["target_license", "version"]) self.clear_output_dir(out_path) bolts_path = join(out_path, "BOLTS") #generate macro start_macro = open(join(out_path, "start_bolts.FCMacro"), "w") start_macro.write("import BOLTS\n") start_macro.write("BOLTS.show_widget()\n") start_macro.close() #copy files #bolttools if not license.is_combinable_with("LGPL 2.1+", args["target_license"]): raise IncompatibleLicenseError( "bolttools is LGPL 2.1+, which is not compatible with %s" % args["target_license"]) copytree(join(self.repo.path, "bolttools"), join(bolts_path, "bolttools")) #remove the test suite and documentation, to save space rmtree(join(bolts_path, "bolttools", "test_blt")) #generate version file date = datetime.now() version_file = open(join(bolts_path, "VERSION"), "w") version_file.write("%s\n%d-%d-%d\n%s\n" % (args["version"], date.year, date.month, date.day, args["target_license"])) version_file.close() #freecad gui code if not license.is_combinable_with("LGPL 2.1+", args["target_license"]): raise IncompatibleLicenseError( "FreeCAD gui files are LGPL 2.1+, which is not compatible with %s" % args["target_license"]) if not exists(join(bolts_path, "freecad")): makedirs(join(bolts_path, "freecad")) if not exists(join(bolts_path, "data")): makedirs(join(bolts_path, "data")) open(join(bolts_path, "freecad", "__init__.py"), "w").close() copytree(join(self.repo.path, "backends", "freecad", "gui"), join(bolts_path, "gui")) copytree(join(self.repo.path, "backends", "freecad", "assets"), join(bolts_path, "assets")) copytree(join(self.repo.path, "icons"), join(bolts_path, "icons")) copyfile(join(self.repo.path, "backends", "freecad", "init.py"), join(bolts_path, "__init__.py")) open(join(bolts_path, "gui", "__init__.py"), "w").close() #compile ui files uic.compileUiDir(join(bolts_path, "gui")) for coll, in self.repo.itercollections(): if not license.is_combinable_with(coll.license_name, args["target_license"]): continue copy(join(self.repo.path, "data", "%s.blt" % coll.id), join(bolts_path, "data", "%s.blt" % coll.id)) if not exists(join(bolts_path, "freecad", coll.id)): makedirs(join(bolts_path, "freecad", coll.id)) if not exists( join(self.repo.path, "freecad", coll.id, "%s.base" % coll.id)): continue copy(join(self.repo.path, "freecad", coll.id, "%s.base" % coll.id), join(bolts_path, "freecad", coll.id, "%s.base" % coll.id)) open(join(bolts_path, "freecad", coll.id, "__init__.py"), "w").close() for base, in self.dbs["freecad"].iterbases(filter_collection=coll): if not base.license_name in license.LICENSES: continue if not license.is_combinable_with(base.license_name, args["target_license"]): continue copy( join(self.repo.path, "freecad", coll.id, basename(base.filename)), join(bolts_path, "freecad", coll.id, basename(base.filename)))
def write_output(self, out_path, target_license, version, stable=False): self.clear_output_dir(out_path) bolts_path = join(out_path, "BOLTS") #generate macro start_macro = open(join(out_path, "start_bolts.FCMacro"), "w") start_macro.write("import BOLTS\n") start_macro.close() #copy files #bolttools if not license.is_combinable_with("LGPL 2.1+", target_license): raise IncompatibleLicenseError( "bolttools licensed under LGPL 2.1+, which is not compatible with %s" % target_license) copytree(join(self.repo.path, "bolttools"), join(bolts_path, "bolttools")) #remove the .git file, because it confuses git remove(join(bolts_path, "bolttools", ".git")) #remove the test suite and documentation, to save space rmtree(join(bolts_path, "bolttools", "test")) rmtree(join(bolts_path, "bolttools", "doc")) #generate version file date = datetime.now() version_file = open(join(bolts_path, "VERSION"), "w") version_file.write( "%s\n%d-%d-%d\n%s\n" % (version, date.year, date.month, date.day, target_license)) version_file.close() #freecad gui code if not license.is_combinable_with("LGPL 2.1+", target_license): raise IncompatibleLicenseError( "FreeCAD gui files are licensed under LGPL 2.1+, which is not compatible with %s" % target_license) if not exists(join(bolts_path, "freecad")): makedirs(join(bolts_path, "freecad")) if not exists(join(bolts_path, "data")): makedirs(join(bolts_path, "data")) open(join(bolts_path, "freecad", "__init__.py"), "w").close() copytree(join(self.repo.path, "backends", "freecad", "gui"), join(bolts_path, "gui")) copytree(join(self.repo.path, "backends", "freecad", "assets"), join(bolts_path, "assets")) copytree(join(self.repo.path, "icons"), join(bolts_path, "icons")) copyfile(join(self.repo.path, "backends", "freecad", "init.py"), join(bolts_path, "__init__.py")) open(join(bolts_path, "gui", "__init__.py"), "w").close() #compile ui files uic.compileUiDir(join(bolts_path, "gui")) for coll in self.repo.collections: if not license.is_combinable_with(coll.license_name, target_license): continue copy(join(self.repo.path, "data", "%s.blt" % coll.id), join(bolts_path, "data", "%s.blt" % coll.id)) if not exists(join(bolts_path, "freecad", coll.id)): makedirs(join(bolts_path, "freecad", coll.id)) if not exists( join(self.repo.path, "freecad", coll.id, "%s.base" % coll.id)): continue copy(join(self.repo.path, "freecad", coll.id, "%s.base" % coll.id), join(bolts_path, "freecad", coll.id, "%s.base" % coll.id)) open(join(bolts_path, "freecad", coll.id, "__init__.py"), "w").close() for cl in coll.classes: base = self.freecad.getbase[cl.id] if not base.license_name in license.LICENSES: continue if not license.is_combinable_with(base.license_name, target_license): continue copy( join(self.repo.path, "freecad", coll.id, basename(base.filename)), join(bolts_path, "freecad", coll.id, basename(base.filename)))