示例#1
0
 def createFromFileName(cls, configFileName):
     checkString('configFileName', configFileName)
     obj = cls()
     obj.fileName = configFileName
     configFile = open(configFileName, 'r')
     obj.data = json.loads(configFile.read())
     configFile.close()
     obj._validate()
     return (obj)
示例#2
0
def processField(name, value, templatesCatalog=None):
    if (name.startswith('subTemplateList')):
        if (templatesCatalog is None):
            raise Exception(
                'A TemplatesCatalog instance is required to process subTemplateList fields'
            )

        nameParts = name.split('_')
        if (len(nameParts) != 3):
            raise Exception(
                'subTemplateList fieldName in dataFile must have format: subTemplateList_<subTemplateId>_<semantics>'
            )
        name_ = str(nameParts[0])
        subTemplateId = int(nameParts[1])
        chkTemplateId(subTemplateId)

        subTemplate = templatesCatalog.getTemplate(subTemplateId)
        subTemplateSemantics = parseSemantics(str(nameParts[2]))
        subTemplateList = ADT_SubTemplateList.create(subTemplateSemantics,
                                                     subTemplate)
        numFields = subTemplate.getNumFields()

        checkString('processor_SubTemplateList.value', value)
        for vEntry in value.split(';'):
            vEntryItems = vEntry.split('|')
            if (len(vEntryItems) != numFields):
                raise Exception('SubTemplate %d requires %d fields' %
                                (subTemplateId, numFields))

            dataRecord = {}
            for numField in xrange(numFields):
                nameField = subTemplate.getField(numField).getName()
                nameField_, vEntryItem = processField(nameField,
                                                      vEntryItems[numField],
                                                      templatesCatalog)
                dataRecord[nameField_] = vEntryItem

            subTemplateList.addDataRecord(dataRecord)
        return (name_, subTemplateList)
    else:
        parser = __FIELD_PARSERS.get(name)
        if (parser is None):
            raise Exception('FieldParser for %s not defined' % name)

        checker = __FIELD_CHECKERS.get(name)
        if (checker is None):
            raise Exception('FieldChecker for %s not defined' % name)

        translator = __FIELD_TRANSLATORS.get(name)
        if (translator is None):
            raise Exception('FieldChecker for %s not defined' % name)

        value = parser(value)
        checker(value)
        value = translator(value)
        return (name, value)
示例#3
0
def readFile(path):
    ''' return None if file does not exist, otherwise its content '''
    strFilePath = checkString('filePath', path)
    if (not fileExists(strFilePath)): return (None)
    f = open(strFilePath, 'r')
    content = f.read()
    f.close()
    return (content)
示例#4
0
    def checkConfiguration(config):
        checkOptions('screenSeverity', checkAttr('screenSeverity', config),
                     LoggerConfigurator.SEVERITY)
        if ('screenFormatter' in config):
            checkString('screenFormatter', config['screenFormatter'])

        checkOptions('fileSeverity', checkAttr('fileSeverity', config),
                     LoggerConfigurator.SEVERITY)
        checkString('fileName', checkAttr('fileName', config))
        if ('fileFormatter' in config):
            checkString('fileFormatter', config['fileFormatter'])
示例#5
0
文件: _Object.py 项目: lgifre/pyTools
 def __init__(self, name):
     checkString('name', name)
     self._name = name
     self._configured = False
     self._running = False
示例#6
0
 def __init__(self, name, *args, **kwargs):
     self._configured = False
     self._running = False
     checkString('name', name)
     self._name = name
     object.__init__(self, *args, **kwargs)
示例#7
0
    'direction': lambda v: str(v),
    'ber': lambda v: float(v),
    'rxPowerMilliwatts': lambda v: float(v),
    'txPowerMilliwatts': lambda v: float(v),
    'rxPowerDecibelMilliwatts': lambda v: float(v),
    'txPowerDecibelMilliwatts': lambda v: float(v),
    'frequencyGigaHertz': lambda v: float(v),
    'stlPaginationIndex': lambda v: int(v),
    'stlPaginationTotal': lambda v: int(v),
}

__FIELD_CHECKERS = {
    'timeStamp':
    lambda v: checkInteger('timeStamp', v, 0),
    'name':
    lambda v: checkString('name', v),
    'containerName':
    lambda v: checkString('containerName', v),
    'observationDomainId':
    lambda v: checkInteger('observationDomainId', v, 0, 4294967295),
    'observationPointId':
    lambda v: checkInteger('observationPointId', v, 0),
    'flowDirection':
    lambda v: checkOptions('flowDirection', v, ['ingress', 'egress']),
    'sourceMacAddress':
    lambda v: checkMACAddr('sourceMacAddress', v),
    'destinationMacAddress':
    lambda v: checkMACAddr('destinationMacAddress', v),
    'ethernetType':
    lambda v: checkOptions('ethernetType', v, ['ARP', 'IPv4', 'IPv6', 'MPLS']),
    'ethernetHeaderLength':
示例#8
0
def writeFile(path, data):
    ''' write data in file pointed by path '''
    strFilePath = checkString('filePath', path)
    f = open(strFilePath, 'w')
    f.write(data)
    f.close()
示例#9
0
 def __format(self, strCommand):
     checkString('command', strCommand)
     return(strCommand.replace('\n', '').replace('\t', ' ').split(' '))
示例#10
0
 def createFromString(cls, data):
     checkString('data', data)
     obj = cls()
     obj.data = json.loads(data)
     obj._validate()
     return (obj)