本文整理汇总了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)
示例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
示例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'))
示例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
示例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'))
示例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'])
示例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 = []
示例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)
示例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
示例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)
示例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'))
示例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"))
示例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)
示例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')
示例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!"