Ejemplo n.º 1
0
 def __init__(self, file_path, name=None, logger=None, required_attributes=None):
     '''
     Circuit Constructor
     
     @input: 
         filename - the file name of the circuit
         name(Opt) - a given name for the circuit
         required_attributes(Opt) - enforce all components have the given attributes
     @output: None
     
     Creates an internal component and unique_component list for easy BOM generation
     '''
     #Logging
     if not logger:
         self.logger = log.getDefaultLogger('circuit.Circuit')
     else:
         self.logger = logger
         
     #Check whether file exists
     if not os.path.isfile(file_path):
         raise SchematicFileError("file does not exist: %s"%(file_path))
     
     #Check .sch file type
     if os.path.splitext(file_path)[1] != ".sch":
         raise SchematicFileError("Given file must have a .sch extension")
     
     #
     #Set attributes
     #
     self.file_path = file_path
     self.file_name = os.path.split(file_path)[1]
     if not name:
         self.name = os.path.splitext(self.file_name)[0]
         self.logger.debug('assigned automatic name to circuit: %s'%(self.getName()))
     else:
         self.name = name
     self.required_attributes = required_attributes
     self.component_list = component.SchematicComponentList()
     self.unique_components = component.BOMComponentList()
     self.restrictedDevices = ['INPUT', 'OUTPUT', 'NET']
     self.ignoreMultipleRefdes = True
     self._ignored = []
     
     
     #
     #Regex's
     #
     
     # Regex for a new component
     self.component_re = re.compile(r"^C(.*?)\n\{(.*?)\}", re.M|re.S)
     
     #Regex for an attribute within a component 
     self.attribute_re = re.compile(r"^(.+)=(.+)", re.M)
     
     #Regex for a variable value attribute
     self.schematic_variable_flag = _variable_flag
     self.variable_value_re = re.compile(r"^value="+_variable_flag_re+"(.+)", re.M)
Ejemplo n.º 2
0
 def __init__(self, file_path, name=None, logger=None, type_=None):
     #Logger init
     if not logger:
         self.logger = log.getDefaultLogger('circuit.Netlist')
     else:
         self.logger = logger
     
     #Name init
     if not name:
         try:
             self.name = os.path.splitext(os.path.split(file_path)[1])[0]
         except:
             self.logger.error("Error in split")
             raise NetlistError("Name could not be assigned")
     else:
         self.name = name
     
     
     #file_path init
     self.file_path = file_path
     if not os.path.isfile(os.path.normpath(file_path)):
         raise NetlistError("File does not exist")
     
     #Template
     self.template = string.Template(open(self.file_path, 'r').read())   
     
     #temp file_path
     path, ext = os.path.splitext(self.file_path)
     self.temp_file_path = path + '.tmp' + ext
     self.temp_file_name = os.path.split(self.temp_file_path)[1]
     
     
     #type init
     if not type_:
         self.setType(self._default_type)
     else:
         self.setType(type_)    
         
     
     #Regex
     self.comment_re = r"\*"
     self.variable_re = re.compile(r"^[^"+self.comment_re+r"].*" + _variable_flag_re + r"(\w+)", re.M)
     
     self.variables = []