当前位置: 首页>>代码示例>>Python>>正文


Python SR类代码示例

本文整理汇总了Python中SR的典型用法代码示例。如果您正苦于以下问题:Python SR类的具体用法?Python SR怎么用?Python SR使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了SR类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_sampleLabelings

    def test_sampleLabelings(self):
        tree = Tree("(A:1,(B:1,(C:1,(E:1,D:1)Int_1:0.5[&&NHX:ancient=1])Int_2:0.5[&&NHX:ancient=0])Int_3:1)Root;", format=1)
        chrom = {}
        chrom["one"] = ["3","4"]
        species = {}
        species["C"] = chrom
        chrom = {}
        chrom["one"] = ["3","4"]
        species["D"] = chrom
        chrom = {}
        chrom["one"] = []
        species["E"] = chrom
        chrom = {}
        chrom["one"] = []
        species["A"] = chrom
        chrom = {}
        chrom["one"] = []
        species["B"] = chrom

        adj = getAdjacencies.findAdjacencies(species)
        paths = getAdjacencies.findTreePaths(tree)
        internal,adjacenciesAncestral = getAdjacencies.assignAncestralAdjacencies(paths,adj,tree)
        graphs = globalAdjacencyGraph.createGraph(adj,adjacenciesAncestral)
        jointLabels, first = SR.enumJointLabelings(graphs)
        probs={"Int_1":{(6, 7):0.1},"Int_2":{(6, 7):0.1},"Int_3":{(6, 7):0.1},"Root":{(6, 7):0.1}}
        for i in range(0,10):
            validLabels, validAtNode = SR.validLabels(jointLabels,first)
            resolvedCCs = SR.sampleLabelings(tree, graphs, validAtNode, adj,probs, alpha=0)
            reconstructedAdj = SR.reconstructedAdjacencies(resolvedCCs)
            print reconstructedAdj
开发者ID:nluhmann,项目名称:PhySca,代码行数:30,代码来源:test_SR.py

示例2: test_enumJointLabelings

 def test_enumJointLabelings(self):
     #print nx.maximal_matching(self.graph)
     #print nx.max_weight_matching(self.graph)
     joint,first = SR.enumJointLabelings([self.graph])
     TestCase.assertEqual(self,len(joint[self.graph]),15)
     valid, validAtNode = SR.validLabels(joint,first)
     TestCase.assertEqual(self,len(valid[self.graph]),8)
开发者ID:nluhmann,项目名称:PhySca,代码行数:7,代码来源:test_SR.py

示例3: endpointing

 def endpointing(self, current):
     energy = 0.0
     # print current
     # print len(current)
     self.is_speech = False
     for i in range(len(current)):
         energy += pow(current[i], 2)
     energy = 10 * numpy.log(energy)
     # print self.threshold, self.level, self.background
     # print energy
     if self.index == 0:
         self.level = energy
     # threshold equals to max energy of first ten frames divide 4
     if self.index < 10 and self.index >= 0:
         if self.max_energy < energy:
             self.max_energy = energy
         self.background += energy
         if self.index == 9:
             self.background /= 10
             self.threshold = self.max_energy / 4
     if self.index >= 10:
         if energy < self.background:
             self.background = energy
         else:
             self.background += (energy - self.background) * self.adjustment
         self.level = (self.level * self.forget_factor + energy) / (self.forget_factor + 1)
         if self.level < self.background:
             self.level = self.background
         if self.level - self.background > self.threshold:
             self.is_speech = True
         if self.is_speech != self.past_is_speech:
             if self.is_speech:
                 self.begin_index = self.index
                 # print "speech begin at %d\n" % self.begin_index
                 # print 'energy = %d\n' % energy
             else:
                 self.end_index = self.index
                 if self.time_synchronous and self.end_index - self.begin_index > 8:
                     # if self.need_train:
                     #    self.need_train = 0
                     #    self.DTW_obj = SR.training_model(5, self.using_kmeans)[0]
                     SR.test(self.time_synchronous, 1, 5, self.using_kmeans, self.begin_index,
                             self.end_index, self.DTW_obj, self.read_feature_from_file)
                     # print "speech end at %d\n" % self.end_index
                     # print 'energy = %d\n' % energy
         self.past_is_speech = self.is_speech
     self.index += 1
开发者ID:LittleLaa,项目名称:SpeechRecognitionSystem,代码行数:47,代码来源:record.py

示例4: load

    def load(self, sr_uuid):
        driver = SR.driver('iscsi')
        self.iscsi = driver(self.original_srcmd, sr_uuid)

        # User must specify a LUN ID(s) for adding to the VG
        if not self.dconf.has_key('LUNid') or  not self.dconf['LUNid']:
            raise xs_errors.XenError('ConfigLUNIDMissing')
        self.dconf['device'] = os.path.join(self.iscsi.path,"LUN%s" % \
                               self.dconf['LUNid'])

        if not self.iscsi.attached:
            # Must attach SR here in order to load VG
            self.iscsi.attach(sr_uuid)
        super(EXToISCSISR, self).load(sr_uuid)
开发者ID:JohnGarbutt,项目名称:xcp-storage-managers,代码行数:14,代码来源:EXToISCSISR.py

示例5: load

    def load(self, sr_uuid):
        driver = SR.driver('hba')
        self.hbasr = driver(self.original_srcmd, sr_uuid)

        pbd = None
        try:
            pbd = util.find_my_pbd(self.session, self.host_ref, self.sr_ref)
        except:
            pass

        if not self.dconf.has_key('SCSIid') or not self.dconf['SCSIid']:
            print >>sys.stderr,self.hbasr.print_devs()
            raise xs_errors.XenError('ConfigSCSIid')

        self.SCSIid = self.dconf['SCSIid']
        self._pathrefresh(OCFSoHBASR)
        super(OCFSoHBASR, self).load(sr_uuid)
开发者ID:Sisimon,项目名称:sm,代码行数:17,代码来源:OCFSoHBASR.py

示例6: load

    def load(self, sr_uuid):
        driver = SR.driver('hba')
        if 'type' not in self.original_srcmd.params['device_config'] or \
                'type' in self.original_srcmd.params['device_config'] and \
                self.original_srcmd.dconf['type'] == "any":
            self.original_srcmd.dconf['type'] = "fcoe"
        self.hbasr = driver(self.original_srcmd, sr_uuid)
        pbd = None
        try:
            pbd = util.find_my_pbd(self.session, self.host_ref, self.sr_ref)
        except:
            pass

        if not self.dconf.has_key('SCSIid') or not self.dconf['SCSIid']:
            print >>sys.stderr, self.hbasr.print_devs()
            raise xs_errors.XenError('ConfigSCSIid')

        self.SCSIid = self.dconf['SCSIid']
        self._pathrefresh(LVHDoFCoESR)
        LVHDSR.LVHDSR.load(self, sr_uuid)
开发者ID:letsboogey,项目名称:sm,代码行数:20,代码来源:LVHDoFCoESR.py

示例7: load

    def load(self, sr_uuid):
        driver = SR.driver('hba')
        self.hbasr = driver(self.original_srcmd, sr_uuid)

        # If this is a vdi command, don't initialise SR
        if not (util.isVDICommand(self.original_srcmd.cmd)):
            pbd = None
            try:
                pbd = util.find_my_pbd(self.session, self.host_ref, self.sr_ref)
            except:
                pass

            try:
                if not self.dconf.has_key('SCSIid') and self.dconf.has_key('device'):
                    # UPGRADE FROM MIAMI: add SCSIid key to device_config
                    util.SMlog("Performing upgrade from Miami")
                    if not os.path.exists(self.dconf['device']):
                        raise xs_errors.XenError('InvalidDev')
                    SCSIid = scsiutil.getSCSIid(self.dconf['device'])
                    self.dconf['SCSIid'] = SCSIid
                    del self.dconf['device']

                    if pbd <> None:
                        device_config = self.session.xenapi.PBD.get_device_config(pbd)
                        device_config['SCSIid'] = SCSIid
                        device_config['upgraded_from_miami'] = 'true'
                        del device_config['device']
                        self.session.xenapi.PBD.set_device_config(pbd, device_config)
            except:
                pass

            if not self.dconf.has_key('SCSIid') or not self.dconf['SCSIid']:
                print >>sys.stderr,self.hbasr.print_devs()
                raise xs_errors.XenError('ConfigSCSIid')

        self.SCSIid = self.dconf['SCSIid']
        self._pathrefresh(LVHDoHBASR, load = False)
        LVHDSR.LVHDSR.load(self, sr_uuid)
开发者ID:chandrikas,项目名称:sm,代码行数:38,代码来源:LVHDoHBASR.py

示例8: load

    def load(self, sr_uuid):
        if not sr_uuid:
            # This is a probe call, generate a temp sr_uuid
            sr_uuid = util.gen_uuid()

        driver = SR.driver('iscsi')
        self.iscsi = driver(self.original_srcmd, sr_uuid)

        # Be extremely careful not to throw exceptions here since this function
        # is the main one used by all operations including probing and creating
        pbd = None
        try:
            pbd = util.find_my_pbd(self.session, self.host_ref, self.sr_ref)
        except:
            pass
        
        if not self.dconf.has_key('SCSIid') and self.dconf.has_key('LUNid') and pbd <> None:
            # UPGRADE FROM RIO: add SCSIid key to device_config
            util.SMlog("Performing upgrade from Rio")
            scsiid = self._getSCSIid_from_LUN(sr_uuid)
            
            device_config = self.session.xenapi.PBD.get_device_config(pbd)
            device_config['SCSIid'] = scsiid
            device_config['upgraded_from_rio'] = 'true'
            self.session.xenapi.PBD.set_device_config(pbd, device_config)

            self.dconf['SCSIid'] = scsiid            

        # Apart from the upgrade case, user must specify a SCSIid
        if not self.dconf.has_key('SCSIid'):
            self._LUNprint(sr_uuid)
            raise xs_errors.XenError('ConfigSCSIid')

        self.SCSIid = self.dconf['SCSIid']
        self._pathrefresh(LVMoISCSISR)

        super(LVMoISCSISR, self).load(sr_uuid)
开发者ID:JohnGarbutt,项目名称:xcp-storage-managers,代码行数:37,代码来源:LVMoISCSISR.py

示例9: load

    def load(self, sr_uuid):
        driver = SR.driver("hba")
        self.hbasr = driver(self.original_srcmd, sr_uuid)

        pbd = None
        try:
            pbd = util.find_my_pbd(self.session, self.host_ref, self.sr_ref)
        except:
            pass

        try:
            if not self.dconf.has_key("SCSIid") and self.dconf.has_key("device"):
                # UPGRADE FROM MIAMI: add SCSIid key to device_config
                util.SMlog("Performing upgrade from Miami")
                if not os.path.exists(self.dconf["device"]):
                    raise
                SCSIid = scsiutil.getSCSIid(self.dconf["device"])
                self.dconf["SCSIid"] = SCSIid
                del self.dconf["device"]

                if pbd <> None:
                    device_config = self.session.xenapi.PBD.get_device_config(pbd)
                    device_config["SCSIid"] = SCSIid
                    device_config["upgraded_from_miami"] = "true"
                    del device_config["device"]
                    self.session.xenapi.PBD.set_device_config(pbd, device_config)
        except:
            pass

        if not self.dconf.has_key("SCSIid") or not self.dconf["SCSIid"]:
            print >>sys.stderr, self.hbasr.print_devs()
            raise xs_errors.XenError("ConfigSCSIid")

        self.SCSIid = self.dconf["SCSIid"]
        self._pathrefresh(LVMoHBASR)
        super(LVMoHBASR, self).load(sr_uuid)
开发者ID:jonludlam,项目名称:xcp-storage-managers,代码行数:36,代码来源:LVMoHBASR.py

示例10: main

def main():
    command = SRCommand.SRCommand()
    command.parse("")

    if not command.type:
        raise SRCommand.SRInvalidArgumentException( \
                                'missing driver type argument: -t <type>')
    if not command.dconf:
        raise SRCommand.SRInvalidArgumentException('missing dconf string')
    if not command.cmdname:
        raise SRCommand.SRInvalidArgumentException('missing command')
    if not command.sr_uuid:
        raise SRCommand.SRInvalidArgumentException('missing SR UUID')
    if command.cmdtype == 'vdi' and not command.vdi_uuid:
        raise SRCommand.SRInvalidArgumentException('missing VDI UUID')
    if not command.cmd:
        raise SRCommand.SRInvalidArgumentException('unknown command')
    if command.args is None:
        raise SRCommand.SRInvalidArgumentException('wrong number of arguments')

    driver = SR.driver(command.type)
    sr = driver(command.dconf, command.sr_uuid)

    command.run(sr)
开发者ID:JohnGarbutt,项目名称:xcp-storage-managers,代码行数:24,代码来源:sm.py

示例11: attach_from_config

        dict['device_config'] = self.sr.dconf
        if dict['device_config'].has_key('chappassword_secret'):
            s = util.get_secret(self.session, dict['device_config']['chappassword_secret'])
            del dict['device_config']['chappassword_secret']
            dict['device_config']['chappassword'] = s
        dict['sr_uuid'] = sr_uuid
        dict['vdi_uuid'] = vdi_uuid
        dict['command'] = 'vdi_attach_from_config'
        # Return the 'config' encoded within a normal XMLRPC response so that
        # we can use the regular response/error parsing code.
        config = xmlrpclib.dumps(tuple([dict]), "vdi_attach_from_config")
        return xmlrpclib.dumps((config,), "", True)

    def attach_from_config(self, sr_uuid, vdi_uuid):
        util.SMlog("OCFSoISCSIVDI.attach_from_config")
        try:
            self.sr.iscsi.attach(sr_uuid)
            if not self.sr.iscsi._attach_LUN_bySCSIid(self.sr.SCSIid):
                raise xs_errors.XenError('InvalidDev')
            return OCFSSR.OCFSFileVDI.attach(self, sr_uuid, vdi_uuid)
        except:
            util.logException("OCFSoISCSIVDI.attach_from_config")
            raise xs_errors.XenError('SRUnavailable', \
                        opterr='Unable to attach the heartbeat disk')


if __name__ == '__main__':
    SRCommand.run(OCFSoISCSISR, DRIVER_INFO)
else:
    SR.registerSR(OCFSoISCSISR)
开发者ID:BobBall,项目名称:sm,代码行数:30,代码来源:OCFSoISCSISR.py

示例12: attach_from_config

                raise xs_errors.XenError('VDIUnavailable')
        resp = {}
        resp['device_config'] = self.sr.dconf
        resp['sr_uuid'] = sr_uuid
        resp['vdi_uuid'] = vdi_uuid
        resp['sr_sm_config'] = self.sr.sm_config
        resp['command'] = 'vdi_attach_from_config'
        # Return the 'config' encoded within a normal XMLRPC response so that
        # we can use the regular response/error parsing code.
        config = xmlrpclib.dumps(tuple([resp]), "vdi_attach_from_config")
        return xmlrpclib.dumps((config,), "", True)

    def attach_from_config(self, sr_uuid, vdi_uuid):
        """Used for HA State-file only. Will not just attach the VDI but
        also start a tapdisk on the file"""
        util.SMlog("CIFSFileVDI.attach_from_config")
        try:
            if not util.pathexists(self.sr.path):
                self.sr.attach(sr_uuid)
        except:
            util.logException("CIFSFileVDI.attach_from_config")
            raise xs_errors.XenError('SRUnavailable', \
                        opterr='Unable to attach from config')


if __name__ == '__main__':
    SRCommand.run(CIFSSR, DRIVER_INFO)
else:
    SR.registerSR(CIFSSR)
#
开发者ID:davidcunado,项目名称:sm,代码行数:30,代码来源:CIFSSR.py

示例13: long

            stat = os.stat(self.path)
            self.utilisation = long(stat.st_size)
            self.size = long(stat.st_size)
        except:
            pass

    def __init__(self, mysr, uuid, filename):
        self.uuid = uuid
        VDI.VDI.__init__(self, mysr, None)
        self.path = os.path.join(mysr.dconf['location'], filename)
        self.label = filename
        self.location = filename
        self.vdi_type = 'file'
        self.read_only = True
        self.shareable = True
        self.sm_config = {}

    def detach(self, sr_uuid, vdi_uuid):
	pass

    def clone(self, sr_uuid, vdi_uuid):
        return self.get_params()

    def snapshot(self, sr_uuid, vdi_uuid):
        return self.get_params()

if __name__ == '__main__':
    SRCommand.run(SHMSR, DRIVER_INFO)
else:
    SR.registerSR(SHMSR)
开发者ID:rdobson,项目名称:sm,代码行数:30,代码来源:SHMSR.py

示例14: vdi

        try:
            util.pread2(["mkfs.ext3", "-F", self.remotepath])
        except util.CommandException, inst:
            raise xs_errors.XenError('LVMFilesystem', \
                  opterr='mkfs failed error %d' % inst.code)

        #Update serial number string
        scsiutil.add_serial_record(self.session, self.sr_ref, \
                  scsiutil.devlist_to_serialstring(self.root.split(',')))

    def vdi(self, uuid, loadLocked = False):
        if not loadLocked:
            return EXTFileVDI(self, uuid)
        return EXTFileVDI(self, uuid)


class EXTFileVDI(FileSR.FileVDI):
    def attach(self, sr_uuid, vdi_uuid):
        if not hasattr(self,'xenstore_data'):
            self.xenstore_data = {}

        self.xenstore_data["storage-type"]="ext"

        return super(EXTFileVDI, self).attach(sr_uuid, vdi_uuid)


if __name__ == '__main__':
    SRCommand.run(EXTSR, DRIVER_INFO)
else:
    SR.registerSR(EXTSR)
开发者ID:chandrikas,项目名称:sm,代码行数:30,代码来源:EXTSR.py

示例15: attach_from_config

        dict['device_config'] = self.sr.dconf
        dict['sr_uuid'] = sr_uuid
        dict['vdi_uuid'] = vdi_uuid
        dict['allocation'] =  self.sr.sm_config['allocation']
        dict['command'] = 'vdi_attach_from_config'
        # Return the 'config' encoded within a normal XMLRPC response so that
        # we can use the regular response/error parsing code.
        config = xmlrpclib.dumps(tuple([dict]), "vdi_attach_from_config")
        return xmlrpclib.dumps((config,), "", True)

    def attach_from_config(self, sr_uuid, vdi_uuid):
        util.SMlog("LVHDoHBAVDI.attach_from_config")
        self.sr.hbasr.attach(sr_uuid)
        if self.sr.mpath == "true":
            self.sr.mpathmodule.refresh(self.sr.SCSIid,0)
        try:
            return self.attach(sr_uuid, vdi_uuid)
        except:
            util.logException("LVHDoHBAVDI.attach_from_config")
            raise xs_errors.XenError('SRUnavailable', \
                        opterr='Unable to attach the heartbeat disk')

def match_scsidev(s):
    regex = re.compile("^/dev/disk/by-id|^/dev/mapper")
    return regex.search(s, 0)
    
if __name__ == '__main__':
    SRCommand.run(LVHDoHBASR, DRIVER_INFO)
else:
    SR.registerSR(LVHDoHBASR)
开发者ID:letsboogey,项目名称:sm,代码行数:30,代码来源:LVHDoHBASR.py


注:本文中的SR类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。