本文整理汇总了Python中tank_vendor.yaml.load函数的典型用法代码示例。如果您正苦于以下问题:Python load函数的具体用法?Python load怎么用?Python load使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了load函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_update_engine_settings
def test_update_engine_settings(self):
self.assertRaises(TankError, self.env.update_engine_settings, "bad_engine", {}, {})
# get raw environment before
env_file = os.path.join(self.project_config, "env", "test.yml")
fh = open(env_file)
env_before = yaml.load(fh)
fh.close()
prev_settings = self.env.get_engine_settings("test_engine")
self.env.update_engine_settings("test_engine", {"foo":"bar"}, {"type":"dev", "path":"foo"})
# get raw environment after
env_file = os.path.join(self.project_config, "env", "test.yml")
fh = open(env_file)
env_after = yaml.load(fh)
fh.close()
# ensure that disk was updated
self.assertNotEqual(env_after, env_before)
env_before["engines"]["test_engine"]["foo"] = "bar"
env_before["engines"]["test_engine"]["location"] = {"type":"dev", "path":"foo"}
self.assertEqual(env_after, env_before)
# ensure memory was updated
new_settings = self.env.get_engine_settings("test_engine")
prev_settings.update({"foo":"bar"})
self.assertEqual(new_settings, prev_settings)
desc_after = self.env.get_engine_descriptor("test_engine")
self.assertEqual(desc_after.get_location(), {"type":"dev", "path":"foo"})
示例2: test_add_app
def test_add_app(self):
self.assertRaises(TankError, self.env.create_app_settings, "test_engine", "test_app")
self.assertRaises(TankError, self.env.create_app_settings, "unknown_engine", "test_app")
# get raw environment before
env_file = os.path.join(self.project_config, "env", "test.yml")
with open(env_file) as fh:
env_before = yaml.load(fh)
self.env.create_app_settings("test_engine", "new_app")
# get raw environment after
env_file = os.path.join(self.project_config, "env", "test.yml")
with open(env_file) as fh:
env_after = yaml.load(fh)
# ensure that disk was updated
self.assertNotEqual(env_after, env_before)
env_before["engines"]["test_engine"]["apps"]["new_app"] = {}
env_before["engines"]["test_engine"]["apps"]["new_app"]["location"] = {}
self.assertEqual(env_after, env_before)
# ensure memory was updated
cfg_after = self.env.get_app_settings("test_engine", "new_app")
self.assertEqual(cfg_after, {})
示例3: setUp
def setUp(self):
super(TestEnvironment, self).setUp()
self.setup_fixtures()
self.test_env = "test"
self.test_engine = "test_engine"
# create env object
self.env = self.tk.pipeline_configuration.get_environment(self.test_env)
# get raw environment
env_file = os.path.join(self.project_config, "env", "test.yml")
fh = open(env_file)
self.raw_env_data = yaml.load(fh)
fh.close()
# get raw app metadata
app_md = os.path.join(self.project_config, "bundles", "test_app", "info.yml")
fh = open(app_md)
self.raw_app_metadata = yaml.load(fh)
fh.close()
# get raw engine metadata
eng_md = os.path.join(self.project_config, "bundles", "test_engine", "info.yml")
fh = open(eng_md)
self.raw_engine_metadata = yaml.load(fh)
fh.close()
示例4: _load_nuke_publish_snapshot_comments
def _load_nuke_publish_snapshot_comments(self, snapshot_file_path):
"""
Load old nuke-style snapshot comments if they exist. These are only
ever read - all new comments are saved to the new file.
"""
comments = {}
try:
# look for old nuke style path:
snapshot_dir = os.path.dirname(snapshot_file_path)
fields = self._snapshot_template.get_fields(snapshot_file_path)
SNAPSHOT_COMMENTS_FILE = r"%s_comments.yml"
comments_file_name = SNAPSHOT_COMMENTS_FILE % fields.get("name", "unknown")
comments_file_path = os.path.join(snapshot_dir, comments_file_name)
comments = {}
if os.path.exists(comments_file_path):
raw_comments = yaml.load(open(comments_file_path, "r"))
for (name, timestamp), comment in raw_comments.iteritems():
fields["name"] = name
fields["timestamp"] = timestamp
snapshot_path = self._snapshot_template.apply_fields(fields)
if os.path.exists(snapshot_path):
# add comment to dictionary in new style:
comments_key = os.path.basename(snapshot_path)
comments[comments_key] = {"comment":comment}
except:
# it's not critical that this succeeds so just ignore any exceptions
pass
return comments
示例5: _get_snapshot_comments
def _get_snapshot_comments(self, snapshot_file_path):
"""
Return the snapshot comments for the specified file path
"""
# first, attempt to load old-nuke-publish-style comments:
comments = self._load_nuke_publish_snapshot_comments(snapshot_file_path)
# now load new style comments:
comments_file_path = self._get_comments_file_path(snapshot_file_path)
raw_comments = {}
if os.path.exists(comments_file_path):
raw_comments = yaml.load(open(comments_file_path, "r"))
# process raw comments to convert old-style to new if need to:
for key, value in raw_comments.iteritems():
if isinstance(value, basestring):
# old style string
comments[key] = {"comment":value}
elif isinstance(value, dict):
# new style dictionary
comments[key] = value
else:
# value isn't valid!
pass
# ensure all comments are returned as utf-8 strings rather than
# unicode - this is due to a previous bug where the snapshot UI
# would return the comment as unicode!
for comment_dict in comments.values():
comment = comment_dict.get("comment")
if comment and isinstance(comment, unicode):
comment_dict["comment"] = comment.encode("utf8")
return comments
示例6: _get_roots_data
def _get_roots_data(self):
"""
Returns roots.yml data for this config.
If no root file can be loaded, {} is returned.
:returns: Roots data yaml content, usually a dictionary
"""
self._io_descriptor.ensure_local()
# get the roots definition
root_file_path = os.path.join(
self._io_descriptor.get_path(),
"core",
constants.STORAGE_ROOTS_FILE)
roots_data = {}
if os.path.exists(root_file_path):
root_file = open(root_file_path, "r")
try:
# if file is empty, initializae with empty dict...
roots_data = yaml.load(root_file) or {}
finally:
root_file.close()
return roots_data
示例7: test_project_root_mismatch
def test_project_root_mismatch(self):
"""
Case that root name specified in projects yml file does not exist in roots file.
"""
# remove root name from the roots file
self.setup_multi_root_fixtures()
self.tk = tank.Tank(self.project_root)
# should be fine
folder.configuration.FolderConfiguration(self.tk, self.schema_location)
roots_file = os.path.join(self.tk.pipeline_configuration.get_path(), "config", "core", "schema", "alternate_1.yml")
fh = open(roots_file, "r")
data = yaml.load(fh)
fh.close()
data["root_name"] = "some_bogus_Data"
fh = open(roots_file, "w")
fh.write(yaml.dump(data))
fh.close()
self.tk = tank.Tank(self.project_root)
self.assertRaises(TankError,
folder.configuration.FolderConfiguration,
self.tk,
self.schema_location)
示例8: get_pc_registered_location
def get_pc_registered_location(pipeline_config_root_path):
"""
Loads the location metadata file from install_location.yml
This contains a reflection of the paths given in the pc entity.
Returns the path that has been registered for this pipeline configuration
for the current OS.
This is the path that has been defined in shotgun. It is also the path that is being
used in the inverse pointer files that exist in each storage.
This is useful when drive letter mappings or symlinks are being used - in these
cases get_path() may not return the same value as get_registered_location_path().
This may return None if no path has been registered for the current os.
"""
# now read in the pipeline_configuration.yml file
cfg_yml = os.path.join(pipeline_config_root_path, "config", "core", "install_location.yml")
if not os.path.exists(cfg_yml):
raise TankError("Location metadata file '%s' missing! Please contact support." % cfg_yml)
fh = open(cfg_yml, "rt")
try:
data = yaml.load(fh)
except Exception, e:
raise TankError("Looks like a config file is corrupt. Please contact "
"support! File: '%s' Error: %s" % (cfg_yml, e))
示例9: _get_metadata
def _get_metadata(self):
"""
Returns the info.yml metadata associated with this descriptor.
Note that this call involves deep introspection; in order to
access the metadata we normally need to have the code content
local, so this method may trigger a remote code fetch if necessary.
"""
if self.__manifest_data is None:
# make sure payload exists locally
if not self.exists_local():
self.download_local()
# get the metadata
bundle_root = self.get_path()
file_path = os.path.join(bundle_root, constants.BUNDLE_METADATA_FILE)
if not os.path.exists(file_path):
raise TankError("Toolkit metadata file '%s' missing." % file_path)
try:
file_data = open(file_path)
try:
metadata = yaml.load(file_data)
finally:
file_data.close()
except Exception, exp:
raise TankError("Cannot load metadata file '%s'. Error: %s" % (file_path, exp))
# cache it
self.__manifest_data = metadata
示例10: test_url_cleanup
def test_url_cleanup(self):
# Make sure that if a file has the url saved incorrectly...
with patch("sgtk.util.shotgun.connection.sanitize_url", wraps=lambda x: x):
session_cache.set_current_host("https://host.cleaned.up.on.read/")
# ... then sure we indeed disabled cleanup and that the malformed value was written to disk...
self.assertEquals("https://host.cleaned.up.on.read/", session_cache.get_current_host())
# ... and finaly that the value is filtered when being read back from disk.
self.assertEquals("https://host.cleaned.up.on.read", session_cache.get_current_host())
# Make sure we're cleaning up the hostname when saving it.
session_cache.set_current_host("https://host.cleaned.up.on.write/")
with open(
os.path.join(
LocalFileStorageManager.get_global_root(
LocalFileStorageManager.CACHE
),
"authentication.yml"
),
"r"
) as fh:
# Let's read the file directly to see if the data was cleaned up.
data = yaml.load(fh)
self.assertEqual(
data["current_host"],
"https://host.cleaned.up.on.write"
)
示例11: get_associated_core_version
def get_associated_core_version(self):
"""
Returns the version string for the core api associated with this config.
This method is 'forgiving' and in the case no associated core API can be
found for this pipeline configuration, None will be returned rather than
an exception raised.
"""
associated_api_root = self.get_install_location()
info_yml_path = os.path.join(associated_api_root, "core", "info.yml")
if os.path.exists(info_yml_path):
try:
info_fh = open(info_yml_path, "r")
try:
data = yaml.load(info_fh)
finally:
info_fh.close()
data = data.get("version")
except:
data = None
else:
data = None
return data
示例12: get_pc_roots_metadata
def get_pc_roots_metadata(pipeline_config_root_path):
"""
Loads and validates the roots metadata file.
The roots.yml file is a reflection of the local storages setup in Shotgun
at project setup time and may contain anomalies in the path layout structure.
The roots data will be prepended to paths and used for comparison so it is
critical that the paths are on a correct normalized form once they have been
loaded into the system.
"""
# now read in the roots.yml file
# this will contain something like
# {'primary': {'mac_path': '/studio', 'windows_path': None, 'linux_path': '/studio'}}
roots_yml = os.path.join(pipeline_config_root_path, "config", "core", "roots.yml")
if not os.path.exists(roots_yml):
raise TankError("Roots metadata file '%s' missing! Please contact support." % roots_yml)
fh = open(roots_yml, "rt")
try:
data = yaml.load(fh)
except Exception, e:
raise TankError("Looks like the roots file is corrupt. Please contact "
"support! File: '%s' Error: %s" % (roots_yml, e))
示例13: _get_metadata
def _get_metadata(self):
"""
Loads the pipeline config metadata (the pipeline_configuration.yml) file from disk.
:param pipeline_config_path: path to a pipeline configuration root folder
:returns: deserialized content of the file in the form of a dict.
"""
# now read in the pipeline_configuration.yml file
cfg_yml = self._get_pipeline_config_file_location()
if not os.path.exists(cfg_yml):
raise TankError("Configuration metadata file '%s' missing! "
"Please contact support." % cfg_yml)
fh = open(cfg_yml, "rt")
try:
data = yaml.load(fh)
if data is None:
raise Exception("File contains no data!")
except Exception as e:
raise TankError("Looks like a config file is corrupt. Please contact "
"support! File: '%s' Error: %s" % (cfg_yml, e))
finally:
fh.close()
return data
示例14: _get_install_locations
def _get_install_locations(path):
"""
Given a pipeline configuration OR core location, return paths on all platforms.
:param path: Path to a pipeline configuration on disk.
:returns: dictionary with keys linux2, darwin and win32
"""
# basic sanity check
if not os.path.exists(path):
raise TankError("The core path '%s' does not exist on disk!" % path)
# for other platforms, read in install_location
location_file = os.path.join(path, "config", "core", "install_location.yml")
if not os.path.exists(location_file):
raise TankError("Cannot find core config file '%s' - please contact support!" % location_file)
# load the config file
try:
open_file = open(location_file)
try:
location_data = yaml.load(open_file)
finally:
open_file.close()
except Exception, error:
raise TankError("Cannot load core config file '%s'. Error: %s" % (location_file, error))
示例15: get_location
def get_location(sgtk, app_bootstrap):
"""
Returns a location dictionary for the bundled framework.
:param sgtk: Handle to the Toolkit API
:param app_bootstrap: Instance of the application bootstrap.
:returns: A dictionary with keys and values following the Toolkit location
convention. Read more at https://support.shotgunsoftware.com/entries/95442678#Code%20Locations
"""
dev_descriptor = {
"type": "dev",
"path": app_bootstrap.get_startup_location_override()
}
# If the startup location had been overriden, the descriptor is automatically
# a dev descriptor.
if app_bootstrap.get_startup_location_override():
return dev_descriptor
# If we are running the bundled startup, it is possible to override it's
# value on first run in order to trigger the system into pulling from
# another location that the app_store, namely git. This is done through an
# environment variable. This is also great for testing app_store updates
# by pretending you have an older version of the code bundled and need an update.
# Local import since sgtk is lazily loaded.
from tank_vendor import yaml
if app_bootstrap.runs_bundled_startup() and "SGTK_DESKTOP_BUNDLED_DESCRIPTOR" in os.environ:
try:
return yaml.load(os.environ["SGTK_DESKTOP_BUNDLED_DESCRIPTOR"])
except yaml.YAMLError, e:
raise BundledDescriptorEnvVarError(e)