def __init__(self, repo): DataBase.__init__(self, "solidworks", repo) self.designtables = [] if not exists(self.backend_root): e = MalformedRepositoryError("solidworks directory does not exist") e.set_repo_path(repo.path) raise e for coll in listdir(self.backend_root): basefilename = join(self.backend_root, coll, "%s.base" % coll) if not exists(basefilename): #skip directory that is no collection continue base = list(yaml.load_all(open(basefilename, "r", "utf8"))) if len(base) != 1: raise MalformedCollectionError( "No YAML document found in file %s" % basefilename) base = base[0] for designtable in base: if not designtable["type"] == "solidworks": continue self.designtables.append( DesignTable(designtable, coll, self.backend_root))
def __init__(self, repo): DataBase.__init__(self, "solidworks", repo) self.designtables = [] if not exists(self.backend_root): e = MalformedRepositoryError("solidworks directory does not exist") e.set_repo_path(repo.path) raise e for coll in listdir(self.backend_root): basefilename = join(self.backend_root, coll, "%s.base" % coll) if not exists(basefilename): #skip directory that is no collection continue try: base = list( yaml.load_all(open(basefilename, "r", "utf8"), Loader=yaml.SafeLoader)) # SafeLoader is not implemented in pyyaml < 5.1 except AttributeError: # this is deprecated for newer pyyaml versions base = list(yaml.load_all(open(basefilename, "r", "utf8"))) if len(base) != 1: raise MalformedCollectionError( "No YAML document found in file %s" % basefilename) base = base[0] for designtable in base: if not designtable["type"] == "solidworks": continue self.designtables.append( DesignTable(designtable, coll, self.backend_root))
def __init__(self,path): DataBase.__init__(self,"drawings", path) self.getbase = {} if not exists(path): e = MalformedRepositoryError("Repo directory does not exist") e.set_repo_path(path) raise e if not exists(join(self.backend_root)): e = MalformedRepositoryError("drawings directory does not exist") e.set_repo_path(path) raise e for coll in listdir(self.backend_root): basefilename = join(self.backend_root,coll,"%s.base" % coll) if not exists(basefilename): #skip directory that is no collection continue base_info = list(yaml.load_all(open(basefilename,"r","utf8"))) if len(base_info) != 1: raise MalformedCollectionError( "Not exactly one YAML document found in file %s" % basefilename) base_info = base_info[0] for drawing_element in base_info: draw = Drawing(drawing_element, coll, self.backend_root) for id in drawing_element["classids"]: self.getbase[id] = draw
def __init__(self,path): DataBase.__init__(self,"solidworks",path) self.designtables = [] if not exists(path): e = MalformedRepositoryError("Repo directory does not exist") e.set_repo_path(path) raise e if not exists(join(self.backend_root)): e = MalformedRepositoryError("solidworks directory does not exist") e.set_repo_path(path) raise e for coll in listdir(self.backend_root): basefilename = join(self.backend_root,coll,"%s.base" % coll) if not exists(basefilename): #skip directory that is no collection continue base = list(yaml.load_all(open(basefilename,"r","utf8"))) if len(base) != 1: raise MalformedCollectionError( "No YAML document found in file %s" % basefilename) base = base[0] for designtable in base: if not designtable["type"] == "solidworks": continue self.designtables.append(DesignTable(designtable,coll,self.backend_root))
def __init__(self,repo): DataBase.__init__(self,"drawings", repo) self.dimdrawings = [] self.condrawings = [] self.conlocations = [] self.dimdrawing_classes = Links() self.condrawings_classes = BipartiteLinks() self.conlocations_condrawings = BipartiteLinks() self.collection_dimdrawings = Links() self.collection_condrawings = Links() if not exists(join(self.backend_root)): e = MalformedRepositoryError("drawings directory does not exist") e.set_repo_path(path) raise e for coll in listdir(self.backend_root): basefilename = join(self.backend_root,coll,"%s.base" % coll) if not exists(basefilename): #skip directory that is no collection continue if coll not in repo.collections: raise MalformedRepositoryError( "Drawings for unknown collection found: %s " % coll) base_info = list(yaml.load_all(open(basefilename,"r","utf8"))) if len(base_info) != 1: raise MalformedCollectionError( "Not exactly one YAML document found in file %s" % basefilename) base_info = base_info[0] for drawing_element in base_info: if drawing_element["type"] == "drawing-dimensions": draw = DrawingDimensions(drawing_element,coll,self.backend_root) if draw.get_svg() is None and draw.get_png() is None: raise MalformedRepositoryError("No drawing files present for %s/%s" % (coll,draw.filename)) self.dimdrawings.append(draw) if drawing_element["classids"] == []: raise MalformedBaseError("Drawing with no associated classes found") for id in drawing_element["classids"]: self.dimdrawing_classes.add_link(draw,self.repo.classes[id]) self.collection_dimdrawings.add_link(repo.collections[coll],draw) if drawing_element["type"] == "drawing-connector": draw = DrawingConnectors(drawing_element,coll,self.backend_root) if draw.get_svg() is None and draw.get_png() is None: raise MalformedRepositoryError("No drawing files present for %s/%s" % (coll,draw.filename)) if not draw.location in self.conlocations: self.conlocations.append(draw.location) self.conlocations_condrawings.add_link(draw.location,draw) self.condrawings.append(draw) for id in drawing_element["classids"]: self.condrawings_classes.add_link(draw,self.repo.classes[id]) self.collection_condrawings.add_link(repo.collections[coll],draw)
def __init__(self,repo): DataBase.__init__(self,"openscad",repo) self.modules = [] self.scadfiles = [] self.connectors = [] self.module_classes = Links() self.scadfile_modules = Links() self.collection_modules = Links() self.collection_scadfiles = Links() self.module_connectors = BijectiveLinks() if not exists(join(self.backend_root)): e = MalformedRepositoryError("openscad directory does not exist") e.set_repo_path(repo.path) raise e for coll in listdir(self.backend_root): basefilename = join(self.backend_root,coll,"%s.base" % coll) if not exists(basefilename): #skip directory that is no collection continue base = list(yaml.load_all(open(basefilename,"r","utf8"))) if len(base) != 1: raise MalformedCollectionError( "No YAML document found in file %s" % basefilename) base = base[0] for basefile in base: scadfile = SCADFile(basefile,coll) self.scadfiles.append(scadfile) self.collection_scadfiles.add_link(repo.collections[coll],scadfile) if basefile["type"] == "module": for mod in basefile["modules"]: try: module = SCADModule(mod,basefile,coll) self.modules.append(module) self.collection_modules.add_link(repo.collections[coll],module) self.scadfile_modules.add_link(scadfile,module) if "connectors" in mod: connectors = Connectors(mod["connectors"]) self.module_connectors.add_link(module,connectors) for id in module.classids: if not id in repo.classes: raise MalformedBaseError( "Unknown class %s" % id) if self.module_classes.contains_dst(repo.classes[id]): raise NonUniqueBaseError(id) self.module_classes.add_link(module,repo.classes[id]) except ParsingError as e: e.set_base(basefile["filename"]) raise e else: raise MalformedBaseError("Unknown base type %s" % basefile["type"])
def __init__(self,path): DataBase.__init__(self,"freecad",path) self.getbase = {} if not exists(path): e = MalformedRepositoryError("Repo directory does not exist") e.set_repo_path(path) raise e if not exists(join(self.backend_root)): e = MalformedRepositoryError("freecad directory does not exist") e.set_repo_path(path) raise e for coll in listdir(self.backend_root): basefilename = join(self.backend_root,coll,"%s.base" % coll) if not exists(basefilename): #skip directory that is no collection continue base_info = list(yaml.load_all(open(basefilename,"r","utf8"))) if len(base_info) != 1: raise MalformedCollectionError( "Not exactly one YAML document found in file %s" % basefilename) base_info = base_info[0] for basefile in base_info: if basefile["type"] == "function": basepath = join(self.backend_root,coll,"%s.py" % coll) if not exists(basepath): raise MalformedBaseError("Python module %s does not exist" % basepath) for func in basefile["functions"]: try: function = BaseFunction(func,basefile,coll,self.backend_root) for id in func["classids"]: if id in self.getbase: raise NonUniqueBaseError(id) self.getbase[id] = function except ParsingError as e: e.set_base(basefile["filename"]) e.set_collection(coll) raise e elif basefile["type"] == "fcstd": basepath = join(self.backend_root,coll,basefile["filename"]) if not exists(basepath): continue for obj in basefile["objects"]: try: fcstd = BaseFcstd(obj,basefile,coll,self.backend_root) for id in obj["classids"]: if id in self.getbase: raise NonUniqueBaseError(id) self.getbase[id] = fcstd except ParsingError as e: e.set_base(basefile["filename"]) e.set_collection(coll) raise e
def __init__(self,path): DataBase.__init__(self,"openscad",path) #maps class id to base module self.getbase = {} if not exists(path): e = MalformedRepositoryError("Repo directory does not exist") e.set_repo_path(path) raise e if not exists(join(self.backend_root)): e = MalformedRepositoryError("openscad directory does not exist") e.set_repo_path(path) raise e for coll in listdir(self.backend_root): basefilename = join(self.backend_root,coll,"%s.base" % coll) if not exists(basefilename): #skip directory that is no collection continue base = list(yaml.load_all(open(basefilename,"r","utf8"))) if len(base) != 1: raise MalformedCollectionError( "No YAML document found in file %s" % basefilename) base = base[0] for basefile in base: if basefile["type"] == "module": for mod in basefile["modules"]: try: module = BaseModule(mod,basefile,coll) for id in module.classids: if id in self.getbase: raise NonUniqueBaseError(id) self.getbase[id] = module except ParsingError as e: e.set_base(basefile["filename"]) raise e elif basefile["type"] == "stl": try: module = BaseSTL(basefile,coll) for id in module.classids: if id in self.getbase: raise NonUniqueBaseError(id) self.getbase[id] = module except ParsingError as e: e.set_base(basefile["filename"]) raise e
def __init__(self,repo): DataBase.__init__(self,"freecad",repo) self.bases = [] self.base_classes = Links() self.collection_bases = Links() if not exists(self.backend_root): e = MalformedRepositoryError("freecad directory does not exist") e.set_repo_path(repo.path) raise e for coll in listdir(self.backend_root): basefilename = join(self.backend_root,coll,"%s.base" % coll) if not exists(basefilename): #skip directory that is no collection continue base_info = list(yaml.load_all(open(basefilename,"r","utf8"))) if len(base_info) != 1: raise MalformedCollectionError( "Not exactly one YAML document found in file %s" % basefilename) base_info = base_info[0] for basefile in base_info: if basefile["type"] == "function": basepath = join(self.backend_root,coll,basefile["filename"]) if not exists(basepath): raise MalformedBaseError("Python module %s does not exist" % basepath) for func in basefile["functions"]: try: function = BaseFunction(func,basefile,coll,self.backend_root) self.bases.append(function) self.collection_bases.add_link(repo.collections[coll],function) for id in func["classids"]: if not id in repo.classes: raise MalformedBaseError( "Unknown class %s" % id) if self.base_classes.contains_dst(repo.classes[id]): raise NonUniqueBaseError(id) self.base_classes.add_link(function,repo.classes[id]) except ParsingError as e: e.set_base(basefile["filename"]) e.set_collection(coll) raise e else: raise MalformedBaseError("Unknown base type %s" % basefile["type"])
def __init__(self,path): DataBase.__init__(self,"drawings", path) self.getdimensions = {} self.getconnectors = {} if not exists(path): e = MalformedRepositoryError("Repo directory does not exist") e.set_repo_path(path) raise e if not exists(join(self.backend_root)): e = MalformedRepositoryError("drawings directory does not exist") e.set_repo_path(path) raise e for coll in listdir(self.backend_root): basefilename = join(self.backend_root,coll,"%s.base" % coll) if not exists(basefilename): #skip directory that is no collection continue base_info = list(yaml.load_all(open(basefilename,"r","utf8"))) if len(base_info) != 1: raise MalformedCollectionError( "Not exactly one YAML document found in file %s" % basefilename) base_info = base_info[0] for drawing_element in base_info: if drawing_element["type"] == "drawing-dimensions": draw = DrawingDimensions(drawing_element, coll, self.backend_root) for id in drawing_element["classids"]: self.getdimensions[id] = draw if drawing_element["type"] == "drawing-connector": draw = DrawingConnectors(drawing_element, coll, self.backend_root) for id in drawing_element["classids"]: if not id in self.getconnectors: self.getconnectors[id] = {draw.location: draw} elif draw.location not in self.getconnectors[id]: self.getconnectors[id][draw.location] = draw else: raise MalformedRepositoryError("More than one drawing for location %s of class %s" % (draw.location,id))
def __init__(self, repo): DataBase.__init__(self, "openscad", repo) self.modules = [] self.scadfiles = [] self.connectors = [] self.module_classes = Links() self.scadfile_modules = Links() self.collection_modules = Links() self.collection_scadfiles = Links() self.module_connectors = BijectiveLinks() if not exists(join(self.backend_root)): e = MalformedRepositoryError("openscad directory does not exist") e.set_repo_path(repo.path) raise e for coll in listdir(self.backend_root): basefilename = join(self.backend_root, coll, "%s.base" % coll) if not exists(basefilename): #skip directory that is no collection continue base = list(yaml.load_all(open(basefilename, "r", "utf8"))) if len(base) != 1: raise MalformedCollectionError( "No YAML document found in file %s" % basefilename) base = base[0] for basefile in base: scadfile = SCADFile(basefile, coll) self.scadfiles.append(scadfile) self.collection_scadfiles.add_link(repo.collections[coll], scadfile) if basefile["type"] == "module": for mod in basefile["modules"]: try: module = SCADModule(mod, basefile, coll) self.modules.append(module) self.collection_modules.add_link( repo.collections[coll], module) self.scadfile_modules.add_link(scadfile, module) if "connectors" in mod: connectors = Connectors(mod["connectors"]) self.module_connectors.add_link( module, connectors) for id in module.classids: if not id in repo.classes: raise MalformedBaseError( "Unknown class %s" % id) if self.module_classes.contains_dst( repo.classes[id]): raise NonUniqueBaseError(id) self.module_classes.add_link( module, repo.classes[id]) except ParsingError as e: e.set_base(basefile["filename"]) raise e else: raise MalformedBaseError("Unknown base type %s" % basefile["type"])
def __init__(self, repo): DataBase.__init__(self, "drawings", repo) self.dimdrawings = [] self.condrawings = [] self.conlocations = [] self.dimdrawing_classes = Links() self.condrawings_classes = BipartiteLinks() self.conlocations_condrawings = BipartiteLinks() self.collection_dimdrawings = Links() self.collection_condrawings = Links() if not exists(join(self.backend_root)): e = MalformedRepositoryError("drawings directory does not exist") e.set_repo_path(path) raise e for coll in listdir(self.backend_root): basefilename = join(self.backend_root, coll, "%s.base" % coll) if not exists(basefilename): #skip directory that is no collection continue if coll not in repo.collections: raise MalformedRepositoryError( "Drawings for unknown collection found: %s " % coll) base_info = list(yaml.load_all(open(basefilename, "r", "utf8"))) if len(base_info) != 1: raise MalformedCollectionError( "Not exactly one YAML document found in file %s" % basefilename) base_info = base_info[0] for drawing_element in base_info: if drawing_element["type"] == "drawing-dimensions": draw = DrawingDimensions(drawing_element, coll, self.backend_root) if draw.get_svg() is None and draw.get_png() is None: raise MalformedRepositoryError( "No drawing files present for %s/%s" % (coll, draw.filename)) self.dimdrawings.append(draw) if drawing_element["classids"] == []: raise MalformedBaseError( "Drawing with no associated classes found") for id in drawing_element["classids"]: self.dimdrawing_classes.add_link( draw, self.repo.classes[id]) self.collection_dimdrawings.add_link( repo.collections[coll], draw) if drawing_element["type"] == "drawing-connector": draw = DrawingConnectors(drawing_element, coll, self.backend_root) if draw.get_svg() is None and draw.get_png() is None: raise MalformedRepositoryError( "No drawing files present for %s/%s" % (coll, draw.filename)) if not draw.location in self.conlocations: self.conlocations.append(draw.location) self.conlocations_condrawings.add_link(draw.location, draw) self.condrawings.append(draw) for id in drawing_element["classids"]: self.condrawings_classes.add_link( draw, self.repo.classes[id]) self.collection_condrawings.add_link( repo.collections[coll], draw)