当前位置: 首页>>代码示例>>Python>>正文


Python OrderedRawConfigParser.add_section方法代码示例

本文整理汇总了Python中txclib.config.OrderedRawConfigParser.add_section方法的典型用法代码示例。如果您正苦于以下问题:Python OrderedRawConfigParser.add_section方法的具体用法?Python OrderedRawConfigParser.add_section怎么用?Python OrderedRawConfigParser.add_section使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在txclib.config.OrderedRawConfigParser的用法示例。


在下文中一共展示了OrderedRawConfigParser.add_section方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: cmd_init

# 需要导入模块: from txclib.config import OrderedRawConfigParser [as 别名]
# 或者: from txclib.config.OrderedRawConfigParser import add_section [as 别名]
def cmd_init(argv, path_to_tx):
    "Initialize a new transifex project."
    parser = init_parser()
    (options, args) = parser.parse_args(argv)
    if len(args) > 1:
        parser.error("Too many arguments were provided. Aborting...")
    if args:
        path_to_tx = args[0]
    else:
        path_to_tx = os.getcwd()

    if os.path.isdir(os.path.join(path_to_tx,".tx")):
        logger.info("tx: There is already a tx folder!")
        reinit = raw_input("Do you want to delete it and reinit the project? [y/N]: ")
        while (reinit != 'y' and reinit != 'Y' and reinit != 'N' and reinit != 'n' and reinit != ''):
            reinit = raw_input("Do you want to delete it and reinit the project? [y/N]: ")
        if not reinit or reinit in ['N', 'n', 'NO', 'no', 'No']:
            return
        # Clean the old settings
        # FIXME: take a backup
        else:
            rm_dir = os.path.join(path_to_tx, ".tx")
            shutil.rmtree(rm_dir)

    logger.info("Creating .tx folder...")
    os.mkdir(os.path.join(path_to_tx,".tx"))

    # Handle the credentials through transifexrc
    home = os.path.expanduser("~")
    txrc = os.path.join(home, ".transifexrc")
    config = OrderedRawConfigParser()

    default_transifex = "https://www.transifex.net"
    transifex_host = options.host or raw_input("Transifex instance [%s]: " % default_transifex)

    if not transifex_host:
        transifex_host = default_transifex
    if not transifex_host.startswith(('http://', 'https://')):
        transifex_host = 'https://' + transifex_host

    config_file = os.path.join(path_to_tx, ".tx", "config")
    if not os.path.exists(config_file):
        # The path to the config file (.tx/config)
        logger.info("Creating skeleton...")
        config = OrderedRawConfigParser()
        config.add_section('main')
        config.set('main', 'host', transifex_host)
        # Touch the file if it doesn't exist
        logger.info("Creating config file...")
        fh = open(config_file, 'w')
        config.write(fh)
        fh.close()

    prj = project.Project(path_to_tx)
    prj.getset_host_credentials(transifex_host, user=options.user,
        password=options.password)
    prj.save()
    logger.info("Done.")
开发者ID:transifex,项目名称:Transifex_Client_wui_interface,代码行数:60,代码来源:commands.py

示例2: cmd_init

# 需要导入模块: from txclib.config import OrderedRawConfigParser [as 别名]
# 或者: from txclib.config.OrderedRawConfigParser import add_section [as 别名]
def cmd_init(argv, path_to_tx):
    """Initialize a new Transifex project."""
    parser = init_parser()
    options = parser.parse_args(argv)
    path_to_tx = options.path_to_tx or os.getcwd()

    print(messages.init_intro)
    save = options.save
    # if we already have a config file and we are not told to override it
    # in the args we have to ask
    config_file = os.path.join(path_to_tx, ".tx", "config")
    if os.path.isfile(config_file):
        if not save:
            if options.no_interactive:
                parser.error("Project already initialized.")
            logger.info(messages.init_initialized)
            if not utils.confirm(messages.init_reinit):
                return
        os.remove(config_file)

    if not os.path.isdir(os.path.join(path_to_tx, ".tx")):
        logger.info("Creating .tx folder...")
        os.mkdir(os.path.join(path_to_tx, ".tx"))

    default_transifex = "https://www.transifex.com"
    transifex_host = options.host or default_transifex

    if not transifex_host.startswith(('http://', 'https://')):
        transifex_host = 'https://' + transifex_host

    if not os.path.exists(config_file):
        # Handle the credentials through transifexrc
        config = OrderedRawConfigParser()
        config.add_section('main')
        config.set('main', 'host', transifex_host)
        # Touch the file if it doesn't exist
        logger.info("Creating config file...")
        fh = open(config_file, 'w')
        config.write(fh)
        fh.close()

    if not options.skipsetup and not options.no_interactive:
        logger.info(messages.running_tx_set)
        cmd_config([], path_to_tx)
    else:
        prj = project.Project(path_to_tx)
        prj.getset_host_credentials(transifex_host, username=options.user,
                                    password=options.password,
                                    token=options.token, force=options.save,
                                    no_interactive=options.no_interactive)
        prj.save()
        logger.info("Done.")
开发者ID:transifex,项目名称:transifex-client,代码行数:54,代码来源:commands.py

示例3: cmd_init

# 需要导入模块: from txclib.config import OrderedRawConfigParser [as 别名]
# 或者: from txclib.config.OrderedRawConfigParser import add_section [as 别名]
def cmd_init(argv, path_to_tx):
    "Initialize a new transifex project."

    # Current working dir path
    usage="usage: %prog [tx_options] init <path>"
    description="This command initializes a new project for use with"\
        " transifex. It is recommended to execute this command in the"\
        " top level directory of your project so that you can include"\
        " all files under it in transifex. If no path is provided, the"\
        " current working dir will be used."
    parser = OptionParser(usage=usage, description=description)
    parser.add_option("--host", action="store", dest="host",
        default=None, help="Specify a default Transifex host.")
    parser.add_option("--user", action="store", dest="user",
        default=None, help="Specify username for Transifex server.")
    parser.add_option("--pass", action="store", dest="password",
        default=None, help="Specify password for Transifex server.")
    (options, args) = parser.parse_args(argv)

    if len(args) > 1:
        parser.error("Too many arguments were provided. Aborting...")

    if args:
        path_to_tx = args[0]
    else:
        path_to_tx = os.getcwd()

    if os.path.isdir(os.path.join(path_to_tx,".tx")):
        utils.MSG("tx: There is already a tx folder!")
        reinit = raw_input("Do you want to delete it and reinit the project? [y/N]: ")
        while (reinit != 'y' and reinit != 'Y' and reinit != 'N' and reinit != 'n' and reinit != ''):
            reinit = raw_input("Do you want to delete it and reinit the project? [y/N]: ")
        if not reinit or reinit in ['N', 'n', 'NO', 'no', 'No']:
            return
        # Clean the old settings
        # FIXME: take a backup
        else:
            rm_dir = os.path.join(path_to_tx, ".tx")
            shutil.rmtree(rm_dir)

    utils.MSG("Creating .tx folder...")
    os.mkdir(os.path.join(path_to_tx,".tx"))

    # Handle the credentials through transifexrc
    home = os.path.expanduser("~")
    txrc = os.path.join(home, ".transifexrc")
    config = OrderedRawConfigParser()

    default_transifex = "https://www.transifex.net"
    transifex_host = options.host or raw_input("Transifex instance [%s]: " % default_transifex)

    if not transifex_host:
        transifex_host = default_transifex
    if not transifex_host.startswith(('http://', 'https://')):
        transifex_host = 'https://' + transifex_host

    config_file = os.path.join(path_to_tx, ".tx", "config")
    if not os.path.exists(config_file):
        # The path to the config file (.tx/config)
        utils.MSG("Creating skeleton...")
        config = OrderedRawConfigParser()
        config.add_section('main')
        config.set('main', 'host', transifex_host)
        # Touch the file if it doesn't exist
        utils.MSG("Creating config file...")
        fh = open(config_file, 'w')
        config.write(fh)
        fh.close()

    prj = project.Project(path_to_tx)
    prj.getset_host_credentials(transifex_host, user=options.user,
        password=options.password)
    prj.save()

    utils.MSG("Done.")
开发者ID:tbarbugli,项目名称:transifex-client,代码行数:77,代码来源:commands.py


注:本文中的txclib.config.OrderedRawConfigParser.add_section方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。