コード例 #1
0
def convertFromSingleForm(options, fileDir, targetDir):
    for _, _, filenames in os.walk(fileDir):
        xlsFilenames = [fi for fi in filenames if fi.endswith(".xls")]
        for file in xlsFilenames:
            xlsFileUtil = XlsFileUtil(fileDir + "/" + file)
            table = xlsFileUtil.getTableByIndex(0)
            firstRow = table.row_values(0)
            keys = table.col_values(0)
            del keys[0]

            for index in range(len(firstRow)):
                if index <= 0:
                    continue
                languageName = firstRow[index]
                values = table.col_values(index)
                del values[0]

                if languageName == "zh-Hans":
                    languageName = "zh-rCN"
                elif languageName == "zh-Hant":
                    languageName = "zh-rTW"
                else:
                    match = re.match(r"^([a-z]{2})-([A-Z]{2})$", languageName)
                    if match:
                        languageName = match.group(1) + "-r" + match.group(2)

                path = targetDir + "/values-" + languageName + "/"
                if languageName == 'en':
                    path = targetDir + "/values/"
                filename = "strings.xml"
                XmlFileUtil.writeToFile(keys, values, path, filename,
                                        options.additional)
    print "Convert %s successfully! you can xml files in %s" % (fileDir,
                                                                targetDir)
コード例 #2
0
def convertFromSingleForm(options, fileDir, targetDir):
    for _, _, filenames in os.walk(fileDir):
        xlsFilenames = [fi for fi in filenames if fi.endswith(".xls")]
        for file in xlsFilenames:
            xlsFileUtil = XlsFileUtil(fileDir+"/"+file)
            table = xlsFileUtil.getTableByIndex(0)
            firstRow = table.row_values(0)
            keys = table.col_values(0)
            del keys[0]

            for index in range(len(firstRow)):
                if index <= 0:
                    continue
                languageName = firstRow[index]
                values = table.col_values(index)
                del values[0]

                if languageName == "zh-Hans":
                    languageName = "zh-rCN"

                path = targetDir + "/values-"+languageName+"/"
                if languageName == 'en':
                    path = targetDir + "/values/"
                filename = file.replace(".xls", ".xml")
                XmlFileUtil.writeToFile(
                    keys, values, path, filename, options.additional)
    print "Convert %s successfully! you can xml files in %s" % (
        fileDir, targetDir)
コード例 #3
0
def convertFromSingleForm(options, fileDir, targetDir):
    for _, _, filenames in os.walk(fileDir):
        xlsFilenames = [fi for fi in filenames if fi.endswith(".xls")]
        for file in xlsFilenames:
            xlsFileUtil = XlsFileUtil(fileDir + "/" + file)
            table = xlsFileUtil.getTableByIndex(0)
            firstRow = table.row_values(0)
            keys = table.col_values(0)
            del keys[0]

            for index in range(len(firstRow)):
                if index <= 0:
                    continue
                languageName = firstRow[index]
                values = table.col_values(index)
                del values[0]

                if languageName == "zh-Hans":
                    languageName = "zh-rCN"

                path = targetDir + "/values-" + languageName + "/"
                if languageName == 'en':
                    path = targetDir + "/values/"
                filename = file.replace(".xls", ".xml")
                XmlFileUtil.writeToFile(keys, values, path, filename,
                                        options.additional)
    print "Convert %s successfully! you can xml files in %s" % (fileDir,
                                                                targetDir)
コード例 #4
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)
コード例 #5
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)
コード例 #6
0
def startConvert(options):
    fileDir = options.fileDir

    if fileDir is None:
        Log.error("strings files directory can not be empty! try -h for help.")
        return

    if options.targetDir is None:
        Log.error("target files directory can not be empty! try -h for help.")
        return

    targetDir = options.targetDir + "/strings-files-to-xml_" + \
        time.strftime("%Y%m%d_%H%M%S")

    for _, _, filenames in os.walk(fileDir):
        stringsFilenames = [fi for fi in filenames if fi.endswith(".strings")]
        for filename in stringsFilenames:
            path = fileDir+"/"+filename
            (keys, values) = StringsFileUtil.getKeysAndValues(path)
            XmlFileUtil.writeToFile(keys, values, targetDir,
                                    filename.replace(".strings", ".xml"), options.additional)

    Log.info("Convert successfully! you can see xml files in %s" % (targetDir))
コード例 #7
0
def convertFromMultipleForm(options, fileDir, targetDir):
    for _, _, filenames in os.walk(fileDir):
        xlsFilenames = [fi for fi in filenames if fi.endswith(".xls")]
        for file in xlsFilenames:
            xlsFileUtil = XlsFileUtil(fileDir+"/"+file)

            languageName = file.replace(".xls", "")
            if languageName == "zh-Hans":
                languageName = "zh-rCN"
            path = targetDir + "/values-"+languageName+"/"
            if languageName == 'en':
                path = targetDir + "/values/"
            if not os.path.exists(path):
                os.makedirs(path)

            for table in xlsFileUtil.getAllTables():
                keys = table.col_values(0)
                values = table.col_values(1)
                filename = table.name.replace(".strings", ".xml")

                XmlFileUtil.writeToFile(
                    keys, values, path, filename, options.additional)
    print "Convert %s successfully! you can xml files in %s" % (
        fileDir, targetDir)
コード例 #8
0
def startConvert(options):
    fileDir = options.fileDir

    if fileDir is None:
        Log.error("strings files directory can not be empty! try -h for help.")
        return

    if options.targetDir is None:
        Log.error("target files directory can not be empty! try -h for help.")
        return

    targetDir = options.targetDir + "/strings-files-to-xml_" + \
        time.strftime("%Y%m%d_%H%M%S")

    for _, _, filenames in os.walk(fileDir):
        stringsFilenames = [fi for fi in filenames if fi.endswith(".strings")]
        for filename in stringsFilenames:
            path = fileDir + "/" + filename
            (keys, values) = StringsFileUtil.getKeysAndValues(path)
            XmlFileUtil.writeToFile(keys, values, targetDir,
                                    filename.replace(".strings", ".xml"),
                                    options.additional)

    Log.info("Convert successfully! you can see xml files in %s" % (targetDir))
コード例 #9
0
def convertFromMultipleForm(options, fileDir, targetDir):
    for _, _, filenames in os.walk(fileDir):
        xlsFilenames = [fi for fi in filenames if fi.endswith(".xls")]
        for file in xlsFilenames:
            xlsFileUtil = XlsFileUtil(fileDir + "/" + file)

            languageName = file.replace(".xls", "")
            if languageName == "zh-Hans":
                languageName = "zh-rCN"
            path = targetDir + "/values-" + languageName + "/"
            if languageName == 'en':
                path = targetDir + "/values/"
            if not os.path.exists(path):
                os.makedirs(path)

            for table in xlsFileUtil.getAllTables():
                keys = table.col_values(0)
                values = table.col_values(1)
                filename = table.name.replace(".strings", ".xml")

                XmlFileUtil.writeToFile(keys, values, path, filename,
                                        options.additional)
    print "Convert %s successfully! you can xml files in %s" % (fileDir,
                                                                targetDir)
コード例 #10
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)
コード例 #11
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)
コード例 #12
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)