示例#1
0
def main():
    """
    脚本主函数
    :return:
    """
    from tools.usage import usage_help
    s_ops = "h"
    s_opexplain = ["help"]
    l_ops = ["up-pylib=", "latest", "up-conf-sample", "add-user"]
    l_opexplain = [
        "<value>, Update the python third-party packages.\n\t\t"
        "Version update of the default installation requirements file)\n\t\t"
        "Optional parameters: 'input-venv' or 'no-input-venv'",
        "Update to the latest package",
        "Update the system configuration sample file. Automatically remove sensitive data (eg passwords)\n\t\t"
        "Mainly the following configuration files:\n\t\t"
        "{}/apps/config_sample.py; {}/apps/db_config_sample.py".format(
            PROJECT_PATH, PROJECT_PATH),
        "Add a Root user, generally only used to initialize the user when the site was just created"
    ]

    action = [
        "Update python lib: python {} --up-pylib no-input-venv".format(
            __file__),
        "Update config sample: python {} --up-conf-sample".format(__file__),
        "Add user: python {} --add-user".format(__file__)
    ]

    opts, args = getopt.getopt(sys.argv[1:], s_ops, l_ops)
    is_up_pylib = False
    input_venv_path = False
    latest = False
    for op, value in opts:
        if op == "--up-pylib":
            from apps.core.utils.sys_tool import update_pylib
            if value == "input-venv":
                input_venv_path = True
            is_up_pylib = True

        elif op == "--latest":
            latest = True

        elif op == "--up-conf-sample":
            from apps.core.utils.sys_tool import copy_config_to_sample
            copy_config_to_sample()

        elif op == "--add-user":
            from start import mdbs
            from apps.core.utils.sys_tool import add_user
            add_user(mdbs=mdbs)

        elif op == "-h" or op == "--help":

            usage_help(s_ops, s_opexplain, l_ops, l_opexplain, action=action)

    if is_up_pylib:
        update_pylib(input_venv_path=input_venv_path, latest=latest)
    if not opts:

        usage_help(s_ops, s_opexplain, l_ops, l_opexplain, action=action)
示例#2
0
def main():
    """
    脚本主函数
    :return:
    """
    from tools.usage import usage_help
    s_ops = "h"
    s_opexplain = ["help"]
    l_ops = ["up-pylib", "venv-path=", "latest", "up-conf-sample", "add-user"]
    l_opexplain = [
        "<value>, Update python package (dependent package)",
        "<value>, up-pylib input venv path: <venv-path> or null",
        "up-pylib Update to the latest version",
        "Update to the latest package",
        "Update the system configuration sample file. Automatically remove sensitive data (eg passwords)\n"
        "Mainly the following configuration files:\n"
        " {}/apps/config_sample.py;\n"
        " {}/apps/db_config_sample.py".format(PROJECT_PATH, PROJECT_PATH),
        "Add a Root user, generally only used to initialize the user when the site was just created"
    ]

    action = [
        "Update python lib: python {} --up-pylib".format(__file__),
        "Update config sample: python {} --up-conf-sample".format(__file__),
        "Add user: python {} --add-user".format(__file__)
    ]

    opts, args = getopt.getopt(sys.argv[1:], s_ops, l_ops)
    is_up_pylib = False
    venv_path = "default"
    latest = False
    for op, value in opts:
        if op == "--up-pylib":
            is_up_pylib = True
        elif op == "--venv-path":
            venv_path = value
        elif op == "--latest":
            latest = True

        elif op == "--up-conf-sample":
            from apps.core.utils.sys_tool import copy_config_to_sample
            copy_config_to_sample()

        elif op == "--add-user":
            from start import mdbs
            from apps.core.utils.sys_tool import add_user
            add_user(mdbs=mdbs)

        elif op == "-h" or op == "--help":
            usage_help(s_ops, s_opexplain, l_ops, l_opexplain, action=action)

    if is_up_pylib:
        from apps.core.utils.sys_tool import update_pylib
        update_pylib(venv_path=venv_path, latest=latest)
    if not opts:
        usage_help(s_ops, s_opexplain, l_ops, l_opexplain, action=action)
示例#3
0
def main():
    '''
    脚本主函数
    :return:
    '''
    from tools.usage import usage_help
    s_ops = "h"
    s_opexplain = ["help"]
    l_ops = ["up-pylib=", "up-conf-sample", "add-user"]
    l_opexplain = [
        "<value>, Check the python package needed to update the system.\n\t\t"
        "Optional parameters: 'input-venv' or 'no-input-venv'",
        "Update the system configuration sample file. Automatically remove sensitive data (eg passwords)\n\t\t"
        "Mainly the following configuration files:\n\t\t"
        "{}/apps/config_sample.py; {}/apps/db_config_sample.py".format(
            PROJECT_PATH, PROJECT_PATH),
        "Add a Root user, generally only used to initialize the user when the site was just created"
    ]

    action = [
        "Update python lib: python {} --up-pylib no-input-venv".format(
            __file__),
        "Update config sample: python {} --up-conf-sample".format(__file__),
        "Add user: python {} --add-user".format(__file__)
    ]

    opts, args = getopt.getopt(sys.argv[1:], s_ops, l_ops)
    for op, value in opts:
        if op == "--up-pylib":
            from apps.core.utils.sys_tool import update_pylib
            if value == "input-venv":
                update_pylib()
            else:
                update_pylib(input_venv_path=False)

        elif op == "--up-conf-sample":
            from apps.core.utils.sys_tool import copy_config_to_sample
            copy_config_to_sample()

        elif op == "--add-user":
            from start import mdb_user
            from apps.core.utils.sys_tool import add_user
            add_user(mdb_user)

        elif op == "-h" or op == "--help":

            usage_help(s_ops, s_opexplain, l_ops, l_opexplain, action=action)
    if not opts:

        usage_help(s_ops, s_opexplain, l_ops, l_opexplain, action=action)
示例#4
0
    def main(self):

        s_ops = "h"
        l_ops = ["path="]
        s_opexplain = ["help"]
        l_opexplain = ["<path>"]
        opts, args = getopt.getopt(sys.argv[1:], s_ops, l_ops)
        if not opts:
            usage_help(s_ops, s_opexplain, l_ops, l_opexplain)

        self.path = None
        for op, value in opts:
            if op == "--path":
                self.path = value

        self.repair()
示例#5
0
    def main(self):

        self.cfg_path = "{}/babel.cfg".format(current_path)
        self.extract_path = "{}/apps".format(project_path)
        s_ops = "hqo:"
        l_ops = [
            "init", "update", "compile", "cfg=", "ext=", "lan=", "all-lan"
        ]
        s_opexplain = [
            "help",
            "quiet:A small amount of output",
            "<output directory>, Output directory.Optional: admin_pages, python-pg, theme",
        ]
        l_opexplain = [
            "init translation(初始化翻译)",
            "Update: Extract and update(用于更新,提取最新的需翻译文本)",
            "compile(更新并翻译后,需要发布翻译)",
            "<cfg file path>, The default:{}(只提取html,js文件)."
            "\nOptional: {}/babel_py.cfg(只提取py文件)".format(
                self.cfg_path, current_path), "<Extract path>, \nSuch as: {}"
            "\n{}/theme".format(self.extract_path, self.extract_path),
            "<language>, Default:zh_Hans_CN  Optional: zh_CN,zh_Hans_CN,en_GB",
            "View all languages"
        ]

        action = [
            "init, [--init --ext <path> -o <dir name> --lan en_US]",
            "update, [--update --ext <path> -o <dir name> --cfg <cfg file path>]",
            "compile, [--compile -o <dir name>]", """Eg:
Ext theme text:
--update --ext apps/themes -o theme --lan en_US\n
Ext admin pages text:
--update --ext apps/admin_pages -o admin_pages --lan en_US\n
Ext python:
--update --ext apps -o python-pg --cfg tools/translations/babel_py.cfg --lan zh_Hans_CN\n
Theme Tr compile:
--compile -o theme\n
Admin pages Tr compile:
--compile -o admin_pages\n
Python Tr compile:
--compile -o python-pg
"""
        ]

        opts, args = getopt.getopt(sys.argv[1:], s_ops, l_ops)
        func = None
        self.save_path = None
        self.quiet = ""
        self.lan = "zh_Hans_CN"

        if not opts:
            usage_help(s_ops, s_opexplain, l_ops, l_opexplain, action=action)
        for op, value in opts:
            if op == "-q":
                self.quiet = "-q"
            elif op == "--lan":
                self.lan = value.strip()
            elif op == "--all-lan":
                os.system("pybabel --list-locales")
                sys.exit()

            elif op == "--cfg":
                self.cfg_path = value.strip()

            elif op == "--ext":
                self.extract_path = value.rstrip("/")

            elif op == "-o":
                self.save_path = "{}/apps/translations/{}".format(
                    project_path, value.strip("/"))

            elif op == "--init":
                func = self.init_tr

            elif op == "--update":
                func = self.update_tr

            elif op == "--compile":
                func = self.compile_tr

            elif op == "-h" or op == "--help":
                usage_help(s_ops,
                           s_opexplain,
                           l_ops,
                           l_opexplain,
                           action=action)

        print(self.save_path)
        if not os.path.exists(self.save_path):
            os.makedirs(self.save_path)

        func()
示例#6
0
    def main(self):

        self.cfg_path = "{}/babel.cfg".format(current_path)
        self.extract_path = "{}/apps".format(project_path)
        s_ops = "hq"
        l_ops = [
            "init", "update", "compile", "cfg=", "extract=", "output=", "lan=",
            "all-lan"
        ]
        s_opexplain = ["help", "quiet:A small amount of output"]
        l_opexplain = [
            "init translation(初始化翻译)",
            "update: extract and update(用于更新,提取最新的需翻译文本)",
            "compile(更新并翻译后,需要发布翻译)",
            "<cfg file path>, The default:{}(只提取html,js文件).\n\t\tOptional: {}/babel_py.cfg(只提取py文件)"
            .format(self.cfg_path, current_path),
            "<Translation extract directory>, Such as: {}".format(
                self.extract_path),
            "<output directory>, Output directory.\n\t\tSuch as:{}/translations/python-pg"
            "\n\t\t\t{}/translations/template".format(self.extract_path,
                                                      self.extract_path),
            "<language>, Such as: zh_CN,zh_Hans_CN,en_GB", "View all languages"
        ]

        action = [
            "init, [--init --extract <path> --output <path> --lan en_US]",
            "update, [--update --extract <path> --output <path> --cfg <cfg file path>]",
            "compile, [--compile --output <path>"
        ]

        opts, args = getopt.getopt(sys.argv[1:], s_ops, l_ops)
        func = None
        self.save_path = None
        self.quiet = ""
        self.lan = "zh_Hans_CN"

        if not opts:
            usage_help(s_ops, s_opexplain, l_ops, l_opexplain, action=action)
        for op, value in opts:
            if op == "-q":
                self.quiet = "-q"
            elif op == "--lan":
                self.lan = value.strip()
            elif op == "--all-lan":
                os.system("pybabel --list-locales")
                sys.exit()

            elif op == "--cfg":
                self.cfg_path = value.strip()

            elif op == "--extract":
                self.extract_path = value.rstrip("/")

            elif op == "--output":
                self.save_path = value.rstrip("/")

            elif op == "--init":
                func = self.init_tr

            elif op == "--update":
                func = self.update_tr

            elif op == "--compile":
                func = self.compile_tr

            elif op == "-h" or op == "--help":
                usage_help(s_ops,
                           s_opexplain,
                           l_ops,
                           l_opexplain,
                           action=action)

        if not os.path.exists(self.save_path):
            os.makedirs(self.save_path)

        func()
示例#7
0
    def main(self):

        self.cfg_path = "{}/babel.cfg".format(current_path)
        self.extract_path = "{}/apps".format(project_path)
        s_ops = "hq"
        l_ops = [
            "init", "update", "compile", "cfg=", "extract=", "output=", "lan=",
            "all-lan", "get-msgid=", "re-msgstr="
        ]
        s_opexplain = ["help", "quiet:A small amount of output"]
        l_opexplain = [
            "init translation", "update: extract and update", "compile",
            "<cfg file path>, The default:{}.\n\t\tOptional: {}/babel_py.cfg".
            format(self.cfg_path, current_path),
            "<Translation extract directory>,The default: {}".format(
                self.extract_path),
            "<output directory>, Output directory.\n\t\tSuce as:{}/translations/template"
            .format(self.extract_path),
            "<language>, Such as: en_US, zh_Hans_CN", "View all languages",
            "<path> Get 'msgid' in po file",
            "<file:Translation completed msgid text> Fill the 'msgstr' in the po file with the translated text"
            "\n                    (此参数指定的文件的格式和行号必须和--get-msgid导出的文件格式和行号一模一样)"
        ]

        action = [
            "init, [--init --extract <path> --output <path:Such as:xxx/transations/theme> --lan en_US]",
            "update, [--update --extract <path> --output <path:Such as:xxx/transations/theme>]",
            "compile, [--compile --output <path:Such as:xxx/transations/theme>]",
            "get-msgid [--get-msgid <path:Such as:xxx/transations/theme> --lan <value>]",
            "re-msgstr [--re-msgstr <path:xxx/xxx.txt> --output <path> --lan <value>]"
        ]

        opts, args = getopt.getopt(sys.argv[1:], s_ops, l_ops)
        func = None
        self.save_path = None
        self.quiet = ""
        self.lan = "zh_Hans_CN"
        self.msgid_tred_file_path = ""
        if not opts:
            usage_help(s_ops, s_opexplain, l_ops, l_opexplain, action=action)
        for op, value in opts:
            if op == "-q":
                self.quiet = "-q"
            elif op == "--lan":
                self.lan = value.strip()
            elif op == "--all-lan":
                os.system("pybabel --list-locales")
                sys.exit()

            elif op == "--cfg":
                self.cfg_path = value.strip()

            elif op == "--extract":
                self.extract_path = value.rstrip("/")

            elif op == "--output":
                self.save_path = value.rstrip("/")

            elif op == "--init":
                func = self.init_tr

            elif op == "--update":
                func = self.update_tr

            elif op == "--compile":
                func = self.compile_tr

            elif op == "--get-msgid":
                self.save_path = value.rstrip("/")
                func = self.get_msgid

            elif op == "--re-msgstr":
                self.msgid_tred_file_path = value.rstrip("/")
                func = self.replace_msgstr

            elif op == "-h" or op == "--help":
                usage_help(s_ops,
                           s_opexplain,
                           l_ops,
                           l_opexplain,
                           action=action)

        if not os.path.exists(self.save_path):
            os.makedirs(self.save_path)

        func()