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


Python yaml.dump函数代码示例

本文整理汇总了Python中tank_vendor.yaml.dump函数的典型用法代码示例。如果您正苦于以下问题:Python dump函数的具体用法?Python dump怎么用?Python dump使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: test_flexible_primary

    def test_flexible_primary(self):
        """
        Tests getting storage paths back from a pipeline config without a 'primary'
        storage.
        """

        # take one path out and mark as undefined
        new_roots = copy.deepcopy(self.roots)
        new_roots["master"] = new_roots.pop("primary")
        root_file = open(self.root_file_path, "w")
        root_file.write(yaml.dump(new_roots))
        root_file.close()
        # We should get a TankError if we don't have a primary storage in a
        # multi-roots file.
        with self.assertRaisesRegexp(TankError, "Could not identify a default storage"):
            pc = tank.pipelineconfig_factory.from_path(self.project_root)
        # Only keep the master storage
        del new_roots["publish"]
        del new_roots["render"]
        root_file = open(self.root_file_path, "w")
        root_file.write(yaml.dump(new_roots))
        root_file.close()
        pc = tank.pipelineconfig_factory.from_path(self.project_root)
        self.assertEqual(pc.get_all_platform_data_roots().keys(), ["master"])
        self.assertEqual(pc.get_data_roots().keys(), ["master"])
        self.assertEqual(self.project_root, pc.get_primary_data_root())
开发者ID:adriankrupa,项目名称:tk-core,代码行数:26,代码来源:test_root.py

示例2: turn_on_shotgun_path_cache

 def turn_on_shotgun_path_cache(self):
     """
     Updates the pipeline configuration settings to have the shotgun based (v0.15+)
     path cache functionality enabled.
     
     Note that you need to force a full path sync once this command has been executed. 
     """
     
     if self.get_shotgun_path_cache_enabled():
         raise TankError("Shotgun based path cache already turned on!")
             
     # get current settings
     curr_settings = pipelineconfig_utils.get_metadata(self._pc_root)
     
     # add path cache setting
     curr_settings["use_shotgun_path_cache"] = True
     
     # write the record to disk
     pipe_config_sg_id_path = os.path.join(self._pc_root, "config", "core", "pipeline_configuration.yml")        
     
     old_umask = os.umask(0)
     try:
         os.chmod(pipe_config_sg_id_path, 0666)
         # and write the new file
         fh = open(pipe_config_sg_id_path, "wt")
         yaml.dump(curr_settings, fh)
     except Exception, exp:
         raise TankError("Could not write to pipeline configuration settings file %s. "
                         "Error reported: %s" % (pipe_config_sg_id_path, exp))
开发者ID:adriankrupa,项目名称:tk-framework-desktopstartup,代码行数:29,代码来源:pipelineconfig.py

示例3: __write_data

 def __write_data(self, path, data):
     """
     writes the main data to disk, raw form
     """
     try:
         env_file = open(path, "wt")
         yaml.dump(data, env_file)
     except Exception, exp:
         raise TankError("Could not write environment file %s. Error reported: %s" % (path, exp))
开发者ID:bdeluca,项目名称:tk-core,代码行数:9,代码来源:environment.py

示例4: _write_yaml_file

def _write_yaml_file(file_path, users_data):
    """
    Writes the yaml file at a given location.

    :param file_path: Where to write the users data
    :param users_data: Dictionary to write to disk.
    """
    old_umask = os.umask(0077)
    try:
        with open(file_path, "w") as users_file:
            yaml.dump(users_data, users_file)
    finally:
        os.umask(old_umask)
开发者ID:kidintwo3,项目名称:sx_goldenman,代码行数:13,代码来源:session_cache.py

示例5: write_location

def write_location(descriptor):
    """
    Writes the descriptor dictionary to disk in the BUNDLE_ROOT/resources/location.yml file.
    """
    # Local import since sgtk is lazily loaded.
    from tank_vendor import yaml
    old_umask = os.umask(0077)
    try:
        # Write the toolkit descriptor information to disk.
        location_yml_path = os.path.join(_get_location_yaml_location(descriptor.get_path()))
        with open(location_yml_path, "w") as location_yml:
            location_yml.write(copyright)
            yaml.dump(descriptor.get_location(), location_yml)
    finally:
        os.umask(old_umask)
开发者ID:shotgunsoftware,项目名称:tk-framework-desktopstartup,代码行数:15,代码来源:location.py

示例6: test_installed_config_manifest

    def test_installed_config_manifest(self):
        """
        Ensures the manifest is read correctly.
        """
        # Create a manifest file for the pipeline configuration.
        with open(os.path.join(self.pipeline_config_root, "config", "info.yml"), "w") as fh:
            fh.write(
                yaml.dump({
                    "display_name": "Unit Test Configuration",
                    "requires_shotgun_version": "v6.3.0",
                    "requires_core_version": "HEAD"
                })
            )

        self.assertEqual(
            self.tk.configuration_descriptor.display_name,
            "Unit Test Configuration"
        )

        self.assertEqual(
            self.tk.configuration_descriptor.description,
            "No description available."
        )

        self.assertEqual(
            self.tk.configuration_descriptor.version_constraints["min_sg"],
            "v6.3.0"
        )

        self.assertEqual(
            self.tk.configuration_descriptor.version_constraints["min_core"],
            "HEAD"
        )
开发者ID:adriankrupa,项目名称:tk-core,代码行数:33,代码来源:test_descriptors.py

示例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)
开发者ID:Pixomondo,项目名称:tk-core,代码行数:27,代码来源:test_configuration.py

示例8: setUp

    def setUp(self):

        # set up a project named temp, so that it will end up in c:\temp

        super(TestTankFromPathWindowsNoSlash, self).setUp(project_tank_name=self.PROJECT_NAME)

        # set up std fixtures
        self.setup_fixtures()

        # patch primary local storage def
        self.primary_storage["windows_path"] = self.STORAGE_ROOT
        # re-add it
        self.add_to_sg_mock_db(self.primary_storage)

        # now re-write roots.yml
        roots = {"primary": {}}
        for os_name in ["windows_path", "linux_path", "mac_path"]:
            #TODO make os specific roots
            roots["primary"][os_name] = self.sg_pc_entity[os_name]
        roots_path = os.path.join(self.pipeline_config_root,
                                  "config",
                                  "core",
                                  "roots.yml")
        roots_file = open(roots_path, "w")
        roots_file.write(yaml.dump(roots))
        roots_file.close()

        # need a new PC object that is using the new roots def file we just created
        self.pipeline_configuration = sgtk.pipelineconfig_factory.from_path(self.pipeline_config_root)
        # push this new PC into the tk api
        self.tk._Tank__pipeline_config = self.pipeline_configuration
        # force reload templates
        self.tk.reload_templates()
开发者ID:hongloull,项目名称:tk-core,代码行数:33,代码来源:test_api.py

示例9: test_self_contained_config_core_descriptor

    def test_self_contained_config_core_descriptor(self):
        """
        Ensures that a configuration with a local bundle cache can return a core
        descriptor that points inside the configuration if the core is cached there.
        """
        config_root = os.path.join(self.tank_temp, "self_contained_config")
        core_location = os.path.join(
            config_root, "bundle_cache", "app_store", "tk-core", "v0.18.133"
        )
        self.create_file(
            os.path.join(core_location, "info.yml"),
            ""
        )
        self.create_file(
            os.path.join(config_root, "core", "core_api.yml"),
            yaml.dump({"location": {"type": "app_store", "name": "tk-core", "version": "v0.18.133"}})
        )

        config_desc = create_descriptor(
            self.mockgun,
            Descriptor.CONFIG,
            "sgtk:descriptor:path?path={0}".format(config_root)
        )
        core_desc = config_desc.resolve_core_descriptor()
        self.assertEqual(
            core_desc.get_path(),
            core_location
        )
开发者ID:adriankrupa,项目名称:tk-core,代码行数:28,代码来源:test_descriptors.py

示例10: test_all_paths

    def test_all_paths(self):
        """
        Tests getting storage paths back from a pipeline config. 
        """
        
        # take one path out and mark as undefined
        new_roots = copy.deepcopy(self.roots)
        new_roots["render"]["linux_path"] = None
        
        root_file = open(self.root_file_path, "w")
        root_file.write(yaml.dump(new_roots))
        root_file.close()

        pc = tank.pipelineconfig_factory.from_path(self.project_root)
        result = pc.get_all_platform_data_roots()
        
        platform_lookup = {"win32": "windows_path", "darwin": "mac_path", "linux2": "linux_path"}

        project_name = os.path.basename(self.project_root)
        for root_name, platform_paths in result.items():
            for platform in platform_paths:
                root_path = platform_paths[platform]
                shotgun_path_key = platform_lookup[platform] 
                if new_roots[root_name][shotgun_path_key] is None:
                    expected_path = None
                elif platform == "win32":
                    expected_path = "%s\\%s" % (new_roots[root_name][shotgun_path_key], project_name)
                else:
                    expected_path = "%s/%s" % (new_roots[root_name][shotgun_path_key], project_name)
                self.assertEqual(expected_path, root_path)
开发者ID:adriankrupa,项目名称:tk-core,代码行数:30,代码来源:test_root.py

示例11: save_comments

    def save_comments(self, file_path, comment):
        """
        Add a comment to the comment file for the saved file.  The comments 
        are stored in the following format:
        
        {<file name> : {
            comment:    String - comment to store
            sg_user:    Shotgun entity dictionary representing the user that created the snapshot
            }
         ...
        }

        :param str file_path: path to the snapshot file.
        :param str comments: comment string to save.
        """

        # clense the comment string
        orig_comment = comment
        comment = ""
        for c in orig_comment:
            if c in ['\n', ';', '\'', '}', '{', '`', '~', ':', '@', '<', '>', '\\']:
                comment += '_'
            else:
                comment += c

        # get comments file path:
        comments_file_path = self._get_comments_file_path(file_path)
        self._app.log_debug("Save_As: Adding comment to file %s" % comments_file_path)
        
        # load yml file
        comments = {}
        if os.path.exists(comments_file_path):
            comments = yaml.load(open(comments_file_path, "r"))

        # comment is now a dictionary so that we can also include the user:
        comments_value = {"comment":comment, "sg_user":self._app.context.user}
        
        # add entry for snapshot file:
        comments_key = os.path.basename(file_path)
        comments[comments_key] = comments_value
        
        # and save yml file
        old_umask = os.umask(0)
        try:
            yaml.dump(comments, open(comments_file_path, "w"))
        finally:
            os.umask(old_umask)
开发者ID:derickdressel,项目名称:tk-multi-workfilesEE,代码行数:47,代码来源:save_as.py

示例12: _setup_fixtures

    def _setup_fixtures(self, name="config", parameters=None):
        """
        See doc for setup fixtures.
        """

        parameters = parameters or {}

        # figure out root point of fixtures config
        config_root = os.path.join(self.fixtures_root, name)

        # first figure out core location
        if "core" in parameters:
            # This config is not simple, as it is piece from a env and hooks folder from one
            # location and the core from another.
            simple_config = False
            # convert slashes to be windows friendly
            core_path_suffix = parameters["core"].replace("/", os.sep)
            core_source = os.path.join(config_root, core_path_suffix)
        else:
            # This config is simple, as it is based on a config that is layed out into a single folder.
            simple_config = True
            # use the default core fixture
            core_source = os.path.join(config_root, "core")

        # Check if the tests wants the files to be copied.
        installed_config = parameters.get("installed_config", False)

        # If the config is not simple of the tests wants the files to be copied
        if not simple_config or installed_config:
            # copy core over to target
            core_target = os.path.join(self.project_config, "core")
            self._copy_folder(core_source, core_target)
            # now copy the rest of the config fixtures
            for config_folder in ["env", "hooks", "bundles"]:
                config_source = os.path.join(config_root, config_folder)
                if os.path.exists(config_source):
                    config_target = os.path.join(self.project_config, config_folder)
                    self._copy_folder(config_source, config_target)
        else:
            # We're going to be using a cached configuration, so set up the source_descriptor.
            pc_yml_location = os.path.join(self.pipeline_config_root, "config", "core", "pipeline_configuration.yml")
            with open(pc_yml_location, "r") as fh:
                pc_data = yaml.safe_load(fh)
            pc_data["source_descriptor"] = {"path": config_root, "type": "path"}
            with open(pc_yml_location, "w") as fh:
                fh.write(yaml.dump(pc_data))

            # Update where the config root variable points to.
            self.project_config = config_root

        # need to reload the pipeline config to respect the config data from
        # the fixtures
        self.reload_pipeline_config()

        if not ("skip_template_reload" in parameters and parameters["skip_template_reload"]):
            # no skip_template_reload flag set to true. So go ahead and reload
            self.tk.reload_templates()
开发者ID:shotgunsoftware,项目名称:tk-core,代码行数:57,代码来源:tank_test_base.py

示例13: _add_snapshot_comment

    def _add_snapshot_comment(self, snapshot_file_path, comment):
        """
        Add a comment to the comment file for a snapshot file.  The comments are stored
        in the following format:
        
        {<snapshot file name> : {
            comment:    String - comment to store
            sg_user:    Shotgun entity dictionary representing the user that created the snapshot
            }
         ...
        }

        :param str file_path: path to the snapshot file.
        :param str comment: comment string to save.

        """
        # validate to make sure path is sane
        if not self._snapshot_template.validate(snapshot_file_path):
            self._app.log_warning("Could not add comment to "
                                         "invalid snapshot path %s!" % snapshot_file_path)
            return

        # get comments file path:        
        comments_file_path = self._get_comments_file_path(snapshot_file_path)
        self._app.log_debug("Snapshot: Adding comment to file %s" % comments_file_path)
        
        # load yml file
        comments = {}
        if os.path.exists(comments_file_path):
            comments = yaml.load(open(comments_file_path, "r"))

        # comment is now a dictionary so that we can also include the user:
        comments_value = {"comment":comment, "sg_user":self._app.context.user}
            
        # add entry for snapshot file:
        comments_key = os.path.basename(snapshot_file_path)
        comments[comments_key] = comments_value
        
        # and save yml file
        old_umask = os.umask(0) 
        try:
            yaml.dump(comments, open(comments_file_path, "w"))
        finally:
            os.umask(old_umask) 
开发者ID:benoit-leveau,项目名称:tk-multi-snapshot,代码行数:44,代码来源:snapshot.py

示例14: setup_multi_root_fixtures

    def setup_multi_root_fixtures(self):
        """
        Helper method which sets up a standard multi-root set of fixtures
        """
        self.setup_fixtures(parameters = {"core": "core.override/multi_root_core", 
                                          "skip_template_reload": True})
        
        # Add multiple project roots
        project_name = os.path.basename(self.project_root)
        self.alt_root_1 = os.path.join(self.tank_temp, "alternate_1", project_name)
        self.alt_root_2 = os.path.join(self.tank_temp, "alternate_2", project_name)
        
        # add local storages to represent the alternate root points
        self.alt_storage_1 = {"type": "LocalStorage",
                              "id": 7778,
                              "code": "alternate_1",
                              "windows_path": os.path.join(self.tank_temp, "alternate_1"),
                              "linux_path": os.path.join(self.tank_temp, "alternate_1"),
                              "mac_path": os.path.join(self.tank_temp, "alternate_1") }
        self.add_to_sg_mock_db(self.alt_storage_1)
        
        self.alt_storage_2 = {"type": "LocalStorage",
                              "id": 7779,
                              "code": "alternate_2",
                              "windows_path": os.path.join(self.tank_temp, "alternate_2"),
                              "linux_path": os.path.join(self.tank_temp, "alternate_2"),
                              "mac_path": os.path.join(self.tank_temp, "alternate_2") }
        self.add_to_sg_mock_db(self.alt_storage_2)
        
        # Write roots file
        roots = {"primary": {}, "alternate_1": {}, "alternate_2": {}}
        for os_name in ["windows_path", "linux_path", "mac_path"]:
            #TODO make os specific roots
            roots["primary"][os_name]     = os.path.dirname(self.project_root)
            roots["alternate_1"][os_name] = os.path.dirname(self.alt_root_1)
            roots["alternate_2"][os_name] = os.path.dirname(self.alt_root_2)
        roots_path = os.path.join(self.pipeline_config_root, "config", "core", "roots.yml")     
        roots_file = open(roots_path, "w") 
        roots_file.write(yaml.dump(roots))
        roots_file.close()
        
        # need a new pipeline config object that is using the
        # new roots def file we just created
        self.pipeline_configuration = sgtk.pipelineconfig_factory.from_path(self.pipeline_config_root)
        # push this new pipeline config into the tk api
        self.tk._Sgtk__pipeline_config = self.pipeline_configuration

        # force reload templates
        self.tk.reload_templates()
        
        # add project root folders
        # primary path was already added in base setUp
        self.add_production_path(self.alt_root_1, self.project)
        self.add_production_path(self.alt_root_2, self.project)
        
        self.tk.create_filesystem_structure("Project", self.project["id"])
开发者ID:cuthb3rt,项目名称:tk-core,代码行数:56,代码来源:tank_test_base.py

示例15: _update_deploy_file

    def _update_deploy_file(self, generation=None, descriptor=None, corrupt=False):
        """
        Updates the deploy file.

        :param generation: If set, will update the generation number of the config.
        :param descriptor: If set, will update the descriptor of the config.
        :param corrupt: If set, will corrupt the configuration file.
        """
        path = self._cached_config._config_writer.get_descriptor_metadata_file()
        if corrupt:
            data = "corrupted"
        else:
            with open(path, "rt") as fh:
                data = yaml.load(fh)
                if generation is not None:
                    data["deploy_generation"] = generation
                if descriptor is not None:
                    data["config_descriptor"] = descriptor

        with open(path, "wt") as fh:
            yaml.dump(data, fh)
开发者ID:shotgunsoftware,项目名称:tk-core,代码行数:21,代码来源:test_configuration.py


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