Example #1
0
 def __init__(self, key=None, value=None):
     OrderedDict.__init__(self)
     if key != None and value != None:
         self[key] = value
         self._name = value
         self._nametype = key
     else:
         self._name = ''
         self._nametype = ''
Example #2
0
    def readLine(self, line):
        '''
        Reads a single line from the stanza, extracting the key-value pair
        '''

        if line.startswith('#') or line == '':
            OrderedDict.append(self, line)
        else:
            raKey = line.split(' ', 1)[0].strip()
            raVal = ''
            if (len(line.split(' ', 1)) == 2):
                raVal = line.split(' ', 1)[1].strip()
            #if raKey in self:
                #raise KeyError(raKey + ' already exists')
            self[raKey] = raVal
Example #3
0
    def read(self, filePath, key=None):
        '''
        Reads an rafile stanza by stanza, and internalizes it. Don't override
        this for derived types, instead override readStanza.
        '''
        self._filename = filePath
        file = open(filePath, 'r')
        scopes = list()

        #entry = None
        stanza = list()
        keyValue = ''

        reading = 1
        
        while reading:
            line = file.readline() # get the line
            if line == '':
                reading = 0
        
            # if its a comment or whitespace we append it to the list representation and ignore in dict
            #line = line.strip()
            if len(stanza) == 0 and (line.strip().startswith('#') or (line.strip() == '' and reading)):
                OrderedDict.append(self, line)
                continue

            if line.strip() != '':
                stanza.append(line)
            elif len(stanza) > 0:
                if keyValue == '':
                    keyValue, name, entry = self.readStanza(stanza, key)
                else:
                    testKey, name, entry = self.readStanza(stanza, key)
                    if entry != None and keyValue != testKey:
                        raise KeyError('Inconsistent Key ' + testKey)

                if entry != None:
                    if name != None or key == None:
                        if name in self:
                            print KeyError('Duplicate Key ' + name)
                        self[name] = entry

                stanza = list()

        file.close()
Example #4
0
	def __init__(self, keys):
		self._name = ''
		self.keys = keys
		OrderedDict.__init__(self)
Example #5
0
	def __init__(self, filePath=''):
		OrderedDict.__init__(self)
		if filePath != '':
			self.read(filePath) 
Example #6
0
File: soft.py Project: bowhan/kent
 def __init__(self, keys, parent):
     self._name = ''
     self._keys = keys
     self.parent = parent
     OrderedDict.__init__(self)
Example #7
0
 def __init__(self):
     self._name = ''
     self._nametype = ''
     OrderedDict.__init__(self)
Example #8
0
 def __init__(self, filePath=None, key=None):
     OrderedDict.__init__(self)
     if filePath != None and os.path.isfile(filePath):
         self.read(filePath, key)
     else:
         self._filename = filePath
Example #9
0
 def append(self, item):
     OrderedDict.append(self, item)
Example #10
0
 def __init__(self, filePath=None, key=None):
     OrderedDict.__init__(self)
     if filePath != None:
         self.read(filePath, key)