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


Python ConfigFactory.parse_file方法代码示例

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


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

示例1: convert

# 需要导入模块: from pyhocon import ConfigFactory [as 别名]
# 或者: from pyhocon.ConfigFactory import parse_file [as 别名]
    def convert(input_file=None, output_file=None, format='json'):
        """Convert to json, properties or yaml

        :param format: json, properties or yaml
        :type format: basestring
        :return: json, properties or yaml string representation
        """

        if input_file is None:
            content = sys.stdin.read()
            config = ConfigFactory.parse_string(content)
        else:
            config = ConfigFactory.parse_file(input_file)

        if format.lower() == 'json':
            res = HOCONConverter.to_json(config)
        elif format.lower() == 'properties':
            res = HOCONConverter.to_properties(config)
        elif format.lower() == 'yaml':
            res = HOCONConverter.to_yaml(config)
        else:
            raise Exception("Format must be 'json', 'properties' or 'yaml'")

        if output_file is None:
            print(res)
        else:
            with open(output_file, "w") as fd:
                fd.write(res)
开发者ID:peoplepattern,项目名称:pyhocon,代码行数:30,代码来源:tool.py

示例2: get_custom_settings

# 需要导入模块: from pyhocon import ConfigFactory [as 别名]
# 或者: from pyhocon.ConfigFactory import parse_file [as 别名]
def get_custom_settings(args):
    custom_settings_file = vars(args).get('custom_settings_file')
    if custom_settings_file and os.path.exists(custom_settings_file):
        print('Loading custom settings {}'.format(custom_settings_file))
        return ConfigFactory.parse_file(custom_settings_file)
    else:
        return None
开发者ID:pengyangtuo,项目名称:conductr-cli,代码行数:9,代码来源:conduct_main.py

示例3: gen_conf

# 需要导入模块: from pyhocon import ConfigFactory [as 别名]
# 或者: from pyhocon.ConfigFactory import parse_file [as 别名]
def gen_conf(scale, app_name, query):
    conf = ConfigFactory.parse_file('../conf/application.conf')
    conf.put("all.query-num", query)
    conf.put("all.data-scale", scale)
    conf.put("all.app-suffix", app_name)

    with open('../conf/application-run.conf', 'w') as f:
       f.write(HOCONConverter.convert(conf, 'hocon'))
开发者ID:chapter09,项目名称:tpch-spark,代码行数:10,代码来源:run-q1-22.py

示例4: _load_custom_config

# 需要导入模块: from pyhocon import ConfigFactory [as 别名]
# 或者: from pyhocon.ConfigFactory import parse_file [as 别名]
def _load_custom_config(run_config):
    """Load custom configuration input HOCON file for cromwell.
    """
    from pyhocon import ConfigFactory, HOCONConverter, ConfigTree
    conf = ConfigFactory.parse_file(run_config)
    out = {}
    if "database" in conf:
        out["database"] = HOCONConverter.to_hocon(ConfigTree({"database": conf.get_config("database")}))
    return out
开发者ID:chapmanb,项目名称:bcbio-nextgen,代码行数:11,代码来源:hpc.py

示例5: gen_conf

# 需要导入模块: from pyhocon import ConfigFactory [as 别名]
# 或者: from pyhocon.ConfigFactory import parse_file [as 别名]
def gen_conf(t1, t2, scale, app_name, query):
    conf = ConfigFactory.parse_file('../conf/application.conf')
    conf.put("Q23.table-list", [t1, t2])
    conf.put("all.data-scale", scale)
    conf.put("all.hdfs", 'hdfs://%s:8020/'%HDFS)
    conf.put("all.app-suffix", app_name)
    conf.put("Q23.query", QUERYS[query])

    with open('../conf/application-run.conf', 'w') as f:
       f.write(HOCONConverter.convert(conf, 'hocon'))
开发者ID:chapter09,项目名称:tpch-spark,代码行数:12,代码来源:run.py

示例6: main

# 需要导入模块: from pyhocon import ConfigFactory [as 别名]
# 或者: from pyhocon.ConfigFactory import parse_file [as 别名]
def main():
    parent_parser = argparse.ArgumentParser(add_help=False)
    parent_parser.add_argument('-d', '--database', help='database', required=True, action='store')
    parent_parser.add_argument('-s', '--schema', help='schema', required=False, action='store', default=None)
    parent_parser.add_argument('-t', '--table', help='table filter (using % as a wildcard)', required=False,
                               action='store')
    parent_parser.add_argument('-dr', '--dry-run', dest='dry_run', help='dry run', required=False, action='store_true')

    argparser = argparse.ArgumentParser(description='export')
    subparsers = argparser.add_subparsers(help='sub-command help', dest='subparser_name')
    ddl_parser = subparsers.add_parser('ddl', help='ddl', parents=[parent_parser])
    ddl_parser.add_argument('-e', '--export', dest='export_file', help='export', required=False, action='store')
    ddl_parser.add_argument('-i', '--import', dest='import_file', help='import', required=False)
    data_parser = subparsers.add_parser('data', help='data', parents=[parent_parser])
    data_parser.add_argument('-e', '--export', dest='export_file', help='export', required=False, action='store')
    data_parser.add_argument('-i', '--import', dest='import_file', help='import', required=False)
    subparsers.add_parser('list', help='list', parents=[parent_parser])

    args = argparser.parse_args()
    home_dir = os.environ['HOME']
    config_path = os.path.join(home_dir, '.catdb')
    if not os.path.exists(config_path):
        sys.stderr.write(
            'File {config_path} not found. Go to https://github.com/chimpler/catdb for more details\n'.format(
                config_path=config_path))
        sys.exit(1)

    config = ConfigFactory.parse_file(config_path)
    db_config = config['databases.' + args.database]

    db = DbManager.get_db(db_config['type'], db_config)
    if args.subparser_name == 'list':
        print '\n'.join(db.list_tables(args.table, args.schema))
    elif args.subparser_name == 'ddl':
        if args.export_file:
            ddl_str = json.dumps(db.get_ddl(args.table, args.schema), sort_keys=True,
                                 indent=config['ddl-format.indent'], separators=(',', ': '))
            with open_output_file(args.export_file) as fd:
                fd.write(ddl_str)
        elif args.import_file:
            with open_input_file(args.import_file) as fd:
                ddl = json.loads(fd.read())
                table_statement = db.create_database_statement(ddl, args.database, args.schema)
                if args.dry_run:
                    print table_statement
                else:
                    db.execute(table_statement)
    elif args.subparser_name == 'data':
        if args.export_file:
            db.export_to_file(args.export_file, args.table, args.schema, config['data-format.delimiter'],
                              config['data-format.null'])

        elif args.import_file:
            db.import_from_file(args.import_fileport_file, args.table, args.schema, config['data-format.delimiter'],
                                config['data-format.null'])
开发者ID:chimpler,项目名称:catdb,代码行数:57,代码来源:main.py

示例7: __init__

# 需要导入模块: from pyhocon import ConfigFactory [as 别名]
# 或者: from pyhocon.ConfigFactory import parse_file [as 别名]
 def __init__(self, routers=None, **kwargs):
     self.extensions = {}
     self.kwargs = kwargs
     default_config_file = os.path.join(os.path.dirname(os.path.abspath(sys.argv[0])), 'application.conf')
     config_file = self.kwargs.pop('config', default_config_file)
     if os.path.exists(config_file):
         self.config = ConfigFactory.parse_file(config_file)
     else:
         self.config = ConfigTree()
     if routers is None:
         routers = []
     self.routers = routers
     self.filters = []
开发者ID:simple2source,项目名称:magEx,代码行数:15,代码来源:__init__.py

示例8: __init__

# 需要导入模块: from pyhocon import ConfigFactory [as 别名]
# 或者: from pyhocon.ConfigFactory import parse_file [as 别名]
    def __init__(self, args):
        name_conf_file = "./config/%s.conf" % args[1]
        conf = ConfigFactory.parse_file(name_conf_file)
        kafka_servers = conf.get('scraper.kafka.servers')
        self.kafka = KafkaListing(kafka_servers)
        self.producer = self.kafka.producer()
        redis_conf = conf.get('scraper.redis')
        self.visited_pages = redis.StrictRedis(host=redis_conf['host'], port=redis_conf['port'],
                                               db=redis_conf['db'])

        job_conf = conf.get('scraper.job')
        self.timeout = int(job_conf['timeout'])
        self.job_name = job_conf['name']
        self.mode = job_conf['mode']
        print('starting job %s' % job_conf)
开发者ID:fabiofumarola,项目名称:scraper,代码行数:17,代码来源:main.py

示例9: load_config

# 需要导入模块: from pyhocon import ConfigFactory [as 别名]
# 或者: from pyhocon.ConfigFactory import parse_file [as 别名]
def load_config(config_file, fallback_config_files):
    """
    Load configuration from a HOCON configuration file, with an optional fallback chain

    @param config_file:           the primary configuration file
    @param fallback_config_files: an optional list of fallback configuration files

    @rtype:                       ConfigTree
    @return:                      configuration
    """

    config = ConfigFactory.parse_file(config_file)

    if fallback_config_files:
        for fallback_config_file in fallback_config_files:
            if isfile(fallback_config_file):
                config = config.with_fallback(fallback_config_file)
            else:
                print 'Warn: "%s" not found or not a file' % fallback_config_file

    return config
开发者ID:bdclark,项目名称:director-scripts,代码行数:23,代码来源:setup-default.py

示例10: convert_from_file

# 需要导入模块: from pyhocon import ConfigFactory [as 别名]
# 或者: from pyhocon.ConfigFactory import parse_file [as 别名]
    def convert_from_file(cls, input_file=None, output_file=None, output_format='json', indent=2, compact=False):
        """Convert to json, properties or yaml

        :param input_file: input file, if not specified stdin
        :param output_file: output file, if not specified stdout
        :param output_format: json, properties or yaml
        :return: json, properties or yaml string representation
        """

        if input_file is None:
            content = sys.stdin.read()
            config = ConfigFactory.parse_string(content)
        else:
            config = ConfigFactory.parse_file(input_file)

        res = cls.convert(config, output_format, indent, compact)
        if output_file is None:
            print(res)
        else:
            with open(output_file, "w") as fd:
                fd.write(res)
开发者ID:chunyang-wen,项目名称:pyhocon,代码行数:23,代码来源:converter.py

示例11: get_test_config

# 需要导入模块: from pyhocon import ConfigFactory [as 别名]
# 或者: from pyhocon.ConfigFactory import parse_file [as 别名]
def get_test_config():
    return ConfigFactory.parse_file(pkg_resources.resource_filename('tests', 'test_data/test.conf'))
开发者ID:pchandar,项目名称:irtk,代码行数:4,代码来源:helpers.py

示例12: str

# 需要导入模块: from pyhocon import ConfigFactory [as 别名]
# 或者: from pyhocon.ConfigFactory import parse_file [as 别名]
    conn.request("GET", url + "/api/search/usage?notUsedSince=" + str(date) + "&repos=" + repo, headers=headers)

    res = conn.getresponse()

    data = res.read()

    json_object = json.loads(data)
    
    if 'results' in json_object:    
        for value in json_object["results"]:
            if not_exclude(value["uri"], exclude):
                updated = value["uri"].replace("api/storage/", "")
                substr = "/artifactory/"
                pos = updated.index(substr)
                path = updated[pos:len(updated)]
                print path
                clean_path(conn, path, headers)


config = ConfigFactory.parse_file("cleaner.conf")

artifactory_url = urlparse(config.get("artifactory.url"))
port = artifactory_url.port if artifactory_url.port else 80 if artifactory_url.scheme == 'http' else 443

conn = httplib.HTTPConnection(artifactory_url.hostname, port) if artifactory_url.scheme == 'http' else httplib.HTTPSConnection(artifactory_url.hostname, port)

user_pass = b64encode(config.get("artifactory.auth")).decode("ascii")
headers = { 'Authorization' : 'Basic %s' %  user_pass }

for value in config.get("repos"):
    outdated(conn, artifactory_url.path, headers, value.get('name'), value.get_int('interval'), config.get("exclude"))
开发者ID:destitutus,项目名称:artifactory-cleaner,代码行数:33,代码来源:cleaner.py

示例13: print

# 需要导入模块: from pyhocon import ConfigFactory [as 别名]
# 或者: from pyhocon.ConfigFactory import parse_file [as 别名]
            print(directory_name + " was not a directory. Skipping.")
            continue

        directory_path = os.path.join(opts.template_directory, directory_name)
        template_path = os.path.join(directory_path, "template.json")
        config_path = os.path.join(directory_path, "template.conf")
        if not os.path.isfile(template_path):
            print("%s is not a template directory (template file is missing)" % directory_path)
            continue

        if not os.path.isfile(config_path):
            print("%s is not a template directory (config file is missing)" % directory_path)
            continue

        template = open(template_path).read()
        config = ConfigFactory.parse_file(config_path)
        if "parameters" not in config:
            config["parameters"] = {}

        template_variables = get_template_variables(template)
        complete_parameters = update_parameters(config["parameters"], template_variables,
                                                template_path, opts.parameter_type)
        parameters_changed = False
        if config["parameters"] != complete_parameters:
            parameters_changed = True
            config["parameters"] = complete_parameters

        template_without_dashes, parameters_without_dashes = convert_dashes_to_underscores(template,
                                                                                           config["parameters"],
                                                                                           template_path)
开发者ID:FRosner,项目名称:cluster-broccoli,代码行数:32,代码来源:templates-0.7.0-to-0.8.0.py

示例14: prepareAndImportConf

# 需要导入模块: from pyhocon import ConfigFactory [as 别名]
# 或者: from pyhocon.ConfigFactory import parse_file [as 别名]
def prepareAndImportConf(options):
    logging.info('Parsing base config ...')

    conf = ConfigFactory.parse_file(DEFAULT_BASE_CONF_NAME)

    logging.info('Parsing base config ... Successful')

    logging.info('Assigning parameters ...')

    name = options.env
    region = options.region
    subscriptionId = options.subId
    tenantId = options.tenantId
    clientId = options.clientId
    clientSecret = options.clientSecret

    username = options.username
    keyFileName = DEFAULT_BASE_DIR + "/" + username + "/" + options.keyFileName
    generateKeyToFile(keyFileName, username)

    networkSecurityGroupResourceGroup = options.networkSecurityGroupResourceGroup
    networkSecurityGroup = options.networkSecurityGroup
    virtualNetworkResourceGroup = options.virtualNetworkResourceGroup
    virtualNetwork = options.virtualNetwork
    subnetName = options.subnetName
    computeResourceGroup = options.computeResourceGroup
    hostFqdnSuffix = options.hostFqdnSuffix

    dbHostOrIP = options.dbHostOrIP
    dbUsername = options.dbUsername
    dbPassword = options.dbPassword

    masterType = options.masterType.upper()
    workerType = options.workerType.upper()
    edgeType = options.edgeType.upper()

    dirUsername = options.dirUsername
    dirPassword = options.dirPassword

    logging.info('Assigning parameters ... Successful')

    logging.info('Modifying config ...')

    conf.put('name', name)
    conf.put('provider.region', region)
    conf.put('provider.subscriptionId', subscriptionId)
    conf.put('provider.tenantId', tenantId)
    conf.put('provider.clientId', clientId)
    conf.put('provider.clientSecret', clientSecret)

    conf.put('ssh.username', username)
    conf.put('ssh.privateKey', keyFileName)

    setInstanceParameters(conf, 'instances.master', masterType, networkSecurityGroupResourceGroup,
                          networkSecurityGroup,
                          virtualNetworkResourceGroup, virtualNetwork, subnetName,
                          computeResourceGroup, hostFqdnSuffix)
    setInstanceParameters(conf, 'instances.worker', workerType, networkSecurityGroupResourceGroup,
                          networkSecurityGroup,
                          virtualNetworkResourceGroup, virtualNetwork, subnetName,
                          computeResourceGroup, hostFqdnSuffix)
    setInstanceParameters(conf, 'instances.edge', edgeType, networkSecurityGroupResourceGroup,
                          networkSecurityGroup,
                          virtualNetworkResourceGroup, virtualNetwork, subnetName,
                          computeResourceGroup, hostFqdnSuffix)
    setInstanceParameters(conf, 'cloudera-manager.instance', edgeType,
                          networkSecurityGroupResourceGroup, networkSecurityGroup,
                          virtualNetworkResourceGroup, virtualNetwork, subnetName,
                          computeResourceGroup, hostFqdnSuffix)
    setInstanceParameters(conf, 'cluster.masters.instance', masterType,
                          networkSecurityGroupResourceGroup, networkSecurityGroup,
                          virtualNetworkResourceGroup, virtualNetwork, subnetName,
                          computeResourceGroup, hostFqdnSuffix)
    setInstanceParameters(conf, 'cluster.workers.instance', masterType,
                          networkSecurityGroupResourceGroup, networkSecurityGroup,
                          virtualNetworkResourceGroup, virtualNetwork, subnetName,
                          computeResourceGroup, hostFqdnSuffix)

    conf.put('databaseServers.mysqlprod1.host', dbHostOrIP)
    conf.put('databaseServers.mysqlprod1.user', dbUsername)
    conf.put('databaseServers.mysqlprod1.password', dbPassword)

    logging.info('Modifying config ... Successful')

    confLocation = DEFAULT_BASE_DIR + "/" + username + "/" + DEFAULT_CONF_NAME

    logging.info('Writing modified config to %s ...' % confLocation)

    with open(confLocation, "w") as text_file:
        text_file.write(tool.HOCONConverter.to_hocon(conf))

    logging.info('Writing modified config to %s ... Successful' % confLocation)

    logging.info('Importing config to Cloudera Director server ...')

    command = "python setup-default.py --admin-username '%s' --admin-password '%s' '%s'" % (
        dirUsername, dirPassword, confLocation)
    execAndLog(command)

    logging.info('Importing config to Cloudera Director server ... Successful')
开发者ID:AbelHu,项目名称:azure-quickstart-templates,代码行数:102,代码来源:prepare-director-conf.py

示例15: get_args

# 需要导入模块: from pyhocon import ConfigFactory [as 别名]
# 或者: from pyhocon.ConfigFactory import parse_file [as 别名]
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from pyhocon import ConfigFactory
import argparse
import os
import subprocess

def get_args():
  parser = argparse.ArgumentParser(description='Find controller.')   
  parser.add_argument("-c" , "--conf", dest="conf_path", help="get controller from the config file")
  return parser.parse_args()

def start(host, port, log_dir):
  if not os.path.exists(log_dir):
    os.makedirs(log_dir)  
  cmd = 'nohup sbt "runMain psrs.Controller --host {0} --port {1}" > {2}/controller_{0}_{1}.log 2>&1 &'.format(host, port, log_dir)
  subprocess.Popen(cmd, shell=True) 

if __name__ == '__main__':
  args = get_args()
  if args.conf_path is not None:
    conf = ConfigFactory.parse_file(args.conf_path)
    host = conf['akka.remote.netty.tcp.hostname'] 
    port = conf['akka.remote.netty.tcp.port'] 
    log_dir = conf['psrs.log-dir'] 
    start(host, port, log_dir)
  else:
    print "error: application.conf is not supplied!"
开发者ID:chlin501,项目名称:psrs,代码行数:32,代码来源:start-controller.py


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