def generateSinglePoT(folder, root):
    xmlfiles = []
    abspath = os.path.join(root, folder)
    if os.path.isdir(abspath):
        os.path.walk(abspath, get_xml_list, xmlfiles)
    else:
        return

    if xmlfiles:
        output = os.path.join(abspath, "locale")
        if not os.path.exists(output):
            os.mkdir(output)
        output = os.path.join(output, folder + ".pot")
        try:
            xml2po_main = Main(default_mode, "pot", output, xml_options)
            xml2po_main.current_mode = myDocbookXmlMode()
        except IOError:
            print("Error: cannot open aFile %s for writing." % (output))
            sys.exit(5)
        # print(xmlfiles)
        # print(">>>outout: %s ", output)
        xml2po_main.to_pot(xmlfiles)
def generateSinglePoT(folder, root):
    xmlfiles = []
    abspath = os.path.join(root, folder)
    if os.path.isdir(abspath):
        os.path.walk(abspath, get_xml_list, xmlfiles)
    else:
        return

    if len(xmlfiles) > 0:
        output = os.path.join(abspath, "locale")
        if not os.path.exists(output):
            os.mkdir(output)
        output = os.path.join(output, folder + ".pot")
        try:
            xml2po_main = Main(default_mode, "pot", output, xml_options)
            xml2po_main.current_mode = myDocbookXmlMode()
        except IOError:
            print("Error: cannot open aFile %s for writing." % (output))
            sys.exit(5)
        # print(xmlfiles)
        # print(">>>outout: %s ", output)
        xml2po_main.to_pot(xmlfiles)
def mergeSingleDocument(folder, language, root):
    xmlfiles = []
    outputfiles = []
    abspath = os.path.join(root, folder)
    if os.path.isdir(abspath):
        os.path.walk(abspath, get_xml_list, xmlfiles)
    else:
        return None

    if xmlfiles:
        popath = os.path.join(abspath, "locale", language + ".po")
        # generate MO file
        mofile_handler, mofile_tmppath = tempfile.mkstemp()
        os.close(mofile_handler)
        os.system("msgfmt -o %s %s" % (mofile_tmppath, popath))

        for aXML in xmlfiles:
            # (filename, ext) = os.path.splitext(os.path.basename(aXML))
            relpath = os.path.relpath(aXML, root)
            outputpath = os.path.join(os.path.curdir, "generated", language,
                                      relpath)
            try:
                xml2po_main = Main(default_mode, "merge", outputpath,
                                   xml_options)
                xml2po_main.current_mode = myDocbookXmlMode()
                xml2po_main.merge(mofile_tmppath, aXML)
                outputfiles.append(outputpath)
            except IOError:
                print("Error: cannot open aFile %s for writing.")
                sys.exit(5)
            except Exception:
                print("Exception happen")
        if mofile_tmppath:
            os.remove(mofile_tmppath)

    return outputfiles
def mergeSingleDocument(folder, language, root):
    xmlfiles = []
    outputfiles = []
    abspath = os.path.join(root, folder)
    if os.path.isdir(abspath):
        os.path.walk(abspath, get_xml_list, xmlfiles)
    else:
        return None

    if len(xmlfiles) > 0:
        popath = os.path.join(abspath, "locale", language + ".po")
        # generate MO file
        mofile_handler, mofile_tmppath = tempfile.mkstemp()
        os.close(mofile_handler)
        os.system("msgfmt -o %s %s" % (mofile_tmppath, popath))

        for aXML in xmlfiles:
            # (filename, ext) = os.path.splitext(os.path.basename(aXML))
            relpath = os.path.relpath(aXML, root)
            outputpath = os.path.join(os.path.curdir, "generated", language,
                                      relpath)
            try:
                xml2po_main = Main(default_mode, "merge", outputpath,
                                   xml_options)
                xml2po_main.current_mode = myDocbookXmlMode()
                xml2po_main.merge(mofile_tmppath, aXML)
                outputfiles.append(outputpath)
            except IOError:
                print("Error: cannot open aFile %s for writing.")
                sys.exit(5)
            except Exception:
                print("Exception happen")
        if mofile_tmppath:
            os.remove(mofile_tmppath)

    return outputfiles