Exemple #1
0
def convertToSingleFile(fileDir, targetDir):
    destDir = genDestDir(targetDir)

    for _, dirnames, _ in os.walk(fileDir):
        valuesDirs = [di for di in dirnames if di.startswith("values")]
        for dirname in valuesDirs:
            for _, _, filenames in os.walk(fileDir + '/' + dirname):
                xmlFiles = [fi for fi in filenames if fi.endswith(".xml")]
                for xmlfile in xmlFiles:
                    fileName = xmlfile.replace(".xml", "")
                    filePath = destDir + "/" + fileName + ".xls"
                    if not os.path.exists(filePath):
                        workbook = pyExcelerator.Workbook()
                        ws = workbook.add_sheet(fileName)
                        index = 0
                        for dirname in dirnames:
                            if index == 0:
                                ws.write(0, 0, 'keyName')
                            countryCode = getCountryCode(dirname)
                            ws.write(0, index + 1, countryCode)

                            path = fileDir + '/' + dirname + '/' + xmlfile
                            (keys, values) = XmlFileUtil.getKeysAndValues(path)
                            for x in range(len(keys)):
                                key = keys[x]
                                value = values[x]
                                if (index == 0):
                                    ws.write(x + 1, 0, key)
                                    ws.write(x + 1, 1, value)
                                else:
                                    ws.write(x + 1, index + 1, value)
                            index += 1
                        workbook.save(filePath)
    print "Convert %s successfully! you can see xls file in %s" % (fileDir,
                                                                   destDir)
def convertToSingleFile(fileDir, targetDir):
    destDir = genDestDir(targetDir)

    for _, dirnames, _ in os.walk(fileDir):
        valuesDirs = [di for di in dirnames if di.startswith("values")]
        for dirname in valuesDirs:
            for _, _, filenames in os.walk(fileDir+'/'+dirname):
                xmlFiles = [fi for fi in filenames if fi.endswith(".xml")]
                for xmlfile in xmlFiles:
                    fileName = xmlfile.replace(".xml", "")
                    filePath = destDir + "/" + fileName + ".xls"
                    if not os.path.exists(filePath):
                        workbook = pyExcelerator.Workbook()
                        ws = workbook.add_sheet(fileName)
                        index = 0
                        for dirname in dirnames:
                            if index == 0:
                                ws.write(0, 0, 'keyName')
                            countryCode = getCountryCode(dirname)
                            ws.write(0, index+1, countryCode)

                            path = fileDir+'/'+dirname+'/' + xmlfile
                            (keys, values) = XmlFileUtil.getKeysAndValues(path)
                            for x in range(len(keys)):
                                key = keys[x]
                                value = values[x]
                                if (index == 0):
                                    ws.write(x+1, 0, key)
                                    ws.write(x+1, 1, value)
                                else:
                                    ws.write(x+1, index + 1, value)
                            index += 1
                        workbook.save(filePath)
    print "Convert %s successfully! you can see xls file in %s" % (
        fileDir, destDir)
Exemple #3
0
def convertToSingleFile(file_dir, target_dir):
    dest_dir = genDestDir(target_dir)
    default_key_values = {}

    for _, dir_names, _ in os.walk(file_dir):
        if "values" in dir_names:
            dir_names.remove("values")
            dir_names.insert(0, "values")
        values_dirs = [di for di in dir_names if di.startswith("values")]
        for dir_name in values_dirs:
            for _, _, filenames in os.walk(os.path.join(file_dir, dir_name)):
                xml_file = "strings.xml"
                file_name = xml_file.replace(".xml", "")
                file_path = os.path.join(dest_dir, file_name + ".xls")
                if not os.path.exists(file_path):
                    workbook = pyExcelerator.Workbook()
                    ws = workbook.add_sheet(file_name)
                    index = 0
                    for dir_name in dir_names:
                        path = os.path.join(file_dir, dir_name, xml_file)
                        if os.path.exists(path):
                            if index == 0:
                                ws.write(0, 0, 'keyName')
                            country_code = getCountryCode(dir_name)
                            ws.write(0, index + 1, country_code)
                            (keys, values,
                             keyValues) = XmlFileUtil.getKeysAndValues(path)
                            x = 0
                            if dir_name == "values":
                                default_key_values = keyValues
                            for key, value in default_key_values.items():
                                rel_value = keyValues[
                                    key] if key in keyValues else ""
                                if index == 0:
                                    ws.write(x + 1, 0, key)
                                    ws.write(x + 1, 1, rel_value)
                                else:
                                    ws.write(x + 1, index + 1, rel_value)
                                x += 1
                            index += 1
                    workbook.save(file_path)
    print "Convert %s successfully! you can see xls file in %s" % (file_dir,
                                                                   dest_dir)
Exemple #4
0
def convertToMultipleFiles(fileDir, targetDir):
    destDir = genDestDir(targetDir)

    for _, dirnames, _ in os.walk(fileDir):
        valuesDirs = [di for di in dirnames if di.startswith("values")]
        for dirname in valuesDirs:
            workbook = pyExcelerator.Workbook()
            for _, _, filenames in os.walk(fileDir + '/' + dirname):
                xmlFiles = [fi for fi in filenames if fi.endswith(".xml")]
                for xmlfile in xmlFiles:
                    ws = workbook.add_sheet(xmlfile)
                    path = fileDir + '/' + dirname + '/' + xmlfile
                    (keys, values) = XmlFileUtil.getKeysAndValues(path)
                    for keyIndex in range(len(keys)):
                        key = keys[keyIndex]
                        value = values[keyIndex]
                        ws.write(keyIndex, 0, key)
                        ws.write(keyIndex, 1, value)
            filePath = destDir + "/" + getCountryCode(dirname) + ".xls"
            workbook.save(filePath)
    print "Convert %s successfully! you can see xls file in %s" % (fileDir,
                                                                   destDir)
def convertToMultipleFiles(fileDir, targetDir):
    destDir = genDestDir(targetDir)

    for _, dirnames, _ in os.walk(fileDir):
        valuesDirs = [di for di in dirnames if di.startswith("values")]
        for dirname in valuesDirs:
            workbook = pyExcelerator.Workbook()
            for _, _, filenames in os.walk(fileDir+'/'+dirname):
                xmlFiles = [fi for fi in filenames if fi.endswith(".xml")]
                for xmlfile in xmlFiles:
                    ws = workbook.add_sheet(xmlfile)
                    path = fileDir+'/'+dirname+'/' + xmlfile
                    (keys, values) = XmlFileUtil.getKeysAndValues(path)
                    for keyIndex in range(len(keys)):
                        key = keys[keyIndex]
                        value = values[keyIndex]
                        ws.write(keyIndex, 0, key)
                        ws.write(keyIndex, 1, value)
            filePath = destDir + "/" + getCountryCode(dirname) + ".xls"
            workbook.save(filePath)
    print "Convert %s successfully! you can see xls file in %s" % (
        fileDir, destDir)