Exemple #1
0
    def getTasks(self):
        #! self._tasks 与 缓存中的task是不同
        if not hasattr(self, '_tasks'):
            self._tasks = []
        if self._tasks:
            return self._tasks

        tasks = self.getCache('tasks')
        if not tasks:
            return []

        # 忽略掉做种的任务
        exclude_status = ['seeding']
        tasks = filter(lambda t: t['status'] not in exclude_status, tasks)
        tasks = filter(lambda t: t['type'] in ['http', 'emule'], tasks)

        hr = lambda s: self.ds.humanReadable(s)
        parsed_tasks = []
        for task in tasks:
            transfer = task['additional']['transfer']
            detail = task['additional']['detail']
            try:
                progress = float(transfer['size_downloaded']) / float(task['size'])
            except:
                progress = 0.0
            status_desc = task['status'].title()
            if task['status'] == 'error':
                status_desc = '{}: {}'.format(status_desc, task['status_extra']['error_detail'])
            new_task = {
                'title'                 : task['title'],
                'id'                    : task['id'],
                'type'                  : task['type'],
                'type_desc'             : 'eMule' if task['type']=='emule' else task['type'].upper(),
                'status'                : task['status'],
                'status_desc'           : status_desc,
                'username'              : task['username'],
                'uri'                   : detail['uri'],
                'size'                  : util.toInt(task['size']),
                'size_downloaded'       : util.toInt(transfer['size_downloaded']),
                'size_uploaded'         : util.toInt(transfer['size_uploaded']),
                'speed_download'        : util.toInt(transfer['speed_download']),
                'speed_upload'          : util.toInt(transfer['speed_upload']),
                'hr_size'               : hr(task['size']),
                'hr_size_downloaded'    : hr(transfer['size_downloaded']),
                'hr_size_uploaded'      : hr(transfer['size_uploaded']),
                'hr_speed_download'     : hr(transfer['speed_download']),
                'hr_speed_upload'       : hr(transfer['speed_upload']),
                'progress'              : progress,
                'progress_percent'      : '{:.2%}'.format(progress)
            }
            new_task.update({
                'desc'  : '{hr_size:10}{hr_size_downloaded:10}{progress_percent:8} DL: {hr_speed_download:8} UL: {hr_speed_upload:8}{type_desc:8}{status_desc:15}'.format(**new_task)
                })
            parsed_tasks.append(new_task)
        self._tasks = sorted(parsed_tasks, key=lambda t:t['title'].lower())
        return self._tasks
Exemple #2
0
    def parseTasks(self, tasks):
        # 忽略掉做种的任务
        exclude_status = ["seeding"]
        tasks = filter(lambda t: t["status"] not in exclude_status, tasks)

        hr = lambda s: dslibHumanReadable(s)
        parsed_tasks = []
        for task in tasks:
            transfer = task["additional"]["transfer"]
            detail = task["additional"]["detail"]
            try:
                progress = float(transfer["size_downloaded"]) / float(task["size"])
            except:
                progress = 0.0
            status_desc = task["status"].title()
            if task["status"] == "error":
                status_desc = "{}: {}".format(status_desc, task["status_extra"]["error_detail"])
            new_task = {
                "title": task["title"],
                "id": task["id"],
                "type": task["type"],
                "type_desc": "eMule" if task["type"] == "emule" else task["type"].upper(),
                "status": task["status"],
                "status_desc": status_desc,
                "username": task["username"],
                "uri": detail["uri"],
                "size": util.toInt(task["size"]),
                "size_downloaded": util.toInt(transfer["size_downloaded"]),
                "size_uploaded": util.toInt(transfer["size_uploaded"]),
                "speed_download": util.toInt(transfer["speed_download"]),
                "speed_upload": util.toInt(transfer["speed_upload"]),
                "hr_size": hr(task["size"]),
                "hr_size_downloaded": hr(transfer["size_downloaded"]),
                "hr_size_uploaded": hr(transfer["size_uploaded"]),
                "hr_speed_download": hr(transfer["speed_download"]),
                "hr_speed_upload": hr(transfer["speed_upload"]),
                "progress": progress,
                "progress_percent": "{:.2%}".format(progress),
            }
            new_task.update(
                {
                    "desc": "{hr_size:10}{hr_size_downloaded:10}{progress_percent:8} DL: {hr_speed_download:8} UL: {hr_speed_upload:8}{type_desc:8}{status_desc:15}".format(
                        **new_task
                    )
                }
            )
            parsed_tasks.append(new_task)
        return sorted(parsed_tasks, key=lambda t: t["title"].lower())
Exemple #3
0
 def parseAddress(self, reg):
     """ This method parses the user given address value.
     
     This address value can be several formats:
         - <integer> This is the simplest way. The user can place a register into a given address.
             The integer format can be deimal or hexadecimal (starts with '0x')
         - <-1> or None: This indicates automatic register address resolution. YARD can resolve
             addresses. This is the recommended way.
         - value[:stride:<count>[:<increment>]] indicates register-arrays. Value count and
             increment (if exists) must be integers. The value describes the start address, the
             count indicates the size of the register-array. The increment indicates the
             *address-differences* between the consecutive registers.
     """
     
     address = reg['address']
     
     if address is None:
         return
     elif isinstance(address, int):
         reg['parsedAddress']['start'] = address
     elif isinstance(address, str):
         try:
             defaultIncrement = self.getDatawidth()/8
             stridedata = address.split(':')
             stridedata.append(defaultIncrement) # append default increment. This wont be used if the user give the increment
             startAddr = int(float(stridedata[0]))
             if stridedata[1].lower() != 'stride':
                 logging.error('Error during parsing stride address in reg: %s. >stride< keyword exzpected >%s< given', reg['name'], stridedata[1].lower())
                 raise Exception()
             count = util.toInt(stridedata[2])
             increment = util.toInt(stridedata[3])
             reg['parsedAddress']['start'] = startAddr
             reg['parsedAddress']['count'] = count
             reg['parsedAddress']['increment'] = increment
         except:
             logging.error('Unhandled exception at ' + reg['name'])
             raise
     else:
         raise Exception('Unreachable code reached...')
         
     reg['parsedAddress']['value'] = self._getAddressValues(reg)
     return
Exemple #4
0
def zoneEditCmd( clientId, remaining):
    if remaining:
        (token, remaining) = first_token(remaining)
        templateId = toInt(token)

        if templateId:
            zoneTemplate = getZoneTemplate( templateId )

            if zoneTemplate:
                _editZone( clientId, zoneTemplate )
                return
            
        _invalidZoneId( clientId, token )

    # ZoneTemplateSelector
    sendToClient( clientId, "ZoneTemplateSelector not impl" )
Exemple #5
0
def zoneEditCmd(clientId, remaining):
    if remaining:
        (token, remaining) = first_token(remaining)
        templateId = toInt(token)

        if templateId:
            zoneTemplate = getZoneTemplate(templateId)

            if zoneTemplate:
                _editZone(clientId, zoneTemplate)
                return

        _invalidZoneId(clientId, token)

    # ZoneTemplateSelector
    sendToClient(clientId, "ZoneTemplateSelector not impl")
Exemple #6
0
def mobEditCmd(clientId, remaining):
    if remaining:
        (token, remaining) = first_token(remaining)
        templateId = toInt(token)

        if templateId:
            mobTemplate = getMobTemplate(templateId)

            if mobTemplate:
                _editMob(clientId, mobTemplate)
                return

        _invalidMobId(clientId, token)

    # MobTemplateSelector
    sendToClient(clientId, "MobTemplateSelector not impl")
Exemple #7
0
K = 26 + 1

### Initialize the HMM

# startProbs[h]  = p_start(h)
startProbs = [1.0 / K for h in range(K)]

# transProbs[h1][h2] = p_trans(h2 | h1)
# Estimate this from raw text (fully spuervised)
transCounts = [[0 for h2 in range(K)] for h1 in range(K)]
for i in range(1, len(rawText)):
    h1, h2 = rawText[i - 1], rawText[i]
    transCounts[h1][h2] += 1
transProbs = [util.normalize(counts) for counts in transCounts]
print(transProbs[util.toInt('t')][util.toInt('e')])
print(transProbs[util.toInt('t')][util.toInt('g')])

# emissionProbs[h][e] = p_emit(e | h)
emissionProbs = [[1.0 / K for e in range(K)] for h in range(K)]

### Run EM to learn the emission probabilities

for t in range(200):
    # E-step
    # q[i][h] = P(H_i = h | E = observations)
    q = util.forwardBackward(observations, startProbs, transProbs,
                             emissionProbs)

    print(t)
    print(util.toStrSeq([util.argmax(q_i) for q_i in q]))
Exemple #8
0
def readHWH(filename):
    """ Reads Xilix's HWH XML file and converts it to YARD database.
    Returns a list of databases. 
    
    Note, that Xilinx HWH and YARD database is a bit different. HWH contains *instances*
    (of a concrete BlockDesign) YARD contains components (aka. modules). Which means YARD is more
    abstract than HWH.
    """
    accessMap = {'read-write': 'RW', 'read-only': 'RO', 'write-only': 'WO'}
    root = ET.parse(filename).getroot()

    modules = getModulesRoot(root)

    dataBases = []
    globAddrMap = {}

    for mod in modules:
        db = main.DataBase()
        dataBases.append(db)
        db.data['name'] = mod.attrib['INSTANCE']
        db.addInterface()
        peripheralPropery = {}
        for modParam in mod.findall('./PARAMETERS/PARAMETER'):
            peripheralPropery[
                modParam.attrib['NAME']] = modParam.attrib['VALUE']

        # If this peripheral has a master interface (ie. AXI-Master) there is a list of the slaves
        # connected to this master. Let's store the address ranges (the base addresses) of these
        # slave peripherals.
        # If there is no master interface the following for-loop will bypassed (no iteration)
        for memMap in mod.iter('MEMORYMAP'):
            for mr in memMap.iter('MEMRANGE'):
                instance = mr.attrib['INSTANCE']
                memRange = {}
                memRange['baseAddress'] = util.toInt(mr.attrib['BASEVALUE'])
                memRange['highAddress'] = util.toInt(mr.attrib['HIGHVALUE'])
                if instance in globAddrMap.keys():
                    if not isEqMemRange(globAddrMap[instance], memRange):
                        print(
                            'Error: same instance has different address ranges... + '
                            + instance)
                    continue
                for k, v in globAddrMap.items():
                    if isOverlapMemRange(v, memRange):
                        print('Error: address conflict:  ' + instance + '  ' +
                              k)
                globAddrMap[instance] = memRange

        # Usually a peripheral has registers (connected on its AXI-Slave interface) If it has let's
        # go through these registers and map them, with their field.
        for reg in mod.findall(
                './/ADDRESSBLOCKS/ADDRESSBLOCK/REGISTERS/REGISTER'):
            regPropery = {}
            regFields = {}
            for prop in reg.iter('PROPERTY'):
                regPropery[prop.attrib['NAME']] = prop.attrib['VALUE']
            for bf in reg.findall('FIELDS/FIELD'):
                bfPropery = {}
                for prop in reg.iter('PROPERTY'):
                    bfPropery[prop.attrib['NAME']] = prop.attrib['VALUE']
                regFields[bf.attrib['NAME']] = bfPropery

            regData = {}
            regData['name'] = reg.attrib['NAME']
            regData['address'] = util.toInt(regPropery['ADDRESS_OFFSET'])
            regData['width'] = util.toInt(regPropery['SIZE'])
            regData['access'] = accessMap[regPropery['ACCESS']]
            regData['brief'] = util.getFirstSentence(regPropery['DESCRIPTION'])
            regData['description'] = regPropery['DESCRIPTION']
            regData['reset'] = util.toInt(regPropery['RESET_VALUE'])
            regData['fields'] = []

            # Map the bitfields of the registers.
            for bfName, bf in regFields.items():
                fieldData = {}
                fieldData['name'] = bfName
                fieldData['position'] = '{}:{}'.format(bf['BIT_OFFSET'],
                                                       bf['BIT_WIDTH'])
                fieldData['description'] = bf['DESCRIPTION']
                fieldData['access'] = accessMap[bf['ACCESS']]
                regData['fields'].append(fieldData)

            db.addRegister(regData)

    # TODO: this section should be emigrated from here.
    # Prints the base address defines for TCL
    for instance, memrange in globAddrMap.items():
        baseAddr = util.toInt(memrange['baseAddress'])
        definename = instance.upper() + '_BASE_ADDR'
        print('set ' + definename.ljust(32) + ' ' + hex(baseAddr))

    return dataBases
Exemple #9
0
	def file_size_int(self):
		return util.toInt(self.file_size)
Exemple #10
0
	def starting_cluster_int(self):
		return util.toInt(self.starting_cluster)
Exemple #11
0
	def __init__(self, sector):
		self.id = sector[0x03:0x0B]
		self.bytes_per_sector = util.toInt(sector[0x0B:0x0D])
		self.sectors_per_cluster = util.toInt(sector[0x0D:0x0E])
		self.reserved_sectors = util.toInt(sector[0x0E:0x10])
		self.fats = util.toInt(sector[0x10:0x11])
		self.root_entries = util.toInt(sector[0x11:0x13])
		self.small_sectors = util.toInt(sector[0x13:0x15])
		self.media_type = util.toInt(sector[0x15:0x16])
		self.sectors_per_fat = util.toInt(sector[0x16:0x18])
		self.sectors_per_track = util.toInt(sector[0x18:0x1A])
		self.head_number = util.toInt(sector[0x1A:0x1C])
		self.hidden_sectors = util.toInt(sector[0x1C:0x20])
		self.large_sectors = util.toInt(sector[0x20:0x24])
		self.drive_number = util.toInt(sector[0x24:0x25])
		self.flags = util.toInt(sector[0x25:0x26])
		self.signature = sector[0x26:0x27]
		self.volume_id = sector[0x27:0x2B]
		self.volume_label = sector[0x2B:0x36]
		self.system_id = sector[0x36:0x3E]
Exemple #12
0
 def fillAllFields(self, data=None):
     """ fills all fields in raw yard data.
     Some fields are optional during designing a yard register descriptor.
     Some of them can be derived from other fields, others can get its
     default value.
     This method creates a fuly detailed yard structure
     
     Keyword arguments:
     db -- holds the parsed (raw) yard data. Optional, overrides the data
             given to constructor.
     """
     
     if data is not None:
         self.data = data
         
     self.loadDefaults()
     
     for iface in self.data['interfaces']:
         
         for reg in iface['registers']:
             self.dictMrg(reg, self._defaults['registerDefaults'])
             self.parseAddress(reg)
             
             if reg['access'] is not None:
                 if reg['location'] is None:
                     if reg['access'] == 'RW':
                         reg['location'] = 'pif'
                     else:
                         reg['location'] = 'core'
                         
             elif reg['location'] is not None:
                 if reg['access'] is None:
                     if reg['location'] == 'pif':
                         reg['access'] = 'RW'
                     else:
                         reg['access'] = 'RO'
             else:
                 logging.error('Nether location nor access has defined in reg %s', reg['name'])
                 
             if reg['width'] is None:
                 reg['width'] = self.getDatawidth(0)
             if reg['type'] is None:
                 reg['type'] = 'std_logic_vector'
             if reg['hasReadEvent'] is None:
                 reg['hasReadEvent'] = False
             if reg['hasWriteEnable'] is None:
                 if reg['access'] == 'RW' and reg['location'] == 'core':
                     reg['hasWriteEnable'] = True
                 else:
                     reg['hasWriteEnable'] = False
             
             if reg['fields']:
                 for bf in reg['fields']:
                     if bf['access'] == None:
                         bf['access'] = reg['access']
                     try:
                         pos = util.toInt(bf['position'])
                         length = 1
                         start = pos
                     except:
                         pos = str(bf['position']).split(':')
                         posHigh = util.toInt(pos[0])
                         posLow = util.toInt(pos[1])
                         length = posHigh-posLow+1
                         start = posLow
                         
                     bf['_positionLength'] = length
                     bf['_positionStart'] = start
                           
     self.dataDirthy=False