Exemplo n.º 1
0
def generateConfigFile(app_store, app_ver, app_description):
    xml = ElementTree()
    update = Element('update')
    xml._setroot(update)
    SubElement(update,'version').text = app_ver
    SubElement(update,'name').text = 'cleanspace'
    app_name = 'cleanspace_' + app_ver + '.apk'
    url = 'http://thelinkit.com/photoclean/update/android/%s/%s'% (app_store,app_name)
    url.join('</url>')
    testurl = 'http://thelinkit.com/photoclean/update/android/%s/test/%s'% (app_store,app_name)
    testurl.join('</testurl>')
    
    SubElement(update,'url').text = url 
    SubElement(update,'testurl').text = testurl
    SubElement(update,'description').text = app_description
    
    path = "./bin/" + app_store;
    if not os.path.isdir(path):
        os.mkdir(path)
        
    if not os.path.isdir(path +'/test'):
        os.mkdir(path + '/test')
    testpath = path + '/test/update.xml'
    
    path += '/update.xml'
    xml.write(path,'utf-8');

    xml.write(testpath,'utf-8');
Exemplo n.º 2
0
 def dump(self, file="XXX"):
     if file == "XXX":
         ET.dump(self.rootElement)
     else:
         tree = ElementTree()
         tree._setroot(self.rootElement)
         tree.write(file, "UTF-8")
Exemplo n.º 3
0
    def write_xml(objs,PicName,Image,save_path):

        imagexml = ElementTree()
        annotation = Element("annotation")  # xml title
        SubElement(annotation, "folder").text = "path"
        SubElement(annotation, "filename").text = PicName
        imagexml._setroot(annotation)
        sp = Image.shape
        width, height, pic_depth = sp[1], sp[0], sp[2]
        item1 = Element("size")
        SubElement(item1, "width").text = str(width)
        SubElement(item1, "height").text = str(height)
        SubElement(item1, "depth").text = str(pic_depth)
        annotation.append(item1)

        for obj in objs:
            item2 = Element("object")
            SubElement(item2, "name").text = "11"
            SubElement(item2, "difficult").text = "0"
            annotation.append(item2)
            item3 = Element("bndbox")
            SubElement(item3, "xmin").text = str(int(obj[0]))  # xmin
            SubElement(item3, "ymin").text = str(int(obj[1]))  # ymin
            SubElement(item3, "xmax").text = str(int(obj[2]))  # xmax
            SubElement(item3, "ymax").text = str(int(obj[3]))  # ymax
            item2.append(item3)

        imagexml.write(save_path, "utf-8")
Exemplo n.º 4
0
 def createReport(self):
     if self.__addr == "":
         return False
     tree = ElementTree()
     root = ET.Element("testsuites")
     tree._setroot(root)
     return self.__seveJUNIT(tree)
Exemplo n.º 5
0
 def dump(self, filename):
     from xml.etree.ElementTree import ElementTree
     pl = self.createPayload()
     #ET.dump(pl)
     tree = ElementTree()
     tree._setroot(pl)
     tree.write(filename, "UTF-8")
def writePluginConfigs(channel, targetFilePath):
    targetTree = None
    targetRoot = None
    pluginNodes = None

    targetTree = ElementTree()
    targetRoot = Element('plugins')
    targetTree._setroot(targetRoot)

    if 'plugins' in channel:
        for plugin in channel['plugins']:
            typeTag = 'plugin'
            typeName = plugin['name']
            typeVal = plugin['type']
            pluginNode = SubElement(targetRoot, typeTag)
            pluginNode.set('name', typeName)
            pluginNode.set('type', typeVal)

    # write third plugin info

    thirdPlugins = channel.get('third-plugins')
    if thirdPlugins != None and len(thirdPlugins) > 0:
        for cPlugin in thirdPlugins:

            if 'plugins' in cPlugin and cPlugin['plugins'] != None and len(cPlugin['plugins']) > 0:
                for plugin in cPlugin['plugins']:
                    typeTag = 'plugin'
                    typeName = plugin['name']
                    typeVal = plugin['type']
                    pluginNode = SubElement(targetRoot, typeTag)
                    pluginNode.set('name', typeName)
                    pluginNode.set('type', typeVal)


    targetTree.write(targetFilePath, 'UTF-8')
Exemplo n.º 7
0
    def updateTopFile(directory, filename, user, score, top_n = 5):
        if not Application.existsFile(directory, filename):
            Application.createTopFile(directory, filename, top_n)

        pla = Application.getTopPlayers(directory, filename)
        t = [f for f in pla if f[0]==user and int(f[1])>score]
        if len(t) == 0:
            return False
        treeP = ElementTree()
        treeP.parse(directory+filename+".xml")
        root = treeP.getroot()
        new_root = Element("top_scores")
        ranks = root.findall("rank")
        top = min([top_n, len(ranks)])
        score_i = int(ranks[0].text)
        score_f = int(ranks[top-1].text)
        ins = False
        for i in range(top):
            if score <= int(ranks[i].text) or (ranks[i].attrib["user"] == "__EMPTY__"):
                tmp = Element("rank")
                tmp.set("user", user)
                tmp.text = str(score)
                new_root.append(tmp)
                ins = True
                break
            else:
                new_root.append(ranks[i])
        for j in range(i,top - 1):
            new_root.append(ranks[j])

        treeP2 = ElementTree()
        treeP2._setroot(new_root)

        treeP2.write(directory+filename+".xml")
        return ins
Exemplo n.º 8
0
    def createProfile(username, directory='profiles/'):
        if username == "" or username == None:
            return False
        treeP = ElementTree()
        root = Element("root")
        
        name = Element("name")
        name.text = username
        root.append(name)

        levels = Application.getDirectories("levels")
        for level_name in levels:
            nivel = Element("level")
            nivel.set("id", level_name)
            puzzles = Application.getFiles("levels/"+level_name)
            for puzzle in puzzles:
                if "_top" in puzzle:
                    continue
                pz = Element("puzzle")
                pz.set("id", puzzle)
                pz.text = "0"
                nivel.append(pz)
            root.append(nivel)
        treeP._setroot(root)
        treeP.write(directory+username+".xml")

        return True
Exemplo n.º 9
0
class XmlWriter():
    def __init__(self):
        self.tree = ElementTree()
        self.root = Element('poem')
        self.tree._setroot(self.root)
        print "##################"
        print locals()
        print "##################"
        
    def addItem(self,map):
        if map != None:
            item = Element("item", {'id' : map['id'], 'name' : map['name'], 'poet':map['poet'], 'type':map['type']})
            SubElement(item,'value').text = map['value']
            SubElement(item,'remark').text = map['remark']
            SubElement(item,'translation').text = map['translation']
            SubElement(item,'analysis').text = map['analysis']
            self.root.append(item)
            
    def write(self,path):
        if path != None:
            dump(self.indent(self.root))
            self.tree.write(path,'utf-8')

    def indent(self,elem, level=0):
        i = "\n" + level*"  "
        if len(elem):
            if not elem.text or not elem.text.strip():
                elem.text = i + "  "
            for e in elem:
                self.indent(e, level+1)
            if not e.tail or not e.tail.strip():
                e.tail = i
        if level and (not elem.tail or not elem.tail.strip()):
            elem.tail = i
        return elem
def genSummaryXml():
    try:
        print "Generate summary.xml ---------------->Start"
        tree = ElementTree()
        root = Element("result_summary", {"plan_name":""})
        tree._setroot(root)
        env = SE(root,"environment",{"build_id":"","cts_version":"","device_id":"","device_model":"","device_name":"","host":"","resolution":"","screen_size":"","manufacturer":""})
        summary = SE(root, "summary")
        startTime = SE(summary, "start_at")
        endTime = SE(summary, "end_at")
        startTime.text = Start
        endTime.text = End
        suite = SE(root, "suite", {"name":"wrt-manifest-android-tests"})
        total_case = SE(suite, "total_case")
        total_case.text = str(totalNum)
        pass_case = SE(suite, "pass_case")
        pass_case.text = str(passNum)
        pass_rate = SE(suite, "pass_rate")
        pass_rate.text = str(float(passNum) / totalNum * 100)
        fail_case = SE(suite, "fail_case")
        fail_case.text = str(failNum)
        fail_rate = SE(suite, "fail_rate")
        fail_rate.text = str(float(failNum) / totalNum * 100)
        SE(suite, "block_case")
        SE(suite, "block_rate")
        SE(suite, "na_case")
        SE(suite, "na_rate")
        tree.write(ConstPath + "/report/summary.xml")
        updateXmlTitle(ConstPath + "/report/summary.xml",'<?xml version="1.0" encoding="UTF-8"?>\n<?xml-stylesheet type="text/xsl" href="./style/summary.xsl"?>\n')
        print "Generate summary.xml ---------------->O.K"
    except Exception,e:
        print Exception,":",e
        print "Generate summary.xml ---------------->Error"
        sys.exit(1)
Exemplo n.º 11
0
def writePluginConfigs(channel, targetFilePath):
    targetTree = None
    targetRoot = None
    pluginNodes = None

    targetTree = ElementTree()
    targetRoot = Element('plugins')
    targetTree._setroot(targetRoot)

    if 'plugins' in channel:
        for plugin in channel['plugins']:
            typeTag = 'plugin'
            typeName = plugin['name']
            typeVal = plugin['type']
            pluginNode = SubElement(targetRoot, typeTag)
            pluginNode.set('name', typeName)
            pluginNode.set('type', typeVal)

    # write third plugin info

    thirdPlugins = channel.get('third-plugins')
    if thirdPlugins != None and len(thirdPlugins) > 0:
        for cPlugin in thirdPlugins:

            if 'plugins' in cPlugin and cPlugin['plugins'] != None and len(
                    cPlugin['plugins']) > 0:
                for plugin in cPlugin['plugins']:
                    typeTag = 'plugin'
                    typeName = plugin['name']
                    typeVal = plugin['type']
                    pluginNode = SubElement(targetRoot, typeTag)
                    pluginNode.set('name', typeName)
                    pluginNode.set('type', typeVal)

    targetTree.write(targetFilePath, 'UTF-8')
Exemplo n.º 12
0
def create_xml_head(_info, _folder, _annotation):
    root = ElementTree()
    anno = Element("annotation")
    root._setroot(anno)

    folder = Element("folder", {})
    folder.text = _folder
    anno.append(folder)

    filename = Element("filename", {})
    filename.text = _info['file_name']
    anno.append(filename)

    source = Element("source", {})
    anno.append(source)
    SubElement(source, "database").text = " The BDCI2017-gsum Database"
    SubElement(source, "annotation").text = _annotation
    SubElement(source, "image").text = "flickr"
    SubElement(source, "date_updated").text = str(
        time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))

    size = Element("size", {})
    anno.append(size)
    SubElement(size, "width").text = str(_info['width'])
    SubElement(size, "height").text = str(_info['height'])
    SubElement(size, "depth").text = '3'

    segmented = Element("segmented", {})
    segmented.text = '0'
    anno.append(segmented)

    # indent(anno)
    return anno, root
Exemplo n.º 13
0
class HuabanPipeline(object):
    def __init__(self):
        self.doc = ElementTree()
        self.allpic = Element("all_pic")
        self.allpic.tail = '\n'
        self.doc._setroot(self.allpic)

    def process_item(self, item, spider):
        if spider.name == 'huabanSpider':
            url = [
                item['pin_id'], "http://img.hb.aicdn.com/" + item['key'],
                item['pic_type'], item['folder']
            ]
            pic = Element('pic')
            pic.tail = '\n'
            self.allpic.append(pic)
            SubElement(pic, 'pin_id').text = url[0]
            SubElement(pic, 'pic_url').text = url[1]
            SubElement(pic, 'pic_type').text = url[2]
            SubElement(pic, 'folder').text = url[3]
            return item

    def close_spider(self, spider):
        if spider.name == 'huabanSpider':
            self.f = open('pic_urls', 'w')
            self.doc.write(self.f)
            self.f.close()
def writeChannelInfoIntoDevelopInfo(decompileDir, channel, privateKey):
    """
        the infomation about channel would configure here
    """
    assetsDir = decompileDir + '/assets'
    developerFile = assetsDir + '/developerInfo.xml'
    if not os.path.exists(assetsDir):
        os.makedirs(assetsDir)
    targetTree = None
    targetRoot = None
    if not os.path.exists(developerFile):
        targetTree = ElementTree()
        targetRoot = Element('developer')
        targetTree._setroot(targetRoot)
    else:
        targetTree = ET.parse(developerFile)
        targetRoot = targetTree.getroot()
    infoNode = targetRoot.find('channel')
    if infoNode is None:
        infoNode = SubElement(targetRoot, 'channel')
    if infoNode.get('idChannel') is None:
        infoNode.set('idChannel', str(channel['channelNum']))
        infoNode.set('uApiKey', channel['uapiKey'])
        infoNode.set('uApiSecret', channel['uapiSecret'])
        infoNode.set('oauthLoginServer', channel['oauthLoginServer'])
        if channel['extChannel'] is not None:
            infoNode.set('extChannel', channel['extChannel'])
        infoNode.set('privateKey', privateKey)
    targetTree.write(developerFile, 'UTF-8')
    file_operate.printf(
        "Save channel's information to developerInfo.xml success")
Exemplo n.º 15
0
def genSummaryXml():
    try:
        tree = ElementTree()
        root = Element("result_summary", {"plan_name":""})
        tree._setroot(root)
        env = SE(root,"environment",{"build_id":"","cts_version":"","device_id":"","device_model":"","device_name":"","host":"","resolution":"","screen_size":"","manufacturer":""})
        summary = SE(root, "summary")
        startTime = SE(summary, "start_at")
        endTime = SE(summary, "end_at")
        startTime.text = Start
        endTime.text = End
        suite = SE(root, "suite", {"name":"wrt-packertool-android-tests"})
        total_case = SE(suite, "total_case")
        total_case.text = str(totalNum)
        pass_case = SE(suite, "pass_case")
        pass_case.text = str(passNum)
        pass_rate = SE(suite, "pass_rate")
        pass_rate.text = str(float(passNum) / totalNum * 100)
        fail_case = SE(suite, "fail_case")
        fail_case.text = str(failNum)
        fail_rate = SE(suite, "fail_rate")
        fail_rate.text = str(float(failNum) / totalNum * 100)
        SE(suite, "block_case")
        SE(suite, "block_rate")
        SE(suite, "na_case")
        SE(suite, "na_rate")
        tree.write(ConstPath + "/report/summary.xml")
        updateXmlTitle(ConstPath + "/report/summary.xml",'<?xml version="1.0" encoding="UTF-8"?>\n<?xml-stylesheet type="text/xsl" href="./style/summary.xsl"?>\n')
        print "Generate summary.xml file ------------------------->O.K"
    except Exception,e:
        print Exception,"Generate summary.xml error:",e
Exemplo n.º 16
0
    def getunique(self, filename):
        """
        Build a unique path / object name scheme.

        The path is build from **initialpath** given during class instantiation
        plus byte 4 and 3 of the UUID in hexadecimal.

        If **annotation** is True during class instantiation, there will be
        a third element in the returned tuple, containing an XML structure that
        can be used as custom metadata annotation for the object.

        :param filename:    the filename to be transformed
        :return:            a tuple consisting of path, unique object name and
                            -eventually- an annotation string.
        :raises:            hcpsdk.pathbuilder.pathbuilderError

        **Example:**

        ::

            >>> from hcpsdk.pathbuilder import PathBuilder
            >>> p = PathBuilder(initialpath='/rest/mypath', annotation=True)
            >>> o = p.getunique('testfile.txt')
            >>> o
            ('/rest/mypath/b4/ec', '8ac8ecb4-9f1e-11e4-a524-98fe94437d8c',
             '<?xml version=\'1.0\' encoding=\'utf-8\'?>
                <hcpsdk_fileobject
                    filename="testfile.txt"
                    path="/rest/mypath/b4/ec"
                    uuid="8ac8ecb4-9f1e-11e4-a524-98fe94437d8c"
             />')
            >>>
        """
        try:
            uuid = str(uuid1())
            path = join(self.leadingpath, uuid[6:8], uuid[4:6])
            if self.annotation:
                xml = ElementTree()
                e = Element('hcpsdk_fileobject', {
                    'filename': filename,
                    'path': path,
                    'uuid': uuid
                })
                # noinspection PyProtectedMember
                xml._setroot(e)
                with BytesIO() as xmlstring:
                    xml.write(xmlstring,
                              encoding="utf-8",
                              method="xml",
                              xml_declaration=True)
                    annotation = xmlstring.getvalue().decode()
        except Exception as e:
            raise PathBuilderError(str(e))

        if self.annotation:
            # noinspection PyUnboundLocalVariable
            return path, uuid, annotation
        else:
            return path, uuid
Exemplo n.º 17
0
def genResultXml(resultList, device, Start, End):
    try:
        print "Generate test.result.xml ---------------->Start"
        tree = ElementTree()
        root = Element("test_definition")
        tree._setroot(root)

        env = Element("environment", {"build_id":"","device_id":"","device_name":"","host":"",\
        "lite_version":"","manufacturer":"","resolution":"","screen_size":""})
        root.append(env)

        #summary element
        summary = Element("summary", {"test_plan_name":""})
        root.append(summary)
        tStart = SE(summary, "start_at")
        tEnd = SE(summary, "end_at")
        tStart.text = Start
        tEnd.text = End

        #suite element
        suite = SE(root, "suite", {"category":"Runtime_Core","launcher":"xwalk",\
        "name":"wrt-manifest-android-tests"})
        setPositive = SE(suite, "set", {"name":"positive","set_debug_msg":""})
        setNegitive = SE(suite, "set", {"name":"negative","set_debug_msg":""})

        #testcase element
        for case in resultList:
            setElement = setPositive
            if case["set"] == "negative":
                setElement = setNegitive
            pur = "Check if packaged web application can be installed/launched/uninstalled successfully"
            testcase = SE(setElement, "testcase", {"component":"Runtime Core",\
            "execution_type":"auto","id":case["id"],"purpose":pur,"result":case["result"]})
            desc = SE(testcase, "description")
            entry = Element("test_script_entry")
            entry.text = case["entry"].decode("utf-8")
            desc.append(entry)
            resultInfo = SE(testcase, "result_info")
            actualResult = SE(resultInfo, "actual_result")
            actualResult.text = case["result"]
            caseStart = SE(resultInfo, "start")
            caseStart.text = case["start"]
            caseEnd = SE(resultInfo, "end")
            caseEnd.text = case["end"]
            stdOut = SE(resultInfo, "stdout")
            if case["result"] == "FAIL":
                stdOut.text = "[message]\n" + case["message"].decode("utf-8")
            else:
                stdOut.text = "[message]"
            SE(resultInfo, "stderr")

        tree.write(ConstPath + "/device_" + device + "/report/wrt-manifest-android-tests.xml")
        updateXmlTitle(ConstPath + "/device_" + device + "/report/wrt-manifest-android-tests.xml",'<?xml version="1.0" encoding="UTF-8"?>\n<?xml-stylesheet type="text/xsl" href="./style/testresult.xsl"?>\n<?xml-stylesheet type="text/xsl" href="testresult.xsl"?>\n')

        print "Generate test.result.xml ---------------->O.K"
    except Exception,e:
        print Exception,":",e
        print "Generate test.result.xml ---------------->Error"
        sys.exit(1)
Exemplo n.º 18
0
    def asXml(self, fileName, datesim):
        doc = ElementTree()
        root = Element(tag=self.type_info, attrib={'datesim': datesim})

        for i in self._children:
            i._recurseXml(root, datesim)

        doc._setroot(root)
        return doc.write(fileName, encoding="utf-8", method="xml")
Exemplo n.º 19
0
    def asXml(self, fileName):
        doc = ElementTree()
        root = Element(tag=self.typeInfo, attrib={"datesim": CONF.get("simulation", "datesim")})

        for i in self._children:
            i._recurseXml(root)

        doc._setroot(root)
        return doc.write(fileName, encoding="utf-8", method="xml")
Exemplo n.º 20
0
def writeSupportInfo(workDir):
    PluginFile = workDir + '/supportPlugin.xml'
    targetTree = None
    targetRoot = None
    pluginLsNode = None
    if not os.path.exists(PluginFile):
        targetTree = ElementTree()
        targetRoot = Element('support')
        targetTree._setroot(targetRoot)
        targetTree.write(PluginFile, 'UTF-8')
Exemplo n.º 21
0
    def asXml(self, fileName):
        doc = ElementTree()
        root = Element(tag=self.typeInfo,
                       attrib={'datesim': CONF.get('simulation', 'datesim')})

        for i in self._children:
            i._recurseXml(root)

        doc._setroot(root)
        return doc.write(fileName, encoding="utf-8", method="xml")
Exemplo n.º 22
0
    def asXml(self, fileName, datesim):
        doc = ElementTree()
        root = Element(tag = self.type_info,
                       attrib={'datesim': datesim})

        for i in self._children:
            i._recurseXml(root, datesim)

        doc._setroot(root)
        return doc.write(fileName, encoding = "utf-8", method = "xml")
def genResultXml():
    try:
        print "Generate test.result.xml ---------------->Start"
        tree = ElementTree()
        root = Element("test_definition")
        tree._setroot(root)

        env = Element("environment", {"build_id":"","device_id":"","device_name":"","host":"",\
        "lite_version":"","manufacturer":"","resolution":"","screen_size":""})
        root.append(env)

        #summary element
        summary = Element("summary", {"test_plan_name":""})
        root.append(summary)
        tStart = SE(summary, "start_at")
        tEnd = SE(summary, "end_at")
        tStart.text = Start
        tEnd.text = End

        #suite element
        suite = SE(root, "suite", {"category":"Runtime_Core","launcher":"xwalk",\
        "name":"wrt-manifest-android-tests"})
        setPositive = SE(suite, "set", {"name":"positive","set_debug_msg":""})
        setNegitive = SE(suite, "set", {"name":"negitive","set_debug_msg":""})

        #testcase element
        for case in ResultList:
            setElement = setPositive
            if case["set"] == "negative":
                setElement = setNegitive
            pur = "Check if packaged web application can be installed/launched/uninstalled successfully"
            testcase = SE(setElement, "testcase", {"component":"Runtime Core",\
            "execution_type":"auto","id":case["id"],"purpose":pur,"result":case["result"]})
            desc = SE(testcase, "description")
            entry = Element("test_script_entry")
            entry.text = case["entry"].decode("utf-8")
            desc.append(entry)
            resultInfo = SE(testcase, "result_info")
            actualResult = SE(resultInfo, "actual_result")
            actualResult.text = case["result"]
            caseStart = SE(resultInfo, "start")
            caseStart.text = case["start"]
            caseEnd = SE(resultInfo, "end")
            caseEnd.text = case["end"]
            SE(resultInfo, "stdout")
            SE(resultInfo, "stderr")

        tree.write(ConstPath + "/report/wrt-manifest-android-tests.xml")
        updateXmlTitle(ConstPath + "/report/wrt-manifest-android-tests.xml",'<?xml version="1.0" encoding="UTF-8"?>\n<?xml-stylesheet type="text/xsl" href="./style/testresult.xsl"?>\n<?xml-stylesheet type="text/xsl" href="testresult.xsl"?>\n')

        print "Generate test.result.xml ---------------->O.K"
    except Exception,e:
        print Exception,":",e
        print "Generate test.result.xml ---------------->Error"
        sys.exit(1)
Exemplo n.º 24
0
def create_xml(name, id, key):
    ## Writing the content to xml document
    book = ElementTree()

    configuration = Element('configuration')
    book._setroot(configuration)

    startup = Element('startup')
    SubElement(startup, 'supportedRuntime', {
        'version': 'v4.0',
        'sku': '.NETFramework,Version=v4.0'
    })

    configuration.append(startup)

    appSettings = Element('appSettings')
    configuration.append(appSettings)

    SubElement(appSettings, 'add', {'key': 'autostart', 'value': '0'})
    SubElement(appSettings, 'add', {'key': 'parkname', 'value': name})
    SubElement(appSettings, 'add', {'key': 'parkid', 'value': id})
    SubElement(appSettings, 'add', {'key': 'parkkey', 'value': key})
    SubElement(appSettings, 'add', {'key': 'parkedition', 'value': '0'})
    SubElement(appSettings, 'add', {
        'key': 'dbserver',
        'value': 'db server ip'
    })
    SubElement(appSettings, 'add', {'key': 'database', 'value': 'db name'})
    SubElement(appSettings, 'add', {'key': 'username', 'value': 'sa'})
    SubElement(appSettings, 'add', {'key': 'password', 'value': '26997211'})
    #SubElement(appSettings, 'add', {'key': 'cloudip','value': '120.25.60.20'})
    SubElement(appSettings, 'add', {'key': 'cloudip', 'value': SERVER_IP})
    SubElement(appSettings, 'add', {'key': 'port', 'value': '2003'})
    SubElement(appSettings, 'add', {'key': 'Intervaltime', 'value': '10'})

    #print(tostring(indent(configuration)).decode('utf-8'))

    xml_declaration = '<?xml version="1.0" encoding="UTF-8"?>\n'
    indented = indent(configuration)
    #print(tostring(configuration))
    #print(name)
    xml_body = tostring(indent(configuration)).decode('utf-8')
    xml = xml_declaration + xml_body

    xml_file = '客户端上传工具.exe.Config'  # + name + '.xml'
    #print(xml)
    book.write(xml_file, 'utf-8')

    with open(xml_file, 'r') as original:
        data = original.read()
        original.close()

    with open(xml_file, 'w') as modified:
        modified.write(xml_declaration + data)
        modified.close()
Exemplo n.º 25
0
    def getunique(self, filename):
        """
        Build a unique path / object name scheme.

        The path is build from **initialpath** given during class instantiation
        plus byte 4 and 3 of the UUID in hexadecimal.

        If **annotation** is True during class instantiation, there will be
        a third element in the returned tuple, containing an XML structure that
        can be used as custom metadata annotation for the object.

        :param filename:    the filename to be transformed
        :return:            a tuple consisting of path, unique object name and
                            -eventually- an annotation string.
        :raises:            hcpsdk.pathbuilder.pathbuilderError

        **Example:**

        ::

            >>> from hcpsdk.pathbuilder import PathBuilder
            >>> p = PathBuilder(initialpath='/rest/mypath', annotation=True)
            >>> o = p.getunique('testfile.txt')
            >>> o
            ('/rest/mypath/b4/ec', '8ac8ecb4-9f1e-11e4-a524-98fe94437d8c',
             '<?xml version=\'1.0\' encoding=\'utf-8\'?>
                <hcpsdk_fileobject
                    filename="testfile.txt"
                    path="/rest/mypath/b4/ec"
                    uuid="8ac8ecb4-9f1e-11e4-a524-98fe94437d8c"
             />')
            >>>
        """
        try:
            uuid = str(uuid1())
            path = join(self.leadingpath, uuid[6:8], uuid[4:6])
            if self.annotation:
                xml = ElementTree()
                e = Element('hcpsdk_fileobject', {'filename': filename,
                                                  'path': path,
                                                  'uuid': uuid})
                # noinspection PyProtectedMember
                xml._setroot(e)
                with BytesIO() as xmlstring:
                    xml.write(xmlstring, encoding="utf-8", method="xml", xml_declaration=True)
                    annotation = xmlstring.getvalue().decode()
        except Exception as e:
            raise PathBuilderError(str(e))

        if self.annotation:
            # noinspection PyUnboundLocalVariable
            return path, uuid, annotation
        else:
            return path, uuid
Exemplo n.º 26
0
class xbmcScraper(scraper):
    """
    the xbmcScraper class provides a generic ground foundation, which is
    required for all XBMC scrapers.
    """
    
    xml = ElementTree()          # holds the scraper regex xml tree
    addonxml = ElementTree()     # xml tree of addon.xml
    settingsxml= ElementTree()   # xml tree of resources/settings.xml
    path = None                  # filesystem path to scraper
    basepath = None              # the path which contains the scraper
    requires = []                # an array of dicts with the keys: scrpaer, version
    deps = []                    # contains the dependencies of the scraper as Scraper object
    
    def __init__(self, scraperPath = None):
        self.xml = ElementTree()
        self.addonxml = ElementTree()
        self.settingsxml= ElementTree()
        self.requires = []
        self.deps = []
        if scraperPath:
            scraperPath = os.path.normpath(scraperPath)
            self.addonxml.parse( os.path.join(scraperPath, "addon.xml") )
            xmlpath = self.addonxml.find("extension").attrib["library"]
            self.xml.parse( os.path.join(scraperPath, xmlpath) )
            if os.path.exists(os.path.join(scraperPath, "resources/settings.xml")):
                self.settingsxml.parse( os.path.join(scraperPath, "resources/settings.xml") )
            requires = self.addonxml.find("requires")
            if requires:
                for require in requires.findall("import"):
                    self.requires.append({})
                    self.requires[-1]["scraper"] = require.attrib["addon"]
                    self.requires[-1]["version"] = require.attrib["version"]
            else:
                logging.warning("could not find <requires> in %s/addon.xml" % scraperPath)
            self.basepath = os.path.split(scraperPath)[0]
        self.path = scraperPath
        if hasattr(self, "__stage2__"):
            self.__stage2__()
        
    def __stage2__(self):
        """ a customizable appendix to __init__ """
        
    def __resolve_deps__(self):
        """ resolve import dependencies of the scraper """
        for require in self.requires:
            if not require["scraper"] in ["xbmc.metadata",]:    # some deps are for xbmc only and are not scraper relevant
                logging.info("importing scraper %s as dependency." % require["scraper"])
                scraper = getScraper(os.path.join(self.basepath, require["scraper"]))
                scraper.__resolve_deps__()
                self.xml._setroot( mergeEtree( self.xml.getroot(), scraper.xml.getroot() ) )
    
    def search(self, name):
        """ dummy """
Exemplo n.º 27
0
 def appendReport(self):
     if self.__addr == "":
         return False
     tree = ElementTree()
     try:
         tree.parse(self.__addr)
     except IOError:
         tree = ElementTree()
         root = ET.Element("testsuites")
         tree._setroot(root)
     return self.__seveJUNIT(tree)
Exemplo n.º 28
0
def writeSelectedProject(info):
    book = ElementTree()
    parent = Element("ProjectInfo")
    book._setroot(parent)
    item = Element("project")
    parent.append(item)
    SubElement(item, "id").text = info["id"]
    SubElement(item, "name").text = info["name"]
    dump(indent(parent))
    if not os.path.exists(confPath.localXml):
        os.makedirs(confPath.localXml)
    book.write(confPath.localXml + "selectedProject.xml", "utf-8")
Exemplo n.º 29
0
def print_out_paper_info(paper_info_list, out_file='book.xml'):
    ele_tree = ElementTree()
    root_paper_tree = Element('PAPERS')
    ele_tree._setroot(root_paper_tree)
    for paper_info in paper_info_list:
        temp_paper_ele = Element('PAPER')
        for key, value in paper_info.items():
            if key == 'author_list': value = '_'.join(value)
            SubElement(temp_paper_ele, key).text = value
        root_paper_tree.append(temp_paper_ele)
    dump(indent(root_paper_tree))
    ele_tree.write(out_file, "utf-8")
Exemplo n.º 30
0
def genResultXml():
    try:
        tree = ElementTree()
        root = Element("test_definition")
        tree._setroot(root)

        env = Element("environment", {"build_id":"","device_id":"","device_name":"","host":"",\
        "lite_version":"","manufacturer":"","resolution":"","screen_size":""})
        root.append(env)

        #summary element
        summary = Element("summary", {"test_plan_name":""})
        root.append(summary)
        tStart = SE(summary, "start_at")
        tEnd = SE(summary, "end_at")
        tStart.text = Start
        tEnd.text = End

        #suite element
        suite = SE(root, "suite", {"category":"Crosswalk_Packer_Tool","launcher":"xwalk",\
        "name":"wrt-packertool-android-tests"})
        setPositive = SE(suite, "set", {"name":"positive","set_debug_msg":""})
        setNegitive = SE(suite, "set", {"name":"negitive","set_debug_msg":""})

        #testcase element
        for case in ResultList:
            setElement = setPositive
            if case["set"] == "negative":
                setElement = setNegitive
            pur = "Check if packer tool work properly"
            testcase = SE(setElement, "testcase", {"component":"Crosswalk Packer Tool",\
            "execution_type":"auto","id":case["id"],"purpose":pur,"result":case["result"]},)
            desc = SE(testcase, "description")
            entry = Element("test_script_entry")
            entry.text = "pack command: " + case["entry"].decode("utf-8")
            desc.append(entry)
            resultInfo = SE(testcase, "result_info")
            actualResult = SE(resultInfo, "actual_result")
            actualResult.text = case["result"]
            caseStart = SE(resultInfo, "start")
            caseStart.text = case["start"]
            caseEnd = SE(resultInfo, "end")
            caseEnd.text = case["end"]
            SE(resultInfo, "stdout")
            SE(resultInfo, "stderr")

        tree.write(ConstPath + "/report/wrt-packertool-android-tests.xml")
        updateXmlTitle(ConstPath + "/report/wrt-packertool-android-tests.xml",'<?xml version="1.0" encoding="UTF-8"?>\n<?xml-stylesheet type="text/xsl" href="./style/testresult.xsl"?>\n<?xml-stylesheet type="text/xsl" href="testresult.xsl"?>\n')

        print "Generate test.result.xml file ------------------------->O.K"
    except Exception,e:
        print Exception,"Generate test.result.xml error:",e
Exemplo n.º 31
0
def __init_xml(outputfile, profile):
    xmltree = ElementTree()
    sbrs = Element('shotBoundaryResults')
    SubElement(sbrs,'shotBoundaryResult',
               {'sysId' : 'pimpy '+profile,
                'totalRunTime'          : '0',
                'totalDecodeTime'       : '0',
                'totalSegmentationTime' : '0',
                'processorTypeSpeed'    : '0'})
    xmltree._setroot(sbrs)
    root = sbrs
    sbr = root.find('shotBoundaryResult')
    return root,sbr 
Exemplo n.º 32
0
def writeLoginInfo(info):
    book = ElementTree()
    parent = Element("LoginInfo")
    book._setroot(parent)
    item = Element("user")
    parent.append(item)
    SubElement(item, "id").text = info["userID"]
    SubElement(item, "name").text = info["userName"]
    SubElement(item, "editRole").text = info["editRole"]
    dump(indent(parent))
    if not os.path.exists(confPath.localXml):
        os.makedirs(confPath.localXml)
    book.write(confPath.localXml + "loginInfo.xml", "utf-8")
Exemplo n.º 33
0
    def _json_to_zwo(self, x):
        root = Element('workout_file')

        for child, value in [
            ('author', self.__author), ('name', self.__name),
            ('description',
             '%s\n\n%s' % ('This workout was generated using ZWOG.',
                           self._json_to_pretty(x))), ('sportType', 'bike')
        ]:
            tmp = SubElement(root, child)
            tmp.text = value

        if self.__category is not None:
            tmp = SubElement(root, 'category')
            tmp.text = self.__category

        if self.__subcategory is not None:
            tmp = SubElement(root, 'subcategory')
            tmp.text = self.__subcategory

        tmp = SubElement(root, 'workout')
        for block_idx, block in enumerate(x):
            if (block_idx == 0 or block_idx ==
                (len(x) - 1)) and self._is_ramp(block):  # warmup and ramp
                element = self._interval_to_xml(block['intervals'][0])
                if block_idx == 0:
                    element.tag = 'Warmup'
                else:
                    element.tag = 'Cooldown'
                tmp.append(element)
            else:
                if self._is_ramp(block) or self._is_steady_state(
                        block):  # ramp or steady state
                    tmp.append(self._interval_to_xml(block['intervals'][0]))
                else:
                    if 'repeats' in block:
                        repeats = block['repeats']
                    else:
                        repeats = 1
                    if self._is_intervalst(block):  # intervalst
                        tmp.append(
                            self._interval_to_xml(block['intervals'],
                                                  repeats=repeats))
                    else:  #  non intervalst
                        for _ in range(repeats):
                            for interval in block['intervals']:
                                tmp.append(self._interval_to_xml(interval))

        tree = ElementTree()
        tree._setroot(root)
        return tree
Exemplo n.º 34
0
    def createTopFile(directory, filename, top_n = 5):
        if filename == "" or filename == None:
            return False
        treeP = ElementTree()
        root = Element("top_scores")

        for i in range(top_n):
            top_i = Element("rank")
            top_i.set("user", "__EMPTY__")
            top_i.text = "0"
            root.append(top_i)
        treeP._setroot(root)
        treeP.write(directory+filename+".xml")
        return True
Exemplo n.º 35
0
def datatoxml(xlsdata):
	xml = ElementTree()
	Students = Element('Students')
	xml._setroot(Students)
	for i in range(0,len(xlsdata)):
		Student = Element('Student',{'Name':xlsdata[i][1]})
		Students.append(Student)
		Scores = Element('Scores')
		Student.append(Scores)
		SubElement(Scores,'math').text= xlsdata[i][2]
		SubElement(Scores,'Yuwen').text = xlsdata[i][3]
		SubElement(Scores,'English').text = xlsdata[i][4]
	dump(indent(Students))
	return xml
Exemplo n.º 36
0
def generateShareSDKXmlFile(pluginInfo, decompileDir):
    assetsPath = file_utils.getFullPath(decompileDir) + "/assets"

    if not os.path.exists(assetsPath):
        os.makedirs(assetsPath)

    shareSdkXml = assetsPath + "/ShareSDK.xml"

    if os.path.exists(shareSdkXml):
        os.remove(shareSdkXml)

    tree = ElementTree()
    root = Element('DevInfor')
    tree._setroot(root)

    shareNode = SubElement(root, 'ShareSDK')

    if 'params' in pluginInfo and pluginInfo['params'] != None and len(
            pluginInfo['params']) > 0:
        for param in pluginInfo['params']:
            paramName = param.get('name')
            if paramName == 'AppKey':
                paramValue = param.get('value')
                shareNode.set('AppKey', paramValue)
                break

    subplugins = pluginInfo.get('subplugins')

    if subplugins != None and len(subplugins) > 0:
        index = 1
        for subplg in subplugins:
            subplgNode = SubElement(root, subplg['name'])
            subparams = subplg.get('params')
            if subparams != None and len(subparams) > 0:
                for subparam in subparams:
                    subplgNode.set(subparam['name'], subparam['value'])

            if subplgNode.get('Id') == None:
                subplgNode.set('Id', str(index))
            else:
                subplgNode.attrib['Id'] = str(index)

            if subplgNode.get('Enable') == None:
                subplgNode.set('Enable', 'true')
            else:
                subplgNode.attrib['Enable'] = 'true'

            index = index + 1

    tree.write(shareSdkXml, 'UTF-8')
Exemplo n.º 37
0
def writeSelectedFile(info):
    book = ElementTree()
    parent = Element("FileInfo")
    book._setroot(parent)
    item = Element("file")
    parent.append(item)
    SubElement(item, "project_id").text = info["project_id"]
    SubElement(item, "entity_type").text = info["entity_type"]
    SubElement(item, "entity_id").text = info["entity_id"]
    SubElement(item, "task_id").text = info["task_id"]
    dump(indent(parent))
    if not os.path.exists(confPath.localXml):
        os.makedirs(confPath.localXml)
    book.write(confPath.localXml + "selectedFile.xml", "utf-8")
Exemplo n.º 38
0
def generateShareSDKXmlFile(pluginInfo, decompileDir):
	assetsPath = file_utils.getFullPath(decompileDir) + "/assets"

	if not os.path.exists(assetsPath):
		os.makedirs(assetsPath)

	shareSdkXml = assetsPath + "/ShareSDK.xml"

	if os.path.exists(shareSdkXml):
		os.remove(shareSdkXml)
		
	tree = ElementTree()
	root = Element('DevInfor')
	tree._setroot(root)

	shareNode = SubElement(root, 'ShareSDK')

	if 'params' in pluginInfo and pluginInfo['params'] != None and len(pluginInfo['params']) > 0:
		for param in pluginInfo['params']:
			paramName = param.get('name')
			if paramName == 'AppKey':
				paramValue = param.get('value')
				shareNode.set('AppKey', paramValue)
				break

	subplugins = pluginInfo.get('subplugins')

	if subplugins != None and len(subplugins) > 0:
		index = 1
		for subplg in subplugins:
			subplgNode = SubElement(root, subplg['name'])
			subparams = subplg.get('params')
			if subparams != None and len(subparams) > 0:
				for subparam in subparams:
					subplgNode.set(subparam['name'], subparam['value'])

			if subplgNode.get('Id') == None:
				subplgNode.set('Id', str(index))
			else:
				subplgNode.attrib['Id'] = str(index)

			if subplgNode.get('Enable') == None:
				subplgNode.set('Enable', 'true')
			else:
				subplgNode.attrib['Enable'] = 'true'

			index = index + 1

	tree.write(shareSdkXml, 'UTF-8')
Exemplo n.º 39
0
    def graphml_generate(self, node_list, edge_list, out_name, debug_flag=False):
        # node & edge tuple list sample
        #[('n1', 'v_node_a'), ('n2', 'v_node_b')]
        #[('e0', 'NONE', 'n0', 'n1'), ('e1', 'e_home', 'n2', 'n1')]

        ns_list = {'gns': '{http://graphml.graphdrawing.org/xmlns}',
                  'yns': '{http://www.yworks.com/xml/graphml}'}

        elm_root = ET.Element('graphml', xmlns=ns_list['gns'].strip('{}'))
        elm_root.set('xmlns:y', ns_list['yns'].strip('{}'))
        elm_share_key = ET.SubElement(elm_root, 'key', id="d6")
        elm_share_key.set('yfiles.type', "nodegraphics")
        elm_share_key = ET.SubElement(elm_root, 'key', id="d10")    
        elm_share_key.set('for', "edge")
        elm_share_key.set('yfiles.type', "edgegraphics")    

        elm_graph = ET.SubElement(elm_root, 'graph', edgedefault="directed", id="G")

        for n in node_list:
            elm_node_tmp = ET.SubElement(elm_graph, 'node', id=n[0])
            elm_node_data = ET.SubElement(elm_node_tmp, 'data', key="d6")
            elm_node_data_SN = ET.SubElement(elm_node_data, 'y:ShapeNode')
            elm_node_data_NL = ET.SubElement(elm_node_data_SN, 'y:NodeLabel')
            elm_node_data_NL.text = n[1]

        for n in edge_list:
            elm_edge_tmp = ET.SubElement(elm_graph, 'edge', id=n[0], source=n[2], target=n[3])
            elm_edge_data = ET.SubElement(elm_edge_tmp, 'data', key="d10")
            elm_edge_data_PLE = ET.SubElement(elm_edge_data, 'y:PolyLineEdge')
            if n[1] is not "NONE":
                elm_edge_data_PLE_EL = ET.SubElement(elm_edge_data_PLE, 'y:EdgeLabel') 
                elm_edge_data_PLE_EL.text = n[1]

        tree_root = ElementTree()
        tree_root._setroot(elm_root)
        tree_root.write(out_name, 'UTF-8', 'True')

        if debug_flag is True:
            print 'Node_List:'
            for n in node_list:
                print n
            print '\nEdge_List:' 
            for n in edge_list:
                print n
            print '\nElementTree Dump:'
            ET.dump(elm_root)
            print '\nTree Dump:'
            for child in tree_root.iter():
                print child.tag, child.attrib
Exemplo n.º 40
0
def writeSelectedRef(info):
    book = ElementTree()
    parent = Element("RefInfo")
    book._setroot(parent)
    item = Element("ref")
    parent.append(item)
    SubElement(item, "tab").text = info["tab"]
    SubElement(item, "parent").text = info["parent"]
    SubElement(item, "selectedNode").text = info["currentNode"]
    SubElement(item, "listIndex").text = info["listIndex"]
    SubElement(item, "inputText").text = info["text"]
    dump(indent(parent))
    if not os.path.exists(confPath.localXml):
        os.makedirs(confPath.localXml)
    book.write(confPath.localXml + "SelectedRef.xml", "utf-8")
Exemplo n.º 41
0
    def parse(self):
        clearedList = ListManager.ListManager.clearListFromEmptyTokens(self.tokenList)
        # tworzymy head
        mainTree = ElementTree()
        mainElement = Element("parserTreeHead")
        mainTree._setroot(mainElement)
        lm = ListManager.ListManager()
        lm.loadList(clearedList)

        #        lm.parseListToElement()
        #        tostring(mainElement)

        element = lm.parseListToElement()
        mainElement.append(element)
        wikify(None, self.options)
def generateDeveloperInfo(channel, SDK, usrSDKConfig, decompileDir,
                          privateKey):
    """the infomation about developer would configure here
       the value of element's attribute cann't be int
    """
    assetsDir = decompileDir + '/assets'
    developerFile = assetsDir + '/developerInfo.xml'
    if not os.path.exists(assetsDir):
        os.makedirs(assetsDir)
    targetTree = None
    targetRoot = None
    if not os.path.exists(developerFile):
        targetTree = ElementTree()
        targetRoot = Element('developer')
        targetTree._setroot(targetRoot)
    else:
        targetTree = ET.parse(developerFile)
        targetRoot = targetTree.getroot()
    infoNode = targetRoot.find('channel')
    if infoNode is None:
        infoNode = SubElement(targetRoot, 'channel')
    if infoNode.get('idChannel') is None:
        infoNode.set('idChannel', str(channel['channelNum']))
        infoNode.set('uApiKey', channel['uapiKey'])
        infoNode.set('uApiSecret', channel['uapiSecret'])
        infoNode.set('oauthLoginServer', channel['oauthLoginServer'])
        if channel['extChannel'] is not None:
            infoNode.set('extChannel', channel['extChannel'])
        infoNode.set('privateKey', privateKey)
    if SDK.get('showVersion') is not None:
        attrName = SDK['SDKName'] + '_Version'
        infoNode.set(attrName, SDK['showVersion'])
    for param in usrSDKConfig['param']:
        if param['bWriteIntoClient'] and not param['bWriteIntoManifest']:
            paramName = param['name']
            pos = paramName.find('##')
            if pos != -1:
                paramName = paramName[pos + 2:]
            if paramName.count('Orientation') > 0:
                infoNode.set(
                    paramName,
                    modifyManifest.getOrientation(
                        decompileDir + '/AndroidManifest.xml', usrSDKConfig))
            else:
                infoNode.set(paramName, param['value'])

    targetTree.write(developerFile, 'UTF-8')
    file_operate.printf('generate developerInfo.xml success')
Exemplo n.º 43
0
def print_out_xml(out_file='book.xml'):
    book = ElementTree()

    purchaseorder = Element('RECORDS')
    book._setroot(purchaseorder)

    purchaseorder2 = Element('RECORD')
    SubElement(purchaseorder2, 'id').text = 'aaaa'
    SubElement(purchaseorder2, 'article').text = 'bbbb'

    purchaseorder3 = Element('RECORD')
    SubElement(purchaseorder3, 'id').text = 'aaaa'
    SubElement(purchaseorder3, 'article').text = 'bbbb'
    purchaseorder.append(purchaseorder2)
    purchaseorder.append(purchaseorder3)

    dump(indent(purchaseorder))
    book.write(out_file, "utf-8")
Exemplo n.º 44
0
def Save2XML(appName,cfgName):

    dic = iniCfg.GetConfig(cfgName)
    
    eTree = ElementTree()
    
    root = Element(appName)
    eTree._setroot(root)
    for subDic in dic:
        pos = subDic.find('.')
        #print "'"+skey[pos+1:]+"':{'en':"+skey[pos+1:]+"','cn':''},"
        sec =subDic[:pos]
        skey=subDic[pos+1:]
        #print 'sec:'+TransStr(sec)
        #print "____key:"+TransStr(skey)+"="+dic[subDic]
        SubElement(root,subDic,{"text":TransStr(skey),"desc":subDic,"category":TransStr(sec)}).text=dic[subDic]
    dump(indent(root))    
    eTree.write(appName+".xml","utf-8")
Exemplo n.º 45
0
def CreateXml():
    book =ElementTree()
    purOrder =Element("MTP")
    book._setroot(purOrder)

    list = Element("account",{'id':'2390094'})
    purOrder.append(list)
    item = Element("item1",{"Adresse":"abcd","Attribute":"4"})
    SubElement(item,"Name").text="Ventil1"
    SubElement(item,"Description").text="Wasserleitung1"
    purOrder.append(item)
    
    item = Element("item2",{"Adresse":"gfhi","attribute":"40"})
    SubElement(item,"Name").text="Ventil2"
    SubElement(item,"Description").text="Wasserleitung2"
    purOrder.append(item)
    
    indent(purOrder)
    return book
Exemplo n.º 46
0
 def generarXMLPlayers(self):
     pperteam = self.numPlayers/self.teamsCount
     rootP = Element("root")
     for team in self.teams:
         tagTeam = Element("team")
         tagTeam.set("color", team)
         for player in self.players:
             if player.team == team:
                 tagPlayer = Element("player")
                 tagPlayer.set("nombre", player.nombre)
                 tagPlayer.set("iniX", str(player.iniX))
                 tagPlayer.set("iniY", str(player.iniY))
                 tagPlayer.set("vidas", str(player.vidas))
                 tagPlayer.text = player.getSpriteFullName()
                 tagTeam.append(tagPlayer)
         rootP.append(tagTeam)
     treeP = ElementTree()
     treeP._setroot(rootP)
     treeP.write("playersInfo.xml","utf-8")
Exemplo n.º 47
0
def gen_filelist(dir_list,version,noconfirm):
    print "正在生成版本差异文件..."
    from xml.etree.ElementTree import ElementTree,Element
    book =  ElementTree()
    filelist = []
    rootNode = Element("filelist",{"version":version,"time":curtime})
    rootNode.tail  = "\r\n"
    book._setroot(rootNode)
    preRootNode = None
    isExist = os.path.exists("filelist.xml")
    if isExist:
        preRootNode = ElementTree().parse("filelist.xml") 
    book._setroot(rootNode)
    #代码资源
    # dir_list = ['res','scripts']
    for dirname in dir_list:
        dirname = project_path+dirname
		# compare_file(project_path+dirname, rootNode, preRootNode, filelist)
        if  os.path.isdir(dirname):
            for root, dirs, files in os.walk(dirname):
                for name in files:
                    namekey = os.path.relpath(os.path.join(root, name),project_path)
                    if name[0] != "." and namekey[0] != "." :
                        md5now = filemd5(os.path.join(root, name))
                        md5pre = getMd5FromXmlFile(preRootNode,namekey)
                        if preRootNode != None and md5now != md5pre:
                            if not noconfirm:
                                    yesorno = input("确定更新文件--->   " + namekey + "(y/n):")
                            if noconfirm or yesorno.lower() == "y" :
                                filelist.append(namekey)
                                element = Element("file",{"name":namekey,"md5":md5now})
                                element.tail  = "\r"
                            elif md5pre != "" :
                                element = Element("file",{"name":namekey,"md5":md5now})
                                element.tail  = "\r"
                            rootNode.append(element)
    else :
        print "新资源路径错误"

    book.write("filelist.xml","UTF-8")
    shutil.copy("filelist.xml",backoutput)
    return 	filelist
Exemplo n.º 48
0
def write_dangerous_permissions(manifestFile, decompileDir, permissions,
                                protocolUrl, isLandscape):
    permissionFile = os.path.join(decompileDir, "assets")
    if not os.path.exists(permissionFile):
        os.makedirs(permissionFile)
    permissionFile = os.path.join(permissionFile, "u8_permissions.xml")

    needWriteSettings = is_need_write_settings(manifestFile)

    targetTree = None
    targetRoot = None
    pluginNodes = None

    targetTree = ElementTree()
    targetRoot = Element('permissions')
    targetTree._setroot(targetRoot)

    if needWriteSettings:
        targetRoot.set('writeSettings', 'true')
    else:
        targetRoot.set('writeSettings', 'false')

    if protocolUrl != None and len(protocolUrl) > 0:
        targetRoot.set('protocolUrl', protocolUrl)

    if isLandscape:
        targetRoot.set('protocolOrientation', 'landscape')
    else:
        targetRoot.set('protocolOrientation', 'portrait')

    for pkey in permissions:
        p = permissions[pkey]
        typeTag = 'permission'
        typeName = p['permission']
        typeCName = p['name']
        typeGroup = p['group']
        pluginNode = SubElement(targetRoot, typeTag)
        pluginNode.set('name', typeName)
        pluginNode.set('cname', typeCName)
        pluginNode.set('group', typeGroup)

    targetTree.write(permissionFile, 'UTF-8')
Exemplo n.º 49
0
def Save2XML2(appName,cfgName):

    dic = getIniContent.getContent(cfgName)
    
    eTree = ElementTree()
    
    root = Element(appName)
    eTree._setroot(root)
    for subDic in dic:
        pos = subDic.find('.')
        #print "'"+skey[pos+1:]+"':{'en':"+skey[pos+1:]+"','cn':''},"
        sec =subDic[:pos]
        skey=subDic[pos+1:]
        print 'sec:'+TransStr(sec)
        va = dic[subDic]
        #dic["optname"]+" "+ dic["value"]+" "+ dic["rem"]
        #print "____key:"+TransStr(skey)+"="+dic[subDic]
        print va.get("rem")
        SubElement(root,subDic,{"text":TransStr(skey),"desc":va.get("rem"),"category":TransStr(sec)}).text=va.get("value")
    #dump(indent(root))    
    eTree.write(appName+".xml","utf-8")
Exemplo n.º 50
0
def writeChannelInfoIntoDevelopInfo(workDir, channel, game):
    """
    the infomation about channel would configure here
    """
    developerFile = workDir + '/developerInfo.xml'
    targetTree = None
    targetRoot = None

    if os.path.exists(developerFile):
        file_operate.delete_file_folder(developerFile)

    if not os.path.exists(developerFile):
        targetTree = ElementTree()
        targetRoot = Element('developer')
        targetTree._setroot(targetRoot)
    else:
        print 'exists developerInfo!!!----' + developerFile
        targetTree = ET.parse(developerFile)
        targetRoot = targetTree.getroot()
    infoNode = targetRoot.find('channel')
    if infoNode is None:
        infoNode = SubElement(targetRoot, 'channel')
    channelNum = str(channel.get('customChannelNumber'))
    if channelNum == '' or channelNum is None:
        channelNum = str(channel.get('channelNum'))
    if infoNode.get('idChannel') is None:
        infoNode.set('idChannel', channelNum)
        infoNode.set('uApiKey', channel['uapiKey'])
        infoNode.set('uApiSecret', channel['uapiSecret'])
        infoNode.set('oauthLoginServer', channel['oauthLoginServer'])
        if channel['extChannel'] is not None:
            infoNode.set('extChannel', channel['extChannel'])
        if game.get('privateKey') is not None:
            infoNode.set('privateKey', game['privateKey'])
        if game.get('order_url') is not None and game['order_url'] != '':
            infoNode.set('order_url', game['order_url'])
        infoNode.set('standby_domain_name', 'pay.rsdk.com')
    targetTree.write(developerFile, 'UTF-8')
    file_operate.printf(
        "Save channel's information to developerInfo.xml success")
    def handle_file(self, matches, file):
        logger.debug("Writing %d matches to %s", len(matches), file)
        ET.register_namespace("torrent", "http://xmlns.ezrss.it/0.1/")
        try:
            tree = ElementTree(file=file)
        except (IOError, ParseError):
            # rss tag does not exist, file did not exist yet, or was corrupted somehow
            tree = ElementTree()
        root = tree.getroot()
        if tree.getroot() is None:
            root = Element("rss", attrib={"version" : "2.0"})
            tree._setroot(root)
        channel = root.find("channel")
        if channel is None:
            channel = Element("channel")
            channel.append(self.create_element_with_text("title", self.title))
            channel.append(self.create_element_with_text("link", self.link))
            channel.append(self.create_element_with_text("description", self.description))
            build_date = datetime.utcnow().strftime("%a, %d %b %Y %H:%M:%S %j") # Sat, 07 Sep 2002 9:42:31 GMT
            channel.append(self.create_element_with_text("lastBuildDate", build_date)) 
            root.append(channel)
        if len(matches) > self.max_torrents: # If there are more than we can fit, choose the first self.max_torrents
            matches = matches[:self.max_torrents]
        for match in matches:
            channel.insert(3, match.torrent.item) # After title, link, description
        items = channel.findall("item")
        while len(items) > self.max_torrents: # If there are more elements than we can fit
            channel.remove(items.pop()) # Remove the oldest from the list        
        self.insert_CDATA(items)
#         tree.write(self.file, encoding="utf-8", xml_declaration=True)
        pretty_xml = self.prettify_xml(root)
        try:
            with open(file, "wb") as f:
                f.write(pretty_xml)
        except IOError:
            return []
        return matches
Exemplo n.º 52
0
    def graphml_generate(self,
                         node_list,
                         edge_list,
                         out_name,
                         debug_flag=False):
        # node & edge tuple list sample
        #[('n1', 'v_node_a'), ('n2', 'v_node_b')]
        #[('e0', 'NONE', 'n0', 'n1'), ('e1', 'e_home', 'n2', 'n1')]

        ns_list = {
            'gns': '{http://graphml.graphdrawing.org/xmlns}',
            'yns': '{http://www.yworks.com/xml/graphml}'
        }

        elm_root = ET.Element('graphml', xmlns=ns_list['gns'].strip('{}'))
        elm_root.set('xmlns:y', ns_list['yns'].strip('{}'))
        elm_share_key = ET.SubElement(elm_root, 'key', id="d6")
        elm_share_key.set('yfiles.type', "nodegraphics")
        elm_share_key = ET.SubElement(elm_root, 'key', id="d10")
        elm_share_key.set('for', "edge")
        elm_share_key.set('yfiles.type', "edgegraphics")

        elm_graph = ET.SubElement(elm_root,
                                  'graph',
                                  edgedefault="directed",
                                  id="G")

        for n in node_list:
            elm_node_tmp = ET.SubElement(elm_graph, 'node', id=n[0])
            elm_node_data = ET.SubElement(elm_node_tmp, 'data', key="d6")
            elm_node_data_SN = ET.SubElement(elm_node_data, 'y:ShapeNode')
            elm_node_data_NL = ET.SubElement(elm_node_data_SN, 'y:NodeLabel')
            elm_node_data_NL.text = n[1]

        for n in edge_list:
            elm_edge_tmp = ET.SubElement(elm_graph,
                                         'edge',
                                         id=n[0],
                                         source=n[2],
                                         target=n[3])
            elm_edge_data = ET.SubElement(elm_edge_tmp, 'data', key="d10")
            elm_edge_data_PLE = ET.SubElement(elm_edge_data, 'y:PolyLineEdge')
            if n[1] is not "NONE":
                elm_edge_data_PLE_EL = ET.SubElement(elm_edge_data_PLE,
                                                     'y:EdgeLabel')
                elm_edge_data_PLE_EL.text = n[1]

        tree_root = ElementTree()
        tree_root._setroot(elm_root)
        tree_root.write(out_name, 'UTF-8', 'True')

        if debug_flag is True:
            print 'Node_List:'
            for n in node_list:
                print n
            print '\nEdge_List:'
            for n in edge_list:
                print n
            print '\nElementTree Dump:'
            ET.dump(elm_root)
            print '\nTree Dump:'
            for child in tree_root.iter():
                print child.tag, child.attrib
Exemplo n.º 53
0
 def write(self, data):
     tree = ElementTree()
     tree._setroot(ConvertUtils.data_to_xml_node(data))
     tree.write(self.file_name)
Exemplo n.º 54
0
def write_layout(layout, filename):
    tree = ElementTree()
    tree._setroot(layout)
    tree.write("index.xml")
    with zipfile.ZipFile('%s.touchosc' % filename, 'w') as myzip:
        myzip.write('index.xml')
def main(argv):

    parser = argparse.ArgumentParser()
    # Required arguments: input and output files.
    parser.add_argument("patch_dir_root", help="Input image, directory")
    parser.add_argument("jpg_dir", help="Feature mat filename.")
    parser.add_argument("shape2_xml_dir", help="Score Output mat filename.")
    parser.add_argument("dir_out", help="Score Output mat filename.")
    # Optional arguments.
    parser.add_argument(
        "--model_def",
        default=os.path.join("./models/market1501/caffenet/feature.proto"),
        help="Model definition file.")
    parser.add_argument(
        "--pretrained_model",
        default=os.path.join(
            "./models/market1501/caffenet/caffenet_iter_17000.caffemodel"),
        help="Trained model weights file.")
    parser.add_argument("--gpu",
                        type=int,
                        default=-1,
                        help="Switch for gpu computation.")
    parser.add_argument(
        "--center_only",
        action='store_true',
        help="Switch for prediction from center crop alone instead of " +
        "averaging predictions across crops (default).")
    parser.add_argument(
        "--images_dim",
        default='256,256',
        help="Canonical 'height,width' dimensions of input images.")
    parser.add_argument(
        "--mean_value",
        default=os.path.join(
            'examples/market1501/market1501_mean.binaryproto'),
        help="Data set image mean of [Channels x Height x Width] dimensions " +
        "(numpy array). Set to '' for no mean subtraction.")
    parser.add_argument(
        "--input_scale",
        type=float,
        help="Multiply input features by this scale to finish preprocessing.")
    parser.add_argument(
        "--raw_scale",
        type=float,
        default=255.0,
        help="Multiply raw input by this scale before preprocessing.")
    parser.add_argument(
        "--channel_swap",
        default='2,1,0',
        help="Order to permute input channels. The default converts " +
        "RGB -> BGR since BGR is the Caffe default by way of OpenCV.")
    parser.add_argument(
        "--ext",
        default='jpg',
        help="Image file extension to take as input when a directory " +
        "is given as the input file.")
    parser.add_argument("--feature_name",
                        default="fc7",
                        help="feature blob name.")
    parser.add_argument("--score_name",
                        default="prediction",
                        help="prediction score blob name.")
    args = parser.parse_args()

    #======================================================================================================
    # cfg.TEST.HAS_RPN = True  # Use RPN for proposals
    # cfg.TEST.RPN_PRE_NMS_TOP_N = 6000
    # ## Number of top scoring boxes to keep after applying NMS to RPN proposals
    # cfg.TEST.RPN_POST_NMS_TOP_N = 2000 #lius 300
    # #cfg.TEST.RPN_POST_NMS_TOP_N = 2000 #lius 300
    # cfg.TEST.AGNOSTIC=True
    # #cfg.TEST.AGNOSTIC=False
    # cfg.TEST.RPN_MIN_SIZE=10
    # prototxt = "/home/liushuai/tiannuocaffe/py-rfcn-gpu/models/shape/ResNet-101_2/rfcn_end2end/s16_14/b14_test_16_s_4_8_16_32_agnostic.prototxt"
    # caffemodel = "/home/liushuai/tiannuocaffe/py-rfcn-gpu/output/goodsType/shapeproj2_trainval/ResNet-101_2_b14_16_s_4_8_16_32_shape_rfcn_ohem_iter_210000.caffemodel"

    # save_ff="/storage2/liushuai/faster_rcnn/FasterRCNN-Encapsulation-Cplusplus/faster_cxx_lib_ev2641/test_resultvgg.jpg"
    # im_name="/storage2/liushuai/faster_rcnn/FasterRCNN-Encapsulation-Cplusplus/faster_cxx_lib_ev2641//cat.jpg"
    # im_name="/storage2/tiannuodata/work/projdata/baiwei/baiweiproj1/JPEGImages/budweiser08782.jpg"#budweiser15059.jpg"
    # num_class=2-1#1360-1 #341
    # if not os.path.isfile(caffemodel):
    #     raise IOError(('{:s} not found.\nDid you run ./data/script/'
    #                    'fetch_faster_rcnn_models.sh?').format(caffemodel))

    # caffe.set_mode_gpu()
    # caffe.set_device(5)
    # cfg.GPU_ID = 5
    # net = caffe.Net(prototxt, caffemodel, caffe.TEST)

    # print '\n\nLoaded network {:s}'.format(caffemodel)

    # # Warmup on a dummy image
    # im = 128 * np.ones((300, 500, 3), dtype=np.uint8)
    # # for i in xrange(2):
    # #     _, _= im_detect(net, im)

    # im_names = ['000456.jpg', '000542.jpg', '001150.jpg',
    #             '001763.jpg', '004545.jpg']
    # # for im_name in im_names:
    # #     print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
    # #     print 'Demo for data/demo/{}'.format(im_name)
    # demo(net, im_name,num_class,save_ff)
    #======================================================================================================
    args.images_dim = "224,224"
    # args.channel_swap="0,1,2"
    # args.raw_scale =1
    image_dims = [int(s) for s in args.images_dim.split(',')]

    channel_swap = None
    if args.channel_swap:
        channel_swap = [int(s) for s in args.channel_swap.split(',')]

    mean_value = None
    if args.mean_value:
        mean_value = [float(s) for s in args.mean_value.split(',')]
        mean_value = np.array(mean_value)

    if args.gpu >= 0:
        caffe.set_mode_gpu()
        caffe.set_device(args.gpu)
        print("GPU mode, device : {}".format(args.gpu))
    else:
        caffe.set_mode_cpu()
        print("CPU mode")

    # Make classifier
    # classifier = SClassifier(args.model_def, args.pretrained_model,
    #       image_dims=image_dims, mean_value=mean_value,
    #       input_scale=args.input_scale, raw_scale=args.raw_scale,
    #       channel_swap=channel_swap)
    classifier = Classifier(args.model_def,
                            args.pretrained_model,
                            image_dims=image_dims,
                            mean=mean_value,
                            input_scale=args.input_scale,
                            raw_scale=args.raw_scale,
                            channel_swap=channel_swap)
    #dir_1="/storage2/liushuai/gs6_env/market1501_extract_freature/dalu2//OK/"
    patch_dir_root = args.patch_dir_root  #"/storage2/liushuai/gs6_env/baiwei_patch_result/"
    jpg_dir = args.jpg_dir  #"/storage2/tiannuodata/work/projdata/baiwei/baiweiproj2/JPEGImages/"
    shape2_xml_dir = args.shape2_xml_dir  #"/storage2/liushuai/gs6_env/market1501_extract_freature/dalu2//NG/"
    dir_out = args.dir_out  #"/storage2/liushuai/gs6_env/market1501_extract_freature/dalu2//out/"
    # dir_1="/storage2/liushuai/gs6_env/market1501_extract_freature/test//OK/"
    # dir_2="/storage2/liushuai/gs6_env/market1501_extract_freature/test//NG/"
    # dir_out="/storage2/liushuai/gs6_env/market1501_extract_freature/test//out/"
    patch_dir_list = os.listdir(patch_dir_root)
    feature_all = []
    label_all = []

    start_time = time.time()
    epoch_time = AverageMeter()
    mat_count = 0
    for patch_dir in patch_dir_list:
        tmp_path = os.path.join(patch_dir_root, patch_dir)
        if os.path.isdir(tmp_path) == True:
            #rint tmp_path
            sku_file_list = os.listdir(tmp_path)
            for sku_file in sku_file_list:
                #rint os.path.splitext(sku_file)[1]
                if os.path.splitext(sku_file)[1] == ".mat":
                    mat_1 = sio.loadmat(os.path.join(tmp_path, sku_file))
                    feature_1 = mat_1["feature"].copy()
                    #rint "feature_1",feature_1.shape,len(feature_1)
                    feature_all.append(feature_1)
                    label_all.append(patch_dir)
                    mat_count = mat_count + 1
    epoch_time.update(time.time() - start_time)
    start_time = time.time()
    need_hour, need_mins, need_secs = convert_secs2time(epoch_time.avg)
    need_time = '{:02d}:{:02d}:{:02d}'.format(need_hour, need_mins, need_secs)
    print mat_count, "mat file.total need time :", need_time
    # save_feature_all=None
    # labels_all=[]
    # list_1 = os.listdir(dir_1)
    # for file_1 in list_1:
    #   if os.path.splitext(file_1)[1] !=".xml":
    #     print file_1
    #     basename = os.path.splitext(file_1)[0]
    #     jpgname = dir_1+file_1
    #     xmlname= dir_1+basename+".xml"
    #     im = caffe.io.load_image(jpgname)#cv2.imread(jpgname)
    #     # im = cv2.imread(jpgname)
    #     # im= im*1.0
    #     baseInfo,objects = parse_xml(xmlname)
    #     save_feature=None
    #     #labels=None
    #     for idx_f,oject_1 in enumerate(objects):
    #       #cropImg = im[oject_1["bbox"][0]:oject_1["bbox"][2],oject_1["bbox"][1]:oject_1["bbox"][3] ]
    #       cropImg = im[oject_1["bbox"][1]:oject_1["bbox"][3], oject_1["bbox"][0]:oject_1["bbox"][2]]
    #       #=============================================================test
    #       # if oject_1['name']=="others" and idx_f==0:
    #       #   #skimage.io.imsave("/storage2/liushuai/gs6_env/market1501_extract_freature/dalu2/OK_patch_dir/cat.jpg",255.0*cropImg)
    #       #   cv2.imwrite("/storage2/liushuai/gs6_env/market1501_extract_freature/dalu2/OK_patch_dir/cat.jpg",255.0*cropImg[:,:,[2,1,0]])
    #       #=============================================================test
    #       _ = classifier.predict([cropImg], not args.center_only)
    #       feature = classifier.get_blob_data(args.feature_name)
    #       assert (feature.shape[0] == 1 )
    #       feature_shape = feature.shape
    #       if save_feature is None:
    #           print('feature : {} : {}'.format(args.feature_name, feature_shape))
    #           save_feature = np.zeros((len(objects), feature.size),dtype=np.float32)
    #       #feature = feature.reshape(1, feature.size)
    #       feature = feature.reshape(-1)
    #       print "feature.shape ",feature.shape
    #       save_feature[idx_f, :] = feature.copy()
    #       labels_all.append(oject_1['name'])
    #       #tmp_file_name=os.path.basename(file_list[idx_f])
    #       #sio.savemat(dir_1+'/'+basename+".feature", {'feature':feature})
    #     if save_feature_all==None:
    #       save_feature_all=save_feature
    #     else:
    #       save_feature_all=np.concatenate((save_feature_all,save_feature),axis=0)
    # # print len(labels_all),len(save_feature)
    # # print labels_all
    # # print "save_feature_all.shape",save_feature_all.shape

    list_2 = os.listdir(jpg_dir)
    random.shuffle(list_2)
    icount = 0
    for file_2 in list_2:
        if os.path.splitext(file_2)[1] != ".xml":
            print file_2
            basename_2 = os.path.splitext(file_2)[0]
            jpgname_2 = jpg_dir + file_2
            xmlname_2 = shape2_xml_dir + basename_2 + ".xml"
            im = caffe.io.load_image(jpgname_2)  #cv2.imread(jpgname_2)
            # im = cv2.imread(jpgname_2)
            # im= im*1.0
            baseInfo_2, objects_2 = parse_xml(xmlname_2)
            save_feature = None
            labels = []

            start_time = time.time()
            epoch_time = AverageMeter()
            for idx_f_2, oject_2 in enumerate(objects_2):
                # if oject_2['name']=="origin":
                #   labels.append("origin")
                #   continue
                # if oject_2['name']=="miss":
                #   labels.append("miss")
                #   continue
                cropImg = im[oject_2["bbox"][1]:oject_2["bbox"][3],
                             oject_2["bbox"][0]:oject_2["bbox"][2]]
                #=============================================================test
                # if oject_2['name']=="weimeng1":#coco10
                #   print oject_2["bbox"][0],oject_2["bbox"][1],oject_2["bbox"][2],oject_2["bbox"][3]
                #   #skimage.io.imsave('/storage2/liushuai/gs6_env/market1501_extract_freature/dalu2/OK_patch_dir/coco10.jpg',255.0*cropImg)
                #   cv2.imwrite("/storage2/liushuai/gs6_env/market1501_extract_freature/dalu2/OK_patch_dir/weimeng1.jpg",255.0*cropImg[:,:,[2,1,0]])
                #=============================================================test
                _ = classifier.predict([cropImg], not args.center_only)
                feature = classifier.get_blob_data(args.feature_name)
                assert (feature.shape[0] == 1)
                feature_shape = feature.shape
                # if save_feature is None:
                #     print('feature : {} : {}'.format(args.feature_name, feature_shape))
                #     save_feature = np.zeros((len(objects), feature.size),dtype=np.float32)
                #feature_here = feature.reshape(1, feature.size)
                feature_here = feature.reshape(-1)
                #rint "feature.shape ",feature_here.shape
                #save_feature[idx_f, :] = feature.copy()
                b_same_class = False
                bmin = 1000.0
                bb_index = 0
                #rint "len:",len(feature_all)
                for bb_fea in range(0, len(feature_all)):
                    #print aa_fea," ",bb_fea," ",same_file_list[bb_fea][0]
                    ret = comp_feature(feature_all[bb_fea], feature_here)
                    #rint label_all[bb_fea],ret,oject_2['name']
                    if ret < 0.2:  #0.3
                        #print "            ",label_all[bb_fea],ret,oject_2['name'],"     ok"
                        b_same_class = True
                        #print type(bb_fea)
                        if ret < bmin:
                            bb_index = bb_fea
                            bmin == ret
                        # if ret<0.1:#0.15
                        #   break
                if b_same_class == True:
                    labels.append(label_all[bb_index])
                    oject_2['name'] = label_all[bb_index]
                else:
                    #print "                             ",oject_2['name'],"     background"
                    labels.append("background")
                    oject_2['name'] = "background"

                epoch_time.update(time.time() - start_time)
                start_time = time.time()
            need_hour, need_mins, need_secs = convert_secs2time(epoch_time.avg)
            need_time = '{:02d}:{:02d}:{:02d}'.format(need_hour, need_mins,
                                                      need_secs)
            print len(objects_2), "every object need time : ", need_time

            ppsring = "cp " + jpgname_2 + " " + dir_out + "/"
            assert Popen_do(ppsring), ppsring + " error!"

            b_empty = True
            for oject_2 in objects_2:
                if oject_2['name'] != "background":
                    b_empty = False
            if b_empty == True:
                continue
            four_root = ElementTree()
            A1 = create_node('annotation', {}, "")
            four_root._setroot(A1)
            B1 = create_node('foder', {}, "2")
            B2 = create_node('filename', {}, jpgname_2)
            B3 = create_node('path', {}, "2")
            A1.append(B1)
            A1.append(B2)
            A1.append(B3)
            B4 = create_node('source', {}, "")
            A1.append(B4)
            C1 = create_node('database', {}, "Unknown")
            B4.append(C1)
            B5 = create_node('size', {}, "")
            SubElement(B5, "width").text = str(im.shape[1])
            SubElement(B5, "height").text = str(im.shape[0])
            SubElement(B5, "depth").text = "3"
            A1.append(B5)
            # SubElement(A1,"folder").text=str(width[i])
            # SubElement(A1,"filename").text=str(height[i])
            # SubElement(A1,"path").text="3"
            for idx_f_2, oject_2 in enumerate(objects_2):
                if oject_2['name'] == "background":
                    continue

                BBobj = create_node('object', {}, "")
                SubElement(BBobj, "name").text = oject_2['name']
                SubElement(BBobj, "pose").text = 'Unspecified'
                SubElement(BBobj, "truncated").text = '0'
                SubElement(BBobj, "difficult").text = '0'
                SubElement(BBobj, "score").text = oject_2['score']
                SubElement(BBobj, "region").text = oject_2['region']
                SubElement(BBobj, "label_des").text = oject_2['label_des']
                SubElement(BBobj, "imageptr").text = oject_2['imageptr']
                child5 = SubElement(BBobj, "bndbox")
                # child1= create_node('name',{},obj['name'])
                SubElement(child5, "xmin").text = str(oject_2["bbox"][0])
                SubElement(child5, "ymin").text = str(oject_2["bbox"][1])
                SubElement(child5, "xmax").text = str(oject_2["bbox"][2])
                SubElement(child5, "ymax").text = str(oject_2["bbox"][3])
                A1.append(BBobj)
            print dir_out + "/" + basename_2 + ".xml"
            four_root.write(dir_out + "/" + basename_2 + ".xml",
                            encoding="utf-8",
                            xml_declaration=False)

            icount = icount + 1
            if icount == 1000:
                break
Exemplo n.º 56
0
class LibvirtKvm(VirtBase):
    def __init__(self, dut, name, suite):
        # initialize virtualization base module
        super(LibvirtKvm, self).__init__(dut, name, suite)

        # initialize qemu emulator, example: qemu-system-x86_64
        self.qemu_emulator = self.get_qemu_emulator()

        # disk and pci device default index
        self.diskindex = 'a'
        self.pciindex = 10

        # configure root element
        self.root = ElementTree()
        self.domain = ET.Element('domain')
        # replace root element
        self.root._setroot(self.domain)
        # add xml header
        self.domain.set('type', 'kvm')
        self.domain.set('xmlns:qemu',
                        'http://libvirt.org/schemas/domain/qemu/1.0')
        ET.SubElement(self.domain, 'name').text = name

        # devices pass-through into vm
        self.pci_maps = []

        # default login user,password
        self.username = self.host_dut.crb['user']
        self.password = self.host_dut.crb['pass']

        # internal variable to track whether default nic has been added
        self.__default_nic = False

        # set some default values for vm,
        # if there is not the values of the specified options
        self.set_vm_default()

    def get_qemu_emulator(self):
        """
        Get the qemu emulator based on the crb.
        """
        arch = self.host_session.send_expect('uname -m', '# ')
        return '/usr/bin/qemu-system-' + arch

    def get_virt_type(self):
        return 'LIBVIRT'

    def has_virtual_ability(self):
        """
        check and setup host virtual ability
        """
        out = self.host_session.send_expect('cat /proc/cpuinfo | grep flags',
                                            '# ')
        rgx = re.search(' vmx ', out)
        if rgx:
            pass
        else:
            self.host_logger.warning("Hardware virtualization "
                                     "disabled on host!!!")
            return False

        out = self.host_session.send_expect('lsmod | grep kvm', '# ')
        if 'kvm' not in out or 'kvm_intel' not in out:
            return False

        out = self.host_session.send_expect('service libvirtd status', "# ")
        if 'active (running)' not in out:
            return False

        return True

    def load_virtual_mod(self):
        self.host_session.send_expect('modprobe kvm', '# ')
        self.host_session.send_expect('modprobe kvm_intel', '# ')

    def unload_virtual_mod(self):
        self.host_session.send_expect('rmmod kvm_intel', '# ')
        self.host_session.send_expect('rmmod kvm', '# ')

    def disk_image_is_ok(self, image):
        """
        Check if the image is OK and no error.
        """
        pass

    def add_vm_mem(self, **options):
        """
        Options:
            size : memory size, measured in MB
            hugepage : guest memory allocated using hugepages
        """
        if 'size' in options.keys():
            memory = ET.SubElement(self.domain, 'memory', {'unit': 'MB'})
            memory.text = options['size']
        if 'hugepage' in options.keys():
            memoryBacking = ET.SubElement(self.domain, 'memoryBacking')
            ET.SubElement(memoryBacking, 'hugepages')

    def set_vm_cpu(self, **options):
        """
        Set VM cpu.
        """
        index = self.find_option_index('cpu')
        if index:
            self.params[index] = {'cpu': [options]}
        else:
            self.params.append({'cpu': [options]})

    def add_vm_cpu(self, **options):
        """
        'number' : '4' #number of vcpus
        'cpupin' : '3 4 5 6' # host cpu list
        """
        vcpu = 0
        if 'number' in options.keys():
            vmcpu = ET.SubElement(self.domain, 'vcpu', {'placement': 'static'})
            vmcpu.text = options['number']
        if 'cpupin' in options.keys():
            cputune = ET.SubElement(self.domain, 'cputune')
            # cpu resource will be allocated
            req_cpus = options['cpupin'].split()
            cpus = self.virt_pool.alloc_cpu(vm=self.vm_name, corelist=req_cpus)
            for cpu in cpus:
                ET.SubElement(cputune, 'vcpupin', {
                    'vcpu': '%d' % vcpu,
                    'cpuset': cpu
                })
                vcpu += 1
        else:  # request cpu from vm resource pool
            cpus = self.virt_pool.alloc_cpu(self.vm_name,
                                            number=int(options['number']))
            for cpu in cpus:
                ET.SubElement(cputune, 'vcpupin', {
                    'vcpu': '%d' % vcpu,
                    'cpuset': cpu
                })
                vcpu += 1

    def get_vm_cpu(self):
        cpus = self.virt_pool.get_cpu_on_vm(self.vm_name)
        return cpus

    def add_vm_qga(self, options):
        qemu = ET.SubElement(self.domain, 'qemu:commandline')
        ET.SubElement(qemu, 'qemu:arg', {'value': '-chardev'})
        ET.SubElement(
            qemu, 'qemu:arg', {
                'value':
                'socket,path=/tmp/' + '%s_qga0.sock,' % self.vm_name +
                'server,nowait,id=%s_qga0' % self.vm_name
            })
        ET.SubElement(qemu, 'qemu:arg', {'value': '-device'})
        ET.SubElement(qemu, 'qemu:arg', {'value': 'virtio-serial'})
        ET.SubElement(qemu, 'qemu:arg', {'value': '-device'})
        ET.SubElement(
            qemu, 'qemu:arg', {
                'value':
                'virtserialport,' + 'chardev=%s_qga0' % self.vm_name +
                ',name=org.qemu.guest_agent.0'
            })
        self.qga_sock_path = '/tmp/%s_qga0.sock' % self.vm_name

    def set_vm_default(self):
        os = ET.SubElement(self.domain, 'os')
        type = ET.SubElement(os, 'type', {
            'arch': 'x86_64',
            'machine': 'pc-i440fx-1.6'
        })
        type.text = 'hvm'
        ET.SubElement(os, 'boot', {'dev': 'hd'})
        features = ET.SubElement(self.domain, 'features')
        ET.SubElement(features, 'acpi')
        ET.SubElement(features, 'apic')
        ET.SubElement(features, 'pae')

        ET.SubElement(self.domain, 'cpu', {'mode': 'host-passthrough'})

        # qemu-kvm for emulator
        device = ET.SubElement(self.domain, 'devices')
        ET.SubElement(device, 'emulator').text = self.qemu_emulator

        # graphic device
        ET.SubElement(device, 'graphics', {
            'type': 'vnc',
            'port': '-1',
            'autoport': 'yes'
        })
        # qemu guest agent
        self.add_vm_qga(None)

        # add default control interface
        if not self.__default_nic:
            def_nic = {'type': 'nic', 'opt_hostfwd': '', 'opt_addr': '00:1f.0'}
            self.add_vm_net(**def_nic)
            self.__default_nic = True

    def set_qemu_emulator(self, qemu_emulator_path):
        """
        Set the qemu emulator in the specified path explicitly.
        """
        out = self.host_session.send_expect('ls %s' % qemu_emulator_path, '# ')
        if 'No such file or directory' in out:
            self.host_logger.error("No emulator [ %s ] on the DUT" %
                                   (qemu_emulator_path))
            return None
        out = self.host_session.send_expect(
            "[ -x %s ];echo $?" % (qemu_emulator_path), '# ')
        if out != '0':
            self.host_logger.error("Emulator [ %s ] " % qemu_emulator_path +
                                   "not executable on the DUT")
            return None
        self.qemu_emulator = qemu_emulator_path

    def add_vm_qemu(self, **options):
        """
        Options:
            path: absolute path for qemu emulator
        """
        if 'path' in options.keys():
            self.set_qemu_emulator(options['path'])
            # update emulator config
            devices = self.domain.find('devices')
            ET.SubElement(devices, 'emulator').text = self.qemu_emulator

    def add_vm_disk(self, **options):
        """
        Options:
            file: absolute path of disk image file
            type: image file formats
        """
        devices = self.domain.find('devices')
        disk = ET.SubElement(devices, 'disk', {
            'type': 'file',
            'device': 'disk'
        })

        if 'file' not in options:
            return False

        ET.SubElement(disk, 'source', {'file': options['file']})
        if 'type' not in options:
            disk_type = 'raw'
        else:
            disk_type = options['type']

        ET.SubElement(disk, 'driver', {'name': 'qemu', 'type': disk_type})

        ET.SubElement(disk, 'target', {
            'dev': 'vd%c' % self.diskindex,
            'bus': 'virtio'
        })

        self.diskindex = chr(ord(self.diskindex) + 1)

    def add_vm_login(self, **options):
        """
        options:
            user: login username of virtual machine
            password: login password of virtual machine
        """
        if 'user' in options.keys():
            user = options['user']
            self.username = user

        if 'password' in options.keys():
            password = options['password']
            self.password = password

    def get_vm_login(self):
        return (self.username, self.password)

    def __parse_pci(self, pci_address):
        pci_regex = r"([0-9a-fA-F]{1,2}):([0-9a-fA-F]{1,2})" + \
            ".([0-9a-fA-F]{1,2})"
        m = re.match(pci_regex, pci_address)
        if m is None:
            return None
        bus = m.group(1)
        slot = m.group(2)
        func = m.group(3)

        return (bus, slot, func)

    def add_vm_device(self, **options):
        """
        options:
            pf_idx: device index of pass-through device
            guestpci: assigned pci address in vm
        """
        devices = self.domain.find('devices')
        hostdevice = ET.SubElement(devices, 'hostdev', {
            'mode': 'subsystem',
            'type': 'pci',
            'managed': 'yes'
        })

        if 'pf_idx' not in options.keys():
            print utils.RED("Missing device index for device option!!!")
            return False

        pf = int(options['pf_idx'])
        if pf > len(self.host_dut.ports_info):
            print utils.RED("PF device index over size!!!")
            return False

        pci_addr = self.host_dut.ports_info[pf]['pci']

        pci = self.__parse_pci(pci_addr)
        if pci is None:
            return False
        bus, slot, func = pci

        source = ET.SubElement(hostdevice, 'source')
        ET.SubElement(
            source, 'address', {
                'domain': '0x0',
                'bus': '0x%s' % bus,
                'slot': '0x%s' % slot,
                'function': '0x%s' % func
            })
        if 'guestpci' in options.keys():
            pci = self.__parse_pci(options['guestpci'])
            if pci is None:
                return False
            bus, slot, func = pci
            ET.SubElement(
                hostdevice, 'address', {
                    'type': 'pci',
                    'domain': '0x0',
                    'bus': '0x%s' % bus,
                    'slot': '0x%s' % slot,
                    'function': '0x%s' % func
                })
            # save host and guest pci address mapping
            pci_map = {}
            pci_map['hostpci'] = pci_addr
            pci_map['guestpci'] = options['guestpci']
            self.pci_maps.append(pci_map)
        else:
            print utils.RED('Host device pass-through need guestpci option!!!')

    def add_vm_net(self, **options):
        """
        Options:
            default: create e1000 netdev and redirect ssh port
        """
        if 'type' in options.keys():
            if options['type'] == 'nic':
                self.__add_vm_net_nic(**options)

    def __add_vm_net_nic(self, **options):
        """
        type: nic
        opt_model: ["e1000" | "virtio" | "i82551" | ...]
                   Default is e1000.
        opt_addr: ''
            note: PCI cards only.
        """
        if 'opt_model' in options.keys():
            model = options['opt_model']
        else:
            model = 'e1000'

        if 'opt_hostfwd' in options.keys():
            port = self.virt_pool.alloc_port(self.vm_name)
            if port is None:
                return
            dut_ip = self.host_dut.crb['IP']
            self.vm_ip = '%s:%d' % (dut_ip, port)

        qemu = ET.SubElement(self.domain, 'qemu:commandline')
        ET.SubElement(qemu, 'qemu:arg', {'value': '-net'})
        if 'opt_addr' in options.keys():
            pci = self.__parse_pci(options['opt_addr'])
            if pci is None:
                return False
            bus, slot, func = pci
            ET.SubElement(qemu, 'qemu:arg',
                          {'value': 'nic,model=e1000,addr=0x%s' % slot})
        else:
            ET.SubElement(
                qemu, 'qemu:arg',
                {'value': 'nic,model=e1000,addr=0x%x' % self.pciindex})
            self.pciindex += 1

        if 'opt_hostfwd' in options.keys():
            ET.SubElement(qemu, 'qemu:arg', {'value': '-net'})
            ET.SubElement(
                qemu, 'qemu:arg',
                {'value': 'user,hostfwd='
                 'tcp:%s:%d-:22' % (dut_ip, port)})

    def add_vm_virtio_serial_channel(self, **options):
        """
        Options:
            path: virtio unix socket absolute path
            name: virtio serial name in vm
        """
        devices = self.domain.find('devices')
        channel = ET.SubElement(devices, 'channel', {'type': 'unix'})
        for opt in ['path', 'name']:
            if opt not in options.keys():
                print "invalid virtio serial channel setting"
                return

        ET.SubElement(channel, 'source', {
            'mode': 'bind',
            'path': options['path']
        })
        ET.SubElement(channel, 'target', {
            'type': 'virtio',
            'name': options['name']
        })
        ET.SubElement(
            channel, 'address', {
                'type': 'virtio-serial',
                'controller': '0',
                'bus': '0',
                'port': '%d' % self.pciindex
            })
        self.pciindex += 1

    def get_vm_ip(self):
        return self.vm_ip

    def get_pci_mappings(self):
        """
        Return guest and host pci devices mapping structure
        """
        return self.pci_maps

    def __control_session(self, command, *args):
        """
        Use the qemu guest agent service to control VM.
        Note:
            :command: there are these commands as below:
                       cat, fsfreeze, fstrim, halt, ifconfig, info,\
                       ping, powerdown, reboot, shutdown, suspend
            :args: give different args by the different commands.
        """
        if not self.qga_sock_path:
            self.host_logger.info(
                "No QGA service between host [ %s ] and guest [ %s ]" %
                (self.host_dut.Name, self.vm_name))
            return None

        cmd_head = '~/QMP/' + \
            "qemu-ga-client " + \
            "--address=%s %s" % \
            (self.qga_sock_path, command)

        cmd = cmd_head
        for arg in args:
            cmd = cmd_head + ' ' + str(arg)

        if command is "ping":
            out = self.host_session.send_expect(cmd, '# ', int(args[0]))
        else:
            out = self.host_session.send_expect(cmd, '# ')

        return out

    def _start_vm(self):
        xml_file = "/tmp/%s.xml" % self.vm_name
        try:
            os.remove(xml_file)
        except:
            pass
        self.root.write(xml_file)
        self.host_session.copy_file_to(xml_file)
        time.sleep(2)

        self.host_session.send_expect("virsh", "virsh #")
        self.host_session.send_expect("create /root/%s.xml" % self.vm_name,
                                      "virsh #")
        self.host_session.send_expect("quit", "# ")
        out = self.__control_session('ping', '120')

        if "Not responded" in out:
            raise StartVMFailedException("Not response in 120 seconds!!!")

        self.__wait_vmnet_ready()

    def __wait_vmnet_ready(self):
        """
        wait for 120 seconds for vm net ready
        10.0.2.* is the default ip address allocated by qemu
        """
        count = 20
        while count:
            out = self.__control_session('ifconfig')
            if "10.0.2" in out:
                return True
            time.sleep(6)
            count -= 1

        raise StartVMFailedException("Virtual machine control net not ready " +
                                     "in 120 seconds!!!")

    def stop(self):
        self.__control_session("shutdown")
        time.sleep(5)
def generatePluginInfo(SDK, usrSDKConfig, decompileDir):
    """the infomation about Plugin would configure here"""
    assetsDir = decompileDir + '/assets'
    if not os.path.exists(assetsDir):
        os.makedirs(assetsDir)
    PluginFile = assetsDir + '/supportPlugin.xml'
    targetTree = None
    targetRoot = None
    pluginLsNode = None
    if not os.path.exists(PluginFile):
        targetTree = ElementTree()
        targetRoot = Element('support')
        targetTree._setroot(targetRoot)
    else:
        targetTree = ET.parse(PluginFile)
        targetRoot = targetTree.getroot()
    for plugin in SDK['pluginLs']:
        type = plugin['typePlugin']
        typeTag = '<plugin>'
        if type == 0:
            typeTag = 'user_plugin'
            if not usrSDKConfig['type'] & 32:
                continue
        elif type == 1:
            typeTag = 'ads_plugin'
            if not usrSDKConfig['type'] & 16:
                continue
        elif type == 2:
            typeTag = 'iap_plugin'
            if not usrSDKConfig['type'] & 8:
                continue
        elif type == 3:
            typeTag = 'social_plugin'
            if not usrSDKConfig['type'] & 4:
                continue
        elif type == 4:
            typeTag = 'share_plugin'
            if not usrSDKConfig['type'] & 2:
                continue
        elif type == 5:
            typeTag = 'analytics_plugin'
            if not usrSDKConfig['type'] & 1:
                continue
        elif type == 6:
            typeTag = 'push_plugin'
            if not usrSDKConfig['type'] & 64:
                continue
        pluginName = plugin['name']
        if pluginName is None:
            file_operate.printf('pluginName error')
            error_operate.error(109)
            return 1
        pluginLsNode = targetRoot.find(typeTag)
        if pluginLsNode is not None:
            for plugin in pluginLsNode.getchildren():
                if plugin.text == pluginName:
                    pluginLsNode.remove(plugin)

        if pluginLsNode is None:
            pluginLsNode = SubElement(targetRoot, typeTag)
        paramNode = SubElement(pluginLsNode, 'param')
        paramNode.text = pluginName
        paramNode.set('name', SDK['SDKName'])

    targetTree.write(PluginFile, 'UTF-8')
    file_operate.printf('generate supportPlugin.xml success')
    return 0
Exemplo n.º 58
0
def write_bmk2(instrument, filename):
    samples = instrument.getAllSamples()

    import xml.etree.ElementTree as ET
    #<BM2 BPM="120.00000000" FileType="4" MemorySize="618344" ProductType="BMKS" SigDen="4" SigNum="4" VersionMajor="2" VersionMinor="5" VersionRevision="6">
    bm2Tag = ET.Element('BM2')
    bm2Tag.set("BMP","120.0")
    bm2Tag.set("FileType","4")
    bm2Tag.set("MemorySize","618344")
    bm2Tag.set("ProductType","BMKS")
    bm2Tag.set("SigDen", "4")
    bm2Tag.set("SigNum", "4")
    bm2Tag.set("VersionMajor", "2")
    bm2Tag.set("VersionMinor", "5")
    bm2Tag.set("VersionRevision", "6")

    #<KeyboardSampler DisplayName="multi" Name="inst" Order="0" Polyphony="5" PolyphonyMode="0" PresetPath="bmuser:/testMulti/multi/multi.bmk2">
    keyboardSamplerTag = ET.SubElement(bm2Tag, 'KeyboardSampler')
    keyboardSamplerTag.set("DisplayName", "multi")
    keyboardSamplerTag.set("Name", "inst")
    keyboardSamplerTag.set("Order", "0")
    keyboardSamplerTag.set("Polyphony", "5")
    keyboardSamplerTag.set("PolyphonyMode", "0")
    keyboardSamplerTag.set("PresetPath", "bmuser:/testMulti/multi/multi.bmk2")

    #<LinearAHDSR AHDSRAmount="1.00000000" AHDSRInvert="false" AttackAmplitude="0.00000000" AttackTime="0.00000000" DecayAmplitude="1.00000000" DecayTime="0.00000000" HoldTime="0.00000000" KillAfterRelease="true" ModDestScaleParamID="0" ModEnabled="true" ModFollowVoices="true" ModScaleRatio="0.00000000" ModUseKeyAsScale="false" ModUseVelocityAsScale="false" Name="ahdsr0" Order="0" ReleaseTime="0.50000000" SustainAmplitude="1.00000000" _AttackTime="73" _DecayTime="74" _ReleaseTime="76" _SustainAmplitude="75"/>
    LinearAHDSRTag1 = ET.SubElement(keyboardSamplerTag, 'LinearAHDSR')
    LinearAHDSRTag1.set("AHDSRAmount", "1.00000000")
    LinearAHDSRTag1.set("AHDSRInvert", "false")
    LinearAHDSRTag1.set("AttackAmplitude", "0.00000000")
    LinearAHDSRTag1.set("AttackTime", "0.00000000")
    LinearAHDSRTag1.set("DecayAmplitude", "1.00000000")
    LinearAHDSRTag1.set("DecayTime", "0.00000000")
    LinearAHDSRTag1.set("HoldTime", "0.00000000")
    LinearAHDSRTag1.set("KillAfterRelease", "true")
    LinearAHDSRTag1.set("ModDestScaleParamID", "0")
    LinearAHDSRTag1.set("ModEnabled", "true")
    LinearAHDSRTag1.set("ModFollowVoices", "true")
    LinearAHDSRTag1.set("ModScaleRatio", "0.00000000")
    LinearAHDSRTag1.set("ModUseKeyAsScale", "false")
    LinearAHDSRTag1.set("ModUseVelocityAsScale", "false")
    LinearAHDSRTag1.set("Name", "ahdsr0")
    LinearAHDSRTag1.set("Order", "0")
    LinearAHDSRTag1.set("ReleaseTime", "0.50000000")
    LinearAHDSRTag1.set("SustainAmplitude", "1.00000000")
    LinearAHDSRTag1.set("_AttackTime", "73")
    LinearAHDSRTag1.set("_DecayTime", "74")
    LinearAHDSRTag1.set("_ReleaseTime", "76")
    LinearAHDSRTag1.set("_SustainAmplitude", "75")

    #<LinearAHDSR AHDSRAmount="1.00000000" AHDSRInvert="false" AttackAmplitude="0.00000000" AttackTime="3.00000000" DecayAmplitude="1.00000000" DecayTime="3.00000000" HoldTime="0.00000000" KillAfterRelease="false" ModDestScaleParamID="0" ModEnabled="false" ModFollowVoices="true" ModScaleRatio="0.00000000" ModUseKeyAsScale="false" ModUseVelocityAsScale="false" Name="ahdsr1" Order="0" ReleaseTime="3.00000000" SustainAmplitude="1.00000000" _AttackTime="77" _DecayTime="78" _ReleaseTime="80" _SustainAmplitude="79"/>
    LinearAHDSRTag2 = ET.SubElement(keyboardSamplerTag, 'LinearAHDSR')
    LinearAHDSRTag2.set("AHDSRAmount", "1.00000000")
    LinearAHDSRTag2.set("AHDSRInvert", "false")
    LinearAHDSRTag2.set("AttackAmplitude", "0.00000000")
    LinearAHDSRTag2.set("AttackTime", "3.00000000")
    LinearAHDSRTag2.set("DecayAmplitude", "1.00000000")
    LinearAHDSRTag2.set("DecayTime", "3.00000000")
    LinearAHDSRTag2.set("HoldTime", "0.00000000")
    LinearAHDSRTag2.set("KillAfterRelease", "false")
    LinearAHDSRTag2.set("ModDestScaleParamID", "0")
    LinearAHDSRTag2.set("ModEnabled", "false")
    LinearAHDSRTag2.set("ModFollowVoices", "true")
    LinearAHDSRTag2.set("ModScaleRatio", "0.00000000")
    LinearAHDSRTag2.set("ModUseKeyAsScale", "false")
    LinearAHDSRTag2.set("ModUseVelocityAsScale", "false")
    LinearAHDSRTag2.set("Name", "ahdsr1")
    LinearAHDSRTag2.set("Order", "0")
    LinearAHDSRTag2.set("ReleaseTime", "3.00000000")
    LinearAHDSRTag2.set("SustainAmplitude", "1.00000000")
    LinearAHDSRTag2.set("_AttackTime", "77")
    LinearAHDSRTag2.set("_DecayTime", "78")
    LinearAHDSRTag2.set("_ReleaseTime", "80")
    LinearAHDSRTag2.set("_SustainAmplitude", "79")

    #<SimpleFilter DisplayName="FILTER" InsertEffectBypass="******" InsertEffectVoiceProcessing="true" Name="filter" Order="0" ProcessorOutputBusName="Render" SFilterCutoffFrequency="3000.00000000" SFilterFilteringMode="0" SFilterKeyFreqAmount="0.00000000" SFilterResonance="0.25000000" _SFilterCutoffFrequency="70" _SFilterKeyFreqAmount="72" _SFilterResonance="71"/>
    SimpleFilterTag = ET.SubElement(keyboardSamplerTag, 'SimpleFilter')
    SimpleFilterTag.set("DisplayName", "FILTER")
    SimpleFilterTag.set("InsertEffectBypass", "true")
    SimpleFilterTag.set("InsertEffectVoiceProcessing", "true")
    SimpleFilterTag.set("Name", "filter")
    SimpleFilterTag.set("Order", "0")
    SimpleFilterTag.set("ProcessorOutputBusName", "Render")
    SimpleFilterTag.set("SFilterCutoffFrequency", "3000.00000000")
    SimpleFilterTag.set("SFilterFilteringMode", "0")
    SimpleFilterTag.set("SFilterKeyFreqAmount", "0.00000000")
    SimpleFilterTag.set("SFilterResonance", "0.25000000")
    SimpleFilterTag.set("_SFilterCutoffFrequency", "70")
    SimpleFilterTag.set("_SFilterKeyFreqAmount", "72")
    SimpleFilterTag.set("_SFilterResonance", "71")

    sampleId = -1
    layerManager = Bmk2LayerManager(instrument)
    for sample in samples:
        sampleId = sampleId + 1
        #<Keygroup KeygroupBaseKey="63" KeygroupExclusiveGroup="0" KeygroupHighKey="35" KeygroupHighVelocity="100" KeygroupLayer="0" KeygroupLoopToggleMode="false" KeygroupLoopToggleSync="9" KeygroupLowKey="0" KeygroupLowVelocity="0" KeygroupMute="false" KeygroupOneShot="false" KeygroupPan="0.00000000" KeygroupPolyphony="0" KeygroupVolume="1.00000000" Name="kg0" Order="0" ProcessorOutputBusName="IN" ProcessorOutputBusPath="../../">
        KeygroupTag = ET.SubElement(keyboardSamplerTag, 'Keygroup')
        KeygroupTag.set("KeygroupBaseKey", str(sample.basekey))
        KeygroupTag.set("KeygroupExclusiveGroup", "0")
        KeygroupTag.set("KeygroupHighKey", str(sample.maxkey))
        KeygroupTag.set("KeygroupHighVelocity", str(sample.maxvel))
        #find layer for sample
        layerId = layerManager.getLayerId(sample)

        KeygroupTag.set("KeygroupLayer", str(layerId))
        KeygroupTag.set("KeygroupLoopToggleMode", "false")
        KeygroupTag.set("KeygroupLoopToggleSync", "9")
        KeygroupTag.set("KeygroupLowKey", str(sample.minkey))
        KeygroupTag.set("KeygroupLowVelocity", str(sample.minvel))
        KeygroupTag.set("KeygroupMute", "false")
        KeygroupTag.set("KeygroupOneShot", "false")
        KeygroupTag.set("KeygroupPolyphony", "0")
        KeygroupTag.set("KeygroupPan", str(sample.pan))

        # volume dst = (-inf, 6] ; orig = dB
        from math import pow
        volume = pow(10.0, (float(sample.volume)/20.0) )
        KeygroupTag.set("KeygroupVolume", str(volume))
        KeygroupTag.set("Name", "kg"+str(sampleId))
        KeygroupTag.set("Order", "0")
        KeygroupTag.set("ProcessorOutputBusName", "IN")
        KeygroupTag.set("ProcessorOutputBusPath", "../../")
        
        #<ModulationConnection ConnectionDestinationParamID="KeygroupVolume" ConnectionSourceModulationPath="../../ahdsr0" Name="ahdsr0con" Order="0"/>
        ModulationConnectionTag1 = ET.SubElement(KeygroupTag, 'ModulationConnection')
        ModulationConnectionTag1.set("ConnectionDestinationParamID", "KeygroupVolume")
        ModulationConnectionTag1.set("ConnectionSourceModulationPath", "../../ahdsr0")
        ModulationConnectionTag1.set("Name", "ahdsr0con")
        ModulationConnectionTag1.set("Order", "0")

        #<ModulationConnection ConnectionDestinationObjectPath="../../filter" ConnectionDestinationParamID="SFilterCutoffFrequency" ConnectionSourceModulationPath="../../ahdsr1" Name="ahdsr1con" Order="0"/>
        ModulationConnectionTag2 = ET.SubElement(KeygroupTag, 'ModulationConnection')
        ModulationConnectionTag2.set("ConnectionDestinationObjectPath", "../../filter")
        ModulationConnectionTag2.set("ConnectionDestinationParamID", "SFilterCutoffFrequency")
        ModulationConnectionTag2.set("ConnectionSourceModulationPath", "../../ahdsr1")
        ModulationConnectionTag2.set("Name", "ahdsr1con")
        ModulationConnectionTag2.set("Order", "0")

        #<ModulationConnection ConnectionDestinationParamID="KeygroupVolume" ConnectionSourceModulationPath="../../lfo0" Name="lfo0con" Order="0"/>
        ModulationConnectionTag3 = ET.SubElement(KeygroupTag, 'ModulationConnection')
        ModulationConnectionTag3.set("ConnectionDestinationParamID", "KeygroupVolume")
        ModulationConnectionTag3.set("ConnectionSourceModulationPath", "../../lfo0")
        ModulationConnectionTag3.set("Name", "lfo0con")
        ModulationConnectionTag3.set("Order", "0")

        #<ModulationConnection ConnectionDestinationObjectPath="../../filter" ConnectionDestinationParamID="SFilterResonance" ConnectionSourceModulationPath="../../lfo1" Name="lfo1con" Order="0"/>
        ModulationConnectionTag4 = ET.SubElement(KeygroupTag, 'ModulationConnection')
        ModulationConnectionTag4.set("ConnectionDestinationObjectPath", "../../filter")
        ModulationConnectionTag4.set("ConnectionDestinationParamID", "SFilterResonance")
        ModulationConnectionTag4.set("ConnectionSourceModulationPath", "../../lfo1")
        ModulationConnectionTag4.set("Name", "lfo1con")
        ModulationConnectionTag4.set("Order", "0")

        #<SampleRenderer LoopEnd="21566" LoopStart="0" LoopType="0" Name="renderer" Order="0" RendererPitch="1.00000000" Reverse="false" SampleEnd="21566" SampleID="0" SamplePath="multi_samples/s2.wav" SampleStart="0" Streaming="false" Stretch="1.00000000" UseSampleInfo="true" Warp="false">
        SampleRendererTag = ET.SubElement(KeygroupTag, 'SampleRenderer')
        SampleRendererTag.set("LoopEnd", str(sample.loopEnd))
        SampleRendererTag.set("LoopStart", str(sample.loopStart))
        SampleRendererTag.set("LoopType", str(sample.loopType))
        SampleRendererTag.set("Name", "renderer")
        SampleRendererTag.set("Order", "0")
        SampleRendererTag.set("RendererPitch", "1.00000000")
        SampleRendererTag.set("Reverse", "false")
        SampleRendererTag.set("SampleEnd", str(sample.nsamples))
        SampleRendererTag.set("SampleID", "0")
        SampleRendererTag.set("SamplePath", sample.path)
        SampleRendererTag.set("SampleStart", "0")
        SampleRendererTag.set("Streaming", "false")
        SampleRendererTag.set("Stretch", "1.00000000")
        SampleRendererTag.set("UseSampleInfo", "true")
        SampleRendererTag.set("Warp", "false")

        #<PitchModulation ModDestScaleParamID="0" ModEnabled="true" ModFollowVoices="false" ModScaleRatio="0.00000000" ModUseKeyAsScale="false" ModUseVelocityAsScale="false" Name="pitchmod" Order="0" PitchModTune="0.00000000" PitchModeFineTune="0.00000000"/>
        PitchModulationTag = ET.SubElement(SampleRendererTag, 'PitchModulation')
        PitchModulationTag.set("ModDestScaleParamID", "0")
        PitchModulationTag.set("ModEnabled", "true")
        PitchModulationTag.set("ModFollowVoices", "false")
        PitchModulationTag.set("ModScaleRatio", "0.00000000")
        PitchModulationTag.set("ModUseKeyAsScale", "false")
        PitchModulationTag.set("ModUseVelocityAsScale", "false")
        PitchModulationTag.set("Name", "pitchmod")
        PitchModulationTag.set("Order", "0")
        PitchModulationTag.set("PitchModTune", "0.00000000")
        PitchModulationTag.set("PitchModeFineTune", "0.00000000")

        #<ModulationConnection ConnectionDestinationParamID="RendererPitch" ConnectionSourceModulationPath="../pitchmod" Name="pitchmodconnection" Order="0"/>
        SampleRendererModulationConnectionTag1 = ET.SubElement(SampleRendererTag, 'ModulationConnection')
        SampleRendererModulationConnectionTag1.set("ConnectionDestinationParamID", "RendererPitch")
        SampleRendererModulationConnectionTag1.set("ConnectionSourceModulationPath", "../pitchmod")
        SampleRendererModulationConnectionTag1.set("Name", "pitchmodconnection")
        SampleRendererModulationConnectionTag1.set("Order", "0")

        #<ModulationConnection ConnectionDestinationParamID="RendererPitch" ConnectionSourceModulationPath="../../../portamento" Name="portamentoconnection" Order="0"/>
        SampleRendererModulationConnectionTag2 = ET.SubElement(SampleRendererTag, 'ModulationConnection')
        SampleRendererModulationConnectionTag2.set("ConnectionDestinationParamID", "RendererPitch")
        SampleRendererModulationConnectionTag2.set("ConnectionSourceModulationPath", "../../../portamento")
        SampleRendererModulationConnectionTag2.set("Name", "portamentoconnection")
        SampleRendererModulationConnectionTag2.set("Order", "0")


    
    #<Layer LayerID="0" LayerName="LAYER 1" Name="layer0" Order="0"/>
    #<Layer LayerID="1" LayerName="LAYER 2" Name="layer1" Order="0"/>
    #...
    for id in range(layerManager.numLayers):
        LayerTag = ET.SubElement(keyboardSamplerTag, 'Layer')
        LayerTag.set("LayerID",str(id))
        LayerTag.set("LayerName","LAYER "+str(id))
        LayerTag.set("Name","layer"+str(id))
        LayerTag.set("Order","0")
    
    #<LFO LFOAmpOrigin="0.20000000" LFOAmplitude="0.80000001" LFORate="0.05000000" LFOSyncRate="33" LFOType="0" ModDestScaleParamID="0" ModEnabled="false" ModFollowVoices="true" ModScaleRatio="0.00000000" ModUseKeyAsScale="false" ModUseVelocityAsScale="false" Name="lfo0" Order="0" _LFOAmpOrigin="82" _LFOAmplitude="81" _LFORate="83"/>
    LFOTag1 = ET.SubElement(keyboardSamplerTag, 'LFO')
    LFOTag1.set("LFOAmpOrigin", "0.20000000")
    LFOTag1.set("LFOAmplitude", "0.80000001")
    LFOTag1.set("LFORate", "0.05000000")
    LFOTag1.set("LFOSyncRate", "33")
    LFOTag1.set("LFOType", "0")
    LFOTag1.set("ModDestScaleParamID", "0")
    LFOTag1.set("ModEnabled", "false")
    LFOTag1.set("ModFollowVoices", "true")
    LFOTag1.set("ModScaleRatio", "0.00000000")
    LFOTag1.set("ModUseKeyAsScale", "false")
    LFOTag1.set("ModUseVelocityAsScale", "false")
    LFOTag1.set("Name", "lfo0")
    LFOTag1.set("Order", "0")
    LFOTag1.set("_LFOAmpOrigin", "82")
    LFOTag1.set("_LFOAmplitude", "81")
    LFOTag1.set("_LFORate", "83")

    #<LFO LFOAmpOrigin="0.50000000" LFOAmplitude="0.50000000" LFORate="0.00200000" LFOSyncRate="33" LFOType="3" ModDestScaleParamID="0" ModEnabled="false" ModFollowVoices="true" ModScaleRatio="0.00000000" ModUseKeyAsScale="false" ModUseVelocityAsScale="false" Name="lfo1" Order="0" _LFOAmpOrigin="85" _LFOAmplitude="84" _LFORate="86"/>
    LFOTag2 = ET.SubElement(keyboardSamplerTag, 'LFO')
    LFOTag2.set("LFOAmpOrigin", "0.20000000")
    LFOTag2.set("LFOAmplitude", "0.80000001")
    LFOTag2.set("LFORate", "0.05000000")
    LFOTag2.set("LFOSyncRate", "33")
    LFOTag2.set("LFOType", "3")
    LFOTag2.set("ModDestScaleParamID", "0")
    LFOTag2.set("ModEnabled", "false")
    LFOTag2.set("ModFollowVoices", "true")
    LFOTag2.set("ModScaleRatio", "0.00000000")
    LFOTag2.set("ModUseKeyAsScale", "false")
    LFOTag2.set("ModUseVelocityAsScale", "false")
    LFOTag2.set("Name", "lfo1")
    LFOTag2.set("Order", "0")
    LFOTag2.set("_LFOAmpOrigin", "82")
    LFOTag2.set("_LFOAmplitude", "81")
    LFOTag2.set("_LFORate", "83")
    #<Portamento ModDestScaleParamID="0" ModEnabled="true" ModFollowVoices="true" ModScaleRatio="0.00000000" ModUseKeyAsScale="false" ModUseVelocityAsScale="false" Name="portamento" Order="0" PortamentoGlideTime="0.00000000" _PortamentoGlideTime="5"/>
    PortamentoTag = ET.SubElement(keyboardSamplerTag, 'Portamento')
    PortamentoTag.set("ModDestScaleParamID", "0")
    PortamentoTag.set("ModEnabled", "true")
    PortamentoTag.set("ModFollowVoices", "true")
    PortamentoTag.set("ModScaleRatio", "0.00000000")
    PortamentoTag.set("ModUseKeyAsScale", "false")
    PortamentoTag.set("ModUseVelocityAsScale", "false")
    PortamentoTag.set("Name", "portamento")
    PortamentoTag.set("Order", "0")
    PortamentoTag.set("PortamentoGlideTime", "0.00000000")
    PortamentoTag.set("_PortamentoGlideTime", "5")

    from xml.etree.ElementTree import ElementTree
    tree = ElementTree()
    tree._setroot(bm2Tag)
    tree.write(filename, encoding='utf-8', xml_declaration=True)
Exemplo n.º 59
0
 # Warmup on a dummy image
 im = 128 * np.ones((300, 500, 3), dtype=np.uint8)
 # for i /storage2/tiannuodata/work/projdata/baiwei/baiweiproj2/analysis/xml_shape/in xrange(2):
 #     _, _= im_detect(net, im)
 in_dir = "/storage2/tiannuodata/work/projdata/baiwei/baiweiproj2//JPEGImages/"
 out_xmldir = "/storage2/tiannuodata/work/projdata/baiwei/testdata/result_xml//"
 file_list = os.listdir(in_dir)
 for file_name in file_list:
     if os.path.splitext(file_name)[1] == '.xml':
         continue
     basename_2 = os.path.splitext(file_name)[0]
     im_name = in_dir + "/" + file_name
     baseInfo, objects_2 = demo(net, im_name, num_class, save_ff)
     four_root = ElementTree()
     A1 = create_node('annotation', {}, "")
     four_root._setroot(A1)
     B1 = create_node('foder', {}, "2")
     B2 = create_node('filename', {}, basename_2)
     B3 = create_node('path', {}, "2")
     A1.append(B1)
     A1.append(B2)
     A1.append(B3)
     B4 = create_node('source', {}, "")
     A1.append(B4)
     C1 = create_node('database', {}, "Unknown")
     B4.append(C1)
     B5 = create_node('size', {}, "")
     SubElement(B5,
                "width").text = baseInfo['size/width']  #str(im.shape[1])
     SubElement(B5,
                "height").text = baseInfo['size/height']  #str(im.shape[0])
Exemplo n.º 60
0
        if not e.tail or not e.tail.strip():
            e.tail = i
    else:
        if level and (not elem.tail or not elem.tail.strip()):
            elem.tail = i


for arg in args:
    print >> sys.stderr, 'extracting data from', arg
    book = xlrd.open_workbook(arg)

    xmlTree = ElementTree()
    stringTree = ElementTree()

    xmlTreeRoot = Element('StaticData')
    xmlTree._setroot(xmlTreeRoot)

    stringTreeRoot = Element('StaticData')
    stringTree._setroot(stringTreeRoot)

    SoilderData(book.sheets()[6], xmlTreeRoot, stringTreeRoot)
    PweaponData(book.sheets()[1], xmlTreeRoot, stringTreeRoot)
    SweaponData(book.sheets()[2], xmlTreeRoot, stringTreeRoot)
    HorseData(book.sheets()[3], xmlTreeRoot, stringTreeRoot)
    ShieldData(book.sheets()[4], xmlTreeRoot, stringTreeRoot)
    ArmorData(book.sheets()[5], xmlTreeRoot, stringTreeRoot)

    indent(xmlTreeRoot)
    indent(stringTreeRoot)
    xmlTree.write('data.xml')
    stringTree.write('string.xml', "utf-8")