本文整理汇总了Python中yaml.yaml_load函数的典型用法代码示例。如果您正苦于以下问题:Python yaml_load函数的具体用法?Python yaml_load怎么用?Python yaml_load使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了yaml_load函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: main
def main(args=None):
"""
Execute the main body of the script.
Parameters
----------
args : list, optional
Command-line arguments. If unspecified, `sys.argv[1:]` is used.
"""
parser = argparse.ArgumentParser(description='Load a YAML file without '
'performing any training.')
parser.add_argument('yaml_file', type=argparse.FileType('r'),
help='The YAML file to load.')
parser.add_argument('-N', '--no-instantiate',
action='store_const', default=False, const=True,
help='Only verify that the YAML parses correctly '
'but do not attempt to instantiate the objects. '
'This might be used as a quick sanity check if '
'checking a file that requires a GPU in an '
'environment that lacks one (e.g. a cluster '
'head node)')
args = parser.parse_args(args=args)
name = args.yaml_file.name
initialize()
if args.no_instantiate:
yaml_load(args.yaml_file)
print("Successfully parsed %s (but objects not instantiated)." % name)
else:
load(args.yaml_file)
print("Successfully parsed and loaded %s." % name)
开发者ID:123fengye741,项目名称:pylearn2,代码行数:30,代码来源:yaml_dryrun.py
示例2: create_form
def create_form(draft, rmap, opts):
if opts.label not in rmap['forms']:
raise FormNotFoundError(label=opts.label)
with open(rmap['forms'][opts.label]) as y:
spec = yaml_load(y)
with open_datasource(rmap, spec['source']) as db:
initial = []
if 'comments' in spec:
wrapped = map(comment_yaml, wrap_text(spec['comments'], 78))
initial.extend(wrapped)
initial.append("# new values")
initial.append("# ----------")
avails = dict(map(lambda x: (x['name'], parse_column_default(x)),
spec['columns']))
initial.extend(yaml_dump(avails).split('\n'))
try:
if opts.values:
reviewed = avails
reviewed.update(parse_opt_values(opts.values))
else:
_, yaml_str = edit(draft, opts, initial="\n".join(initial))
reviewed = yaml_load(yaml_str)
db.execute(text(spec['insert']), **reviewed)
return 0, "Record created successfully!"
except (YAMLParserError, YAMLScannerError) as e:
err = EditError('YAML Parsing Error: %s' % str(e))
err.original_exception = e
raise err
except sqlexc.StatementError as e:
err = EditError('SQL Statement Error: %s' % str(e))
err.original_exception = e
raise err
开发者ID:alkiller22,项目名称:deft,代码行数:34,代码来源:deft.py
示例3: override_installer
def override_installer(platforms, installer, spec):
from glob import glob
from yaml import load as yaml_load
from os.path import basename, isfile
from copy import deepcopy
default_yaml = path_join(spec, '_default.yaml')
if isfile(default_yaml):
yaml = yaml_load(file(default_yaml).read())
default = yaml.get('default', {})
map(lambda x: x in yaml and default.update(yaml[x]), platforms)
else:
default = {}
installer['_default'].update(default)
for filename in glob(path_join(spec, '[a-z0-9A-Z]*.yaml')):
name = basename(filename)[0:-len('.yaml')]
yaml = yaml_load(file(filename).read())
result = deepcopy(installer['_default'])
result.update(yaml.get('default', {}))
map(lambda x: x in yaml and result.update(yaml[x]), platforms)
if name in installer:
installer[name].update(result)
else:
installer[name] = result
return installer
开发者ID:jianingy,项目名称:campcraft,代码行数:29,代码来源:campcraft.py
示例4: __init__
def __init__(self, config_file, sleep_file, hosts):
self.name, _ = splitext(basename(config_file))
self.sleep_file = sleep_file
with open(config_file) as f:
watcher_data = yaml_load(f)
monitor_name = watcher_data['monitor']['use']
monitor_data = watcher_data['monitor']
monitor_config = path_join('conf/monitors', monitor_name) + '.yaml'
self.rules = watcher_data['notification']
"""
`confirm' examples (3 out of 5 errors means a real error):
> monitor:
> - confirm: [3, 5]
"""
span = monitor_data['where']['confirm'][1]
self.moving_states = defaultdict(lambda: deque(maxlen=span))
self.events = dict()
self.freq = monitor_data['where']['frequency']
self.confirm_round = monitor_data['where']['confirm'][0]
with open(monitor_config) as f:
command_data = yaml_load(f)['command']
self.command_data = command_data
self.monitor_data = monitor_data
self.monitor_config = monitor_config
self.hosts = hosts
self.workers = int(monitor_data['where']['workers'])
开发者ID:jianingy,项目名称:watchgang,代码行数:32,代码来源:libwatcher.py
示例5: config_from_yaml
def config_from_yaml(filepath=None, fileobj=None, silent=False, BANNED_SETTINGS=[], upper_only=False, parse_env=False, debug=False, **kwargs):
"""
Usage:
>>> from StringIO import StringIO
>>> fileobj = StringIO('DEBUG: true')
>>> config = config_from_yaml(fileobj=fileobj)
>>> config.get('DEBUG')
True
#>>> os.getenv('TEST_HOSTNAME') == 'MYTEST'
#True
#>>> fileobj = StringIO('HOSTNAME: ENV_TEST_HOSTNAME')
#>>> config = config_from_yaml(fileobj=fileobj, parse_env=True)
#>>> config.get('HOSTNAME')
#'MYTEST'
"""
if not filepath and not fileobj:
if silent is False:
raise ValueError(u"Not filepath or fileobj in parameters")
else:
return {}
if filepath and not os.path.exists(filepath):
if silent is False:
raise ValueError("file not found : %s" % filepath)
else:
return {}
config = {}
dict_update = {}
try:
if not fileobj:
with open(filepath, 'r') as fp:
config = yaml_load(fp, Loader=YAMLLoader)
else:
config = yaml_load(fileobj, Loader=YAMLLoader)
except:
if silent is False:
raise
try:
for k, v in six.iteritems(config):
if upper_only and not k.isupper():
continue
if not k in BANNED_SETTINGS:
dict_update[k] = v
except:
if silent is False:
raise
if parse_env:
dict_update = replace_with(dict_update.copy())
return dict_update
开发者ID:srault95,项目名称:tplconfig,代码行数:59,代码来源:config_from.py
示例6: is_yaml_string_valid
def is_yaml_string_valid(yaml_string):
try:
yaml_load(yaml_string)
except ConstructorError:
return True
except:
return False
return True
开发者ID:ateranishi,项目名称:pyon,代码行数:8,代码来源:interface_util.py
示例7: parse_all_kinds
def parse_all_kinds(yaml_path, sort_rank_path, include_kind_detail):
from glob import glob
from os.path import join, split, exists
from yaml import load as yaml_load
from vectordatasource.transform import CSVMatcher
all_kinds = {}
for yaml_file in glob(join(yaml_path, '*.yaml')):
layer_name = split(yaml_file)[1][:-5]
with open(yaml_file, 'r') as fh:
yaml_data = yaml_load(fh)
# by default, we don't have any sort_rank information
sort_rank = no_matcher
# look for a spreadsheet for sort_rank
csv_file = join(yaml_path, '..', 'spreadsheets', 'sort_rank',
'%s.csv' % layer_name)
if exists(csv_file):
with open(csv_file, 'r') as fh:
sort_rank = CSVMatcher(fh)
for item in yaml_data['filters']:
kinds = parse_item(layer_name, item, sort_rank,
include_kind_detail)
for k, v in kinds.iteritems():
prev_v = all_kinds.get(k)
if prev_v is not None:
v = merge_info(prev_v, v)
all_kinds[k] = v
return all_kinds
开发者ID:tilezen,项目名称:vector-datasource,代码行数:32,代码来源:kinds.py
示例8: _init
def _init(_yaml):
_setting = dict()
with codecs.open(yaml, "r", encoding="utf-8") as f:
_setting = yaml_load(f.read())
_setting["servers"] = dict(map(lambda x: (x["name"], x),
_setting["servers"]))
_setting["channels"] = dict(
map(lambda x: ((x["server"], x["name"]), x), _setting["channels"]))
if "users" in _setting:
_setting["users"] = map(compile_regex, _setting["users"])
else:
_setting["users"] = list()
# rearrange handlers' data structure
try:
h = dict(privmsg=list(), user_joined=list(), joined=list())
for item in _setting["handlers"]:
if "rewrites" in item:
item["rewrites"] = map(compile_regex, item["rewrites"])
if item["type"] in h:
data = dict(map(_compile_regex, item.items()))
h[item["type"]].append(data)
else:
log.msg("invalid message type: %s" % item["type"])
_setting["handlers"] = h
except Exception as e:
raise ConfigError("malformed handler configuration: %s" % str(e))
return _setting
开发者ID:jianingy,项目名称:sabo,代码行数:34,代码来源:setting.py
示例9: __init__
def __init__(self,
config = '/etc/chasm/zone.conf', auto_start = True):
self.cfg = yaml_load(open(config))
address = (self.cfg["server"]["address"], self.cfg["server"]["port"])
self._address = address
# this will contain all registered packet handlers
# the lock protects this from adds/gets during _receiving_loop
self._packet_handlers_lock = RLock()
self._packet_handlers = {}
# this is an arbitrary packet identifier which handlers can register
# if they want to be invoked when an address disconnects in the core.
# See the SessionManager._handle_disconnect() for an example.
self.DISCONNECT_PACKET_ID = "DISCONNECTED"
self._local_packet_handlers = {
c2s_packet.ArenaEnter._id : self._handle_arena_enter,
c2s_packet.ArenaLeave._id : self._handle_arena_leave,
self.DISCONNECT_PACKET_ID : self._handle_disconnect,
}
self.add_packet_handlers(**self._local_packet_handlers)
self.core = server.Server(self._address)
self.shutting_down = Event()
self._threads = {
"recv" : Thread(target=self._receiving_loop,name="Zone:recv")
}
# ping server runs on port + 1
ping_address = address[0], address[1] + 1
self.ping_server = ping.PingServer(ping_address, self)
self.sessions = session.SessionManager(self)
self.message = message.Messenger(self, self.cfg["messaging"])
self.arenas = [arena.Arena(self, arena_name, self.cfg["arenas"][arena_name])
for arena_name in self.cfg["arenas"].iterkeys()]
开发者ID:dmccartney,项目名称:chasm,代码行数:31,代码来源:zone.py
示例10: get_yaml_from_mercurial
def get_yaml_from_mercurial(vcs_address, vcs_subdir):
from mercurial import ui, commands
from urllib2 import HTTPError
import hglib
vtemp = mkdtemp(prefix='multipkg-vcs-')
try:
commands.clone(ui.ui(), str(vcs_address), dest=vtemp)
client = hglib.open(vtemp)
# get index.yaml
path_to_yaml = path_join(vtemp, vcs_subdir, 'index.yaml')
yaml = yaml_load(file(path_to_yaml).read())
recent_changes = []
for entry in client.log('tip:tip^^'):
num, rev, none, branch, author, msg, date = entry
date = date.strftime('%Y-%m-%d %H:%M:%S')
recent_changes.append("commit %s | Author: %s | Date: %s \n%s\n" %
(rev, author, date, msg))
yaml['.'] = dict(recent_changes="\n".join(recent_changes))
return yaml
except HTTPError:
raise RemotePackageNotFoundError(vcs_address)
except IOError as e:
if e.errno == errno.ENOENT and e.filename.find('.yaml') > -1:
raise IndexNotFoundError('index.yaml not found in your repository')
raise
except:
raise
finally:
if isdir(vtemp):
rmtree(vtemp)
开发者ID:jianingy,项目名称:multipkgadmin,代码行数:31,代码来源:utils.py
示例11: get_yaml_from_subversion
def get_yaml_from_subversion(vcs_address, vcs_subdir):
import pysvn
vtemp = mkdtemp(prefix='multipkg-vcs-')
client = pysvn.Client()
client.exception_style = 1
try:
client.checkout(vcs_address, vtemp, depth=pysvn.depth.empty)
# get index.yaml
path_to_yaml = path_join(vtemp, vcs_subdir, 'index.yaml')
client.update(path_to_yaml)
yaml = yaml_load(file(path_to_yaml).read())
recent_changes = []
for entry in client.log(vcs_address, limit=3):
date = datetime.datetime.fromtimestamp(int(entry.date))
date = date.strftime('%Y-%m-%d %H:%M:%S')
fmt = "revision #%-8s | Author: %-20s | Date: %-20s | Comment: %s"
recent_changes.append(fmt % (entry.revision.number,
entry.author, date, entry.message))
yaml['.'] = dict(recent_changes="\n".join(recent_changes))
return yaml
except pysvn.ClientError as e:
message, code = e.args[1][0]
if code == 170000:
raise RemotePackageNotFoundError(vcs_address)
else:
raise
except IOError as e:
if e.errno == errno.ENOENT and e.filename.find('.yaml') > -1:
raise IndexNotFoundError('index.yaml not found in your repository')
raise
finally:
if isdir(vtemp):
rmtree(vtemp)
开发者ID:jianingy,项目名称:multipkgadmin,代码行数:34,代码来源:utils.py
示例12: _load_token
def _load_token(file):
with open(file) as tokenfile:
token = yaml_load(tokenfile)
return OAuth1(token['api_key'],
client_secret = token['api_secret'],
resource_owner_key = token['token'],
resource_owner_secret = token['token_secret'])
开发者ID:jboynyc,项目名称:twitter-research,代码行数:7,代码来源:utils.py
示例13: __init__
def __init__(self, conf_file=None, defs_file=None):
self._base_defs = {}
self._plugins = {}
self._parsers = {}
self._config_file = conf_file
self.data = ConfigData()
if defs_file is None:
# Create configuration definitions from source
b_defs_file = to_bytes('%s/base.yml' % os.path.dirname(__file__))
else:
b_defs_file = to_bytes(defs_file)
# consume definitions
if os.path.exists(b_defs_file):
with open(b_defs_file, 'rb') as config_def:
self._base_defs = yaml_load(config_def, Loader=SafeLoader)
else:
raise AnsibleError("Missing base configuration definition file (bad install?): %s" % to_native(b_defs_file))
if self._config_file is None:
# set config using ini
self._config_file = find_ini_config_file()
# consume configuration
if self._config_file:
if os.path.exists(self._config_file):
# initialize parser and read config
self._parse_config_file()
# update constants
self.update_config_data()
开发者ID:awiddersheim,项目名称:ansible,代码行数:34,代码来源:manager.py
示例14: run
def run(self):
"""
Implements the directive
"""
# Get content and options
file_path = self.options.get('file', None)
type = self.options.get('type', 'all')
if not file_path:
return [self._report('file_path -option missing')]
projects = yaml_load(open(self._get_directive_path(file_path)).read())
ret = []
for project in projects:
project = projects[project]
if type == 'top' and project['is_primary'] == False:
continue
node = doctrineprojects()
node['project'] = project
node['type'] = type
node['sort'] = project['sort']
ret.append(node)
ret.sort(key=operator.itemgetter('sort'))
return ret
开发者ID:doctrine,项目名称:doctrine-website-sphinx,代码行数:29,代码来源:doctrineprojects.py
示例15: load_yaml_config
def load_yaml_config(settings=None, default_config=None):
if not HAVE_YAML:
raise Exception("PyYAML is not installed\n")
default_config = default_config or {}
if isinstance(settings, list):
found = False
for s in settings:
if not s:
continue
filepath = os.path.abspath(os.path.expanduser(s))
logger.debug("search in %s" % filepath)
if filepath and os.path.exists(filepath):
logger.info("load from %s" % filepath)
settings = filepath
found = True
break
if not found:
raise Exception("file not found in all paths")
stream = settings
if isinstance(settings, string_types):
with open(settings) as fp:
stream = StringIO(fp.read())
yaml_config = yaml_load(stream)
default_config.update(yaml_config)
return default_config
开发者ID:jawed123,项目名称:mongrey,代码行数:35,代码来源:utils.py
示例16: load_from_path
def load_from_path(self, path):
self.path = path
if not os.path.exists(path):
console_ui.emit_error("Error", "Path does not exist")
return False
if not os.path.isfile and not os.path.islink(path):
console_ui.emit_error("Error", "File specified is not a file")
return False
filename = os.path.basename(path)
# We'll get rid of this at some point :P
if filename != "package.yml":
console_ui.emit_warning("Unnecessarily Anal Warning",
"File is not named package.yml")
# Attempt to parse the input file
with open(path, "r") as inpfile:
try:
yaml_data = yaml_load(inpfile, Loader=Loader)
except Exception as e:
console_ui.emit_error("YAML", "Failed to parse YAML file")
print(e)
return False
b = self.load_from_data(yaml_data)
if not b:
return b
return self.load_component()
开发者ID:AvdN,项目名称:ypkg,代码行数:29,代码来源:ypkgspec.py
示例17: _load_rules
def _load_rules(self, file_path):
config = {}
with open(file_path, 'r') as config_stream:
config = yaml_load(config_stream, Loader=YAMLLoader)
self._settings = config.get('settings', self._settings)
self._rules = config.get('rules', self._rules)
开发者ID:asgeir,项目名称:old-school-projects,代码行数:8,代码来源:repository.py
示例18: config_load
def config_load():
'''load the commandr config files from the users home dir and the local
meta/ folder and merge them together into one'''
global_config = dict()
local_config = dict()
global_config_file = path("$HOME").expand() / ".commandr.yml"
if global_config_file.exists():
global_stream = open(global_config_file, 'r')
global_config = yaml_load(global_stream)
local_config_file = path_meta() / "commandr.yml"
if local_config_file.exists():
local_stream = open(local_config_file, 'r')
local_config = yaml_load(local_stream)
return dict_merge(global_config, local_config)
开发者ID:michaelcontento,项目名称:monkey-shovel,代码行数:17,代码来源:commandr.py
示例19: load_params_layer
def load_params_layer(self, params_file):
"""
Load an individual layer of params from file on to params
"""
yaml_string = self.env.get_template(params_file).render(**self.params)
yaml_dict = yaml_load(yaml_string)
self.params.update(yaml_dict)
self.params.setdefault('_files', {})[params_file] = yaml_dict
开发者ID:RickyCook,项目名称:configify,代码行数:8,代码来源:configify.py
示例20: get_atomic_config
def get_atomic_config():
# Returns the atomic configuration file (/etc/atomic.conf)
# in a dict
# :return: dict based structure of the atomic config file
if not os.path.exists(ATOMIC_CONF):
raise ValueError("{} does not exist".format(ATOMIC_CONF))
with open(ATOMIC_CONF, 'r') as conf_file:
return yaml_load(conf_file)
开发者ID:gbraad,项目名称:atomic,代码行数:8,代码来源:util.py
注:本文中的yaml.yaml_load函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论