Ejemplo n.º 1
0
    def delete_link(self, allow_delete_locked):
        """
        Creates the symlink on disk.

        :param allow_delete_locked:
                If True, then the link may be deleted, even if it is locked. If False, the link may not be deleted if it
                is locked.

        :return:
                Nothing.
        """

        assert type(allow_delete_locked) is bool

        if not allow_delete_locked and self.is_locked():
            err_msg = self.localized_resource_obj.get_error_msg(11106)
            err_msg = err_msg.format(pin=self.pin_p)
            raise SquirrelError(err_msg, 11106)

        if os.path.exists(os.path.abspath(self.pin_p)):
            if not os.path.islink(self.pin_p):
                err_msg = self.localized_resource_obj.get_error_msg(11008)
                err_msg = err_msg.format(pin=self.pin_p)
                raise SquirrelError(err_msg, 11008)
            os.unlink(self.pin_p)

        if os.path.exists(self.attr_pin_p):
            if not os.path.islink(self.attr_pin_p):
                err_msg = self.localized_resource_obj.get_error_msg(11102)
                err_msg = err_msg.format(pin=self.attr_pin_p)
                raise SquirrelError(err_msg, 11102)
            os.unlink(self.attr_pin_p)

        self.unlock()
Ejemplo n.º 2
0
    def _asset_id_from_uri(self, uri):
        """
        Returns a single asset_id based on the URI.

        :param uri:
                The uri.

        :return:
                An asset id.
        """

        assert uri is None or type(uri) is str

        if not urilib.validate_uri_format(uri):
            err_msg = self.localized_resource_obj.get_error_msg(201)
            err_msg = err_msg.format(uri=uri)
            raise SquirrelError(err_msg, 201)

        sql = self.sql_resources.get("asset_id_from_uri", "asset_id_from_uri")
        rows = self.cursor.execute(sql, (uri, )).fetchall()

        if len(rows) == 0:
            err_msg = self.localized_resource_obj.get_error_msg(911)
            err_msg = err_msg.format(uri=uri)
            raise SquirrelError(err_msg, 911)

        if len(rows) > 1:
            err_msg = self.localized_resource_obj.get_error_msg(912)
            err_msg = err_msg.format(uri=uri)
            raise SquirrelError(err_msg, 912)

        return rows[0][0]
Ejemplo n.º 3
0
    def asset_parent_d_and_name_from_uri(self, uri):
        """
        Given a URI, return tuple containing the asset parent_d and asset_n.

        :param uri:
                The full URI that identifies the asset (repo_name://uri_path/asset_name)

        :return:
                A tuple containing the asset parent_d and asset_n.
        """

        assert type(uri) is str

        sql = self.sql_resources.get("asset_obj_from_url", "asset_d_from_uri")
        rows = self.cursor.execute(sql, (uri, )).fetchall()

        if len(rows) == 0:
            err_msg = self.localized_resource_obj.get_error_msg(911)
            err_msg = err_msg.format(uri=uri)
            raise SquirrelError(err_msg, 911)

        if len(rows) > 1:
            err_msg = self.localized_resource_obj.get_error_msg(912)
            err_msg = err_msg.format(uri=uri)
            raise SquirrelError(err_msg, 912)

        asset_parent_d, asset_n = rows[0]

        return asset_parent_d, asset_n
Ejemplo n.º 4
0
    def make_repo(self, repo_d):
        """
        Given a path, creates a new repo out of this path by blessing the directory structure. Automatically adds the
        new repo to the list of existing repos.

        :param repo_d:
                The path to the directory structure that should be made into a repo.

        :return:
                Nothing.
        """

        if not os.path.isdir(repo_d):
            err_msg = self.localized_resource_obj.get_error_msg(100)
            err_msg = err_msg.format(dir=repo_d)
            raise SquirrelError(err_msg, 100)

        repo_obj = Repo(repo_root_d=repo_d,
                        cache_obj=self.cache_obj,
                        config_obj=self.config_obj,
                        localized_resource_obj=self.localized_resource_obj)

        # Make sure the repo name is not already taken
        if repo_obj.repo_n in self.repos.keys(
        ) and repo_d != self.repos[repo_obj.repo_n].repo_root_d:
            err_msg = self.localized_resource_obj.get_error_msg(303)
            err_msg = err_msg.format(repo_name=repo_d)
            raise SquirrelError(err_msg, 303)

        self.repos[repo_obj.repo_n] = repo_obj
        self.bless_repo(repo_obj.repo_n)
Ejemplo n.º 5
0
    def _load_repo(self, repo_p):
        """
        Loads a single repo given a path. If the path given does not point to a valid repo dir, an error will be raised.

        :param repo_p:
                The path to the repo to load. The path must exist and must be a valid repo. Raises an error if not.

        :return:
                Nothing.
        """

        assert type(repo_p) is str

        if not os.path.exists(repo_p) or not os.path.isdir(repo_p):
            err_msg = self.localized_resource_obj.get_error_msg(302)
            err_msg = err_msg.format(repo_path=repo_p)
            raise SquirrelError(err_msg, 302)

        repo_obj = Repo(repo_root_d=repo_p,
                        cache_obj=self.cache_obj,
                        config_obj=self.config_obj,
                        localized_resource_obj=self.localized_resource_obj)

        if not repo_obj.is_repo():
            err_msg = self.localized_resource_obj.get_error_msg(301)
            err_msg = err_msg.format(repo_path=repo_p)
            raise SquirrelError(err_msg, 301)

        self.repos[repo_obj.repo_n] = repo_obj
Ejemplo n.º 6
0
    def add_repo(self, repo_d):
        """
        Adds the repo to the dictionary of repos as well as to the config file.

        :param repo_d:
                The path to the repository. Must be a blessed root path. Note: if the name of this directory is the same
                as an existing repo, an error will be raised.

        :return:
                Nothing.
        """

        assert os.path.isdir(repo_d)

        repo_obj = Repo(repo_root_d=repo_d,
                        cache_obj=self.cache_obj,
                        config_obj=self.config_obj,
                        localized_resource_obj=self.localized_resource_obj)

        # Make sure the repo name is not already taken
        if repo_obj.repo_n in self.repos.keys(
        ) and repo_d != self.repos[repo_obj.repo_n].repo_root_d:
            err_msg = self.localized_resource_obj.get_error_msg(303)
            err_msg = err_msg.format(repo_name=repo_d)
            raise SquirrelError(err_msg, 303)

        # Make sure the path points to a valid, blessed repo
        if not repo_obj.is_repo():
            err_msg = self.localized_resource_obj.get_error_msg(301)
            err_msg = err_msg.format(repo_path=repo_d)
            raise SquirrelError(err_msg, 301)

        self.repos[repo_obj.repo_n] = repo_obj
Ejemplo n.º 7
0
    def _verify_thumbnail_paths(self, thumbnail_paths):
        """
        Raises an error if any of the thumbnail files are missing or are actually directories (vs. files).

        :param thumbnail_paths:
                The list of full paths to the thumbnail files.

        :return:
                Nothing.
        """

        assert type(thumbnail_paths) is list
        for thumbnail_path in thumbnail_paths:
            assert type(thumbnail_path) is str

        for thumbnail in thumbnail_paths:

            if not os.path.exists(thumbnail):
                err_msg = self.localized_resource_obj.get_error_msg(11209)
                err_msg = err_msg.format(path=thumbnail)
                raise SquirrelError(err_msg, 11209)

            if os.path.isdir(thumbnail):
                err_msg = self.localized_resource_obj.get_error_msg(11300)
                raise SquirrelError(err_msg, 11300)
Ejemplo n.º 8
0
    def _validate_pin_name(self, pin_n):
        """
        Pin names may not be one of the following reserved names: thumbnaildata, data.
        Pin names may not begin with a ".". Pin names may not end with "_locked".

        :param pin_n:
                Then name of the pin.

        :return:
                Nothing.
        """

        assert type(pin_n) is str

        if pin_n[0] == ".":
            err_msg = self.localized_resource_obj.error(11112)
            err_msg = err_msg.format(pin=pin_n)
            raise SquirrelError(err_msg, 11112)

        if pin_n.upper() in ["THUMBNAILDATA", "DATA"]:
            err_msg = self.localized_resource_obj.get_error_msg(11103)
            err_msg = err_msg.format(pin=pin_n)
            raise SquirrelError(err_msg, 11103)

        if pin_n.upper().endswith("_LOCKED"):
            err_msg = self.localized_resource_obj.get_error_msg(11111)
            raise SquirrelError(err_msg, 11111)
Ejemplo n.º 9
0
    def _cache_posters(self, asset_id):
        """
        Finds all the posters for all versions and pins and caches them.

        :param asset_id:
                The asset id for the asset for which we are caching the posters.

        :return:
                Nothing.
        """

        sql = self.sql_resources.get("cache_posters", "asset_obj_from_id")
        rows = self.cursor.execute(sql, (asset_id, )).fetchall()

        if len(rows) == 0:
            err_msg = self.localized_resource_obj.get_error_msg(913)
            raise SquirrelError(err_msg, 913)

        if len(rows) > 1:
            err_msg = self.localized_resource_obj.get_error_msg(914)
            raise SquirrelError(err_msg, 914)

        parent_d, asset_n = rows[0]

        asset_obj = Asset(asset_parent_d=parent_d,
                          name=asset_n,
                          config_obj=self.config_obj,
                          localized_resource_obj=self.localized_resource_obj)

        version_ints = asset_obj.version_objs.keys()
        pins_n = asset_obj.pin_objs.keys()

        for version_int in version_ints:
            poster_p = asset_obj.list_poster(version_int)
            if not poster_p:
                poster_p = ""
            self._cache_poster(version_int=version_int,
                               poster_p=poster_p,
                               asset_id=asset_id)

        for pin_n in pins_n:
            version_int = asset_obj.pin_objs[pin_n].version_int
            poster_p = asset_obj.list_poster(version_int)
            if not poster_p:
                poster_p = ""
            # TODO: How to cache this with a pin name
            self._cache_poster(version_int=pin_n,
                               poster_p=poster_p,
                               asset_id=asset_id)

        self.connection.commit()
Ejemplo n.º 10
0
    def _cache_thumbnails(self, asset_id):
        """
        Finds all the thumbnails for all versions and pins and caches them.

        :param asset_id:
                The asset id for the asset for which we are caching the thumbnails.

        :return:
                Nothing.
        """

        sql = self.sql_resources.get("cache_thumbnails", "asset_obj_from_id")
        rows = self.cursor.execute(sql, (asset_id, )).fetchall()

        if len(rows) == 0:
            err_msg = self.localized_resource_obj.get_error_msg(913)
            raise SquirrelError(err_msg, 913)

        if len(rows) > 1:
            err_msg = self.localized_resource_obj.get_error_msg(914)
            raise SquirrelError(err_msg, 914)

        parent_d, asset_n = rows[0]

        asset_obj = Asset(asset_parent_d=parent_d,
                          name=asset_n,
                          config_obj=self.config_obj,
                          localized_resource_obj=self.localized_resource_obj)

        version_ints = asset_obj.version_objs.keys()
        pins_n = asset_obj.pin_objs.keys()

        for version_int in version_ints:
            framespec_obj = Framespec()
            framespec_obj.files = asset_obj.list_thumbnails(version_int)
            thumbnails_p = framespec_obj.framespec_str
            self._cache_thumbnail(version_int=version_int,
                                  thumbnail_p=thumbnails_p,
                                  asset_id=asset_id)

        for pin_n in pins_n:
            version_int = asset_obj.pin_objs[pin_n].version_int
            framespec_obj = Framespec()
            framespec_obj.files = asset_obj.list_thumbnails(version_int)
            thumbnails_p = framespec_obj.framespec_str
            # TODO: Version_int cannot store pin_n
            self._cache_thumbnail(version_int=pin_n,
                                  thumbnail_p=thumbnails_p,
                                  asset_id=asset_id)

        self.connection.commit()
Ejemplo n.º 11
0
def validate_config(config_obj, localized_resource_obj, validation_dict):
    """
    Makes sure the config file is valid. Raises an asset error if not.

    :param config_obj:
            The config object responsible for managing preferences.
    :param localized_resource_obj:
            The localization object responsible for managing localized strings.
    :param validation_dict:
            A dictionary where the key is the section that must exist. The value may be None which indicates that there
            is no defined set of options in the section (in other words, the section must exist, but it can have any
            content - or even no content).

            If there are defined items that must exist in the section then the value must be in the form of:

            [(option name1, data type), (option name2, data type), etc.]

            For example:

            {"asset_settings": [("auto_create_default_pin", "bool"), ("default_pin_name", "str")]}

            This means there must be a section called "asset_settings" and it must have two options in it:
            auto_create_default_pin (type boolean) and default_pin_name (type string).

    :return:
           Nothing.
    """

    failures = config_obj.validate(validation_dict)

    if failures:
        if failures[1] is None:
            err_msg = localized_resource_obj.get_error_msg(501)
            err_msg = err_msg.format(config_p=config_obj.config_path,
                                     section=failures[0])
            raise SquirrelError(err_msg, 501)
        else:
            if failures[2] is None:
                err_msg = localized_resource_obj.get_error_msg(502)
                err_msg = err_msg.format(config_p=config_obj.config_path,
                                         setting=failures[1],
                                         section=failures[0])
                raise SquirrelError(err_msg, 502)
            else:
                err_msg = localized_resource_obj.get_error_msg(504)
                err_msg = err_msg.format(config_p=config_obj.config_path,
                                         setting=failures[1],
                                         section=failures[0],
                                         datatype=failures[2])
                raise SquirrelError(err_msg, 504)
Ejemplo n.º 12
0
    def _verify_thumbnail_names(self, thumbnail_paths):
        """
        Raises an error if any of the thumbnail files has an incorrect name, or the frame range is not contiguous,
        starting from 1.

        The name format that the thumbnails must match is: asset_name.###.ext where:

        1) asset_name exactly matches the name of the asset
        2) ### is a frame sequence number of any length (does not have to be padded to 3 digits)
        3) ext is any valid image file extension.

        :param thumbnail_paths:
                The list of full paths to the thumbnail files.

        :return:
                Nothing.
        """

        assert type(thumbnail_paths) is list
        for thumbnail_path in thumbnail_paths:
            assert type(thumbnail_path) is str

        pattern = r"(.+)\.([0-9]+)\.(.+)"

        frame_numbers = list()

        for thumbnail_p in thumbnail_paths:

            thumbnail_n = os.path.split(thumbnail_p)[1]
            result = re.match(pattern, thumbnail_n)

            if result is None:
                err_msg = self.localized_resource_obj.get_error_msg(11006)
                err_msg = err_msg.format(thumbnail_file=thumbnail_n,
                                         basename=self.asset_n)
                raise SquirrelError(err_msg, 11006)

            if result.groups()[0] != self.asset_n:
                err_msg = self.localized_resource_obj.get_error_msg(11006)
                err_msg = err_msg.format(thumbnail_file=thumbnail_n,
                                         basename=self.asset_n)
                raise SquirrelError(err_msg, 11006)

            frame_numbers.append(int(result.groups()[1]))

        frame_numbers.sort()
        if frame_numbers != list(range(1, len(frame_numbers) + 1)):
            err_msg = self.localized_resource_obj.get_error_msg(11301)
            raise SquirrelError(err_msg, 11301)
Ejemplo n.º 13
0
def create_repo_list_object(localized_resource_obj, repo_list_p=None):
    """
    Create a repo list object.

    :param localized_resource_obj:
            The localization object responsible for managing localized strings.
    :param repo_list_p:
            If provided, this path will be used instead of any provided by an env variable or the default repo list
            file location. If None, then the repo list file will be read from the path given by the env variable or,
            if that is not set, from the default location. Defaults to None.

    :return:
            A repo list object.
    """

    assert repo_list_p is None or type(repo_list_p) is str

    if repo_list_p is None:
        if REPO_LIST_PATH_ENV_VAR in os.environ.keys():
            repo_list_p = os.environ[REPO_LIST_PATH_ENV_VAR]
        else:
            module_d = os.path.split(inspect.stack()[0][1])[0]
            repo_list_p = os.path.join(module_d, "..", "..", "..", "config",
                                       "repos")

    if not os.path.exists(repo_list_p):
        err_msg = localized_resource_obj.get_error_msg(603)
        err_msg = err_msg.format(repo_list_file=repo_list_p)
        raise SquirrelError(err_msg, 603)

    repo_list_obj = Config(repo_list_p)
    validate_repo_list(repo_list_obj, localized_resource_obj)

    return repo_list_obj
Ejemplo n.º 14
0
    def set_poster_frame(self, poster_p):
        """
        Sets the poster frame for the thumbnails.

        :param poster_p:
                The path to the poster frame.

        :return:
                Nothing.
        """

        assert type(poster_p) is str

        self._verify_thumbnail_paths([poster_p])

        ext = os.path.splitext(poster_p)[1]
        try:
            copydescriptors = bvzversionedfiles.single_file_to_copydescriptors(
                file_p=poster_p,
                relative_d="",
                dest_n="poster" + ext,
                link_in_place=False)
        except ValueError as e:
            err_msg = self.localized_resource_obj.get_error_msg(50002)
            raise SquirrelError(f"{err_msg}: {str(e)}", 50002)

        bvzversionedfiles.copy_files_deduplicated(
            copydescriptors=copydescriptors,
            dest_d=self.thumbnail_d,
            data_d=self.thumbnail_data_d,
            ver_prefix="sqv",
            num_digits=4,
            do_verified_copy=False)
Ejemplo n.º 15
0
    def uri_path_from_asset_name(self, repo_n, asset_n):
        """
        Given a uri_path, validate it against the cache. If it is not valid, raise an error. If it is valid, return the
        uri_path.

        :param repo_n:
                The repo name.
        :param asset_n:
                The asset name.

        :return:
                The uri path.
        """

        sql = self.sql_resources.get("disambiguate_uri", "asset_name_exists")
        rows = self.cursor.execute(sql, (repo_n, asset_n)).fetchall()

        # If no assets match this name, raise an error
        if len(rows) == 0:
            err_msg = self.localized_resource_obj.get_error_msg(905)
            err_msg = err_msg.format(repo_n=repo_n, asset_n=asset_n)
            raise SquirrelError(err_msg, 905)

        # If more than one asset matches this name, raise an error
        if len(rows) > 1:
            err_msg = self.localized_resource_obj.get_error_msg(906)
            err_msg = err_msg.format(repo_n=repo_n, asset_n=asset_n)
            raise SquirrelError(err_msg, 906)

        sql = self.sql_resources.get("disambiguate_uri",
                                     "get_uri_path_from_asset_n")
        rows = self.cursor.execute(sql, (repo_n, asset_n)).fetchall()

        # If no uri path match this asset name
        if len(rows) == 0:
            err_msg = self.localized_resource_obj.get_error_msg(908)
            err_msg = err_msg.format(asset_n=asset_n)
            raise SquirrelError(err_msg, 908)

        # If more than one uri paths match this name
        if len(rows) > 1:
            err_msg = self.localized_resource_obj.get_error_msg(909)
            err_msg = err_msg.format(asset_n=asset_n)
            raise SquirrelError(err_msg, 909)

        return rows[0][0]
Ejemplo n.º 16
0
    def _validate_asset_d(self):
        """
        Makes sure that the asset directory exists.
        """

        if not os.path.isdir(self.asset_d):
            err_msg = self.localized_resource_obj.get_error_msg(11208)
            err_msg = err_msg.format(asset_dir=self.asset_d)
            raise SquirrelError(err_msg, 11208)
Ejemplo n.º 17
0
def create_config_object(validation_dict,
                         localized_resource_obj,
                         config_p=None):
    """
    Create a config object.

    :param validation_dict:
            A dictionary where the key is the section that must exist. The value may be None which indicates that there
            is no defined set of options in the section (in other words, the section must exist, but it can have any
            content - or even no content).

            If there are defined items that must exist in the section then the value must be in the form of:

            [(option name1, data type), (option name2, data type)]

            For example:

            {"asset_settings": [("auto_create_default_pin", "bool"), ("default_pin_name", "str")]}

            This means there must be a section called "asset_settings" and it must have two options in it:
            auto_create_default_pin (type boolean) and default_pin_name (type string).
    :param localized_resource_obj:
            The localization object responsible for managing localized strings.
    :param config_p:
            If provided, this path will be used instead of any provided by an env variable or the default config
            file location. If None, then the config file will be read from the path given by the env variable or,
            if that is not set, from the default location. Defaults to None.

    :return:
            A config object.
    """

    assert config_p is None or type(config_p) is str
    assert type(validation_dict) is dict

    if config_p is None:
        if CONFIG_PATH_ENV_VAR in os.environ.keys():
            config_p = os.environ[CONFIG_PATH_ENV_VAR]
        else:
            module_d = os.path.split(inspect.stack()[0][1])[0]
            config_p = os.path.abspath(
                os.path.join(module_d, "..", "..", "..", "config",
                             "squirrel.config"))

    if not os.path.exists(config_p):
        err_msg = localized_resource_obj.get_error_msg(503)
        err_msg = err_msg.format(config=config_p)
        raise SquirrelError(err_msg, 503)

    config_obj = Config(config_p)
    validate_config(config_obj=config_obj,
                    localized_resource_obj=localized_resource_obj,
                    validation_dict=validation_dict)

    return config_obj
Ejemplo n.º 18
0
    def _verify_metadata_dir_exists(self):
        """
        Checks to make sure the metadata directory exists.

        :return:
                Nothing.
        """

        if not os.path.exists(os.path.join(self.asset_d, ".metadata")):
            err_msg = self.localized_resource_obj.get_error_msg(10010)
            raise SquirrelError(err_msg, 10010)
Ejemplo n.º 19
0
    def _verify_key_value_file_exists(self):
        """
        Checks to make sure the key value file exists.

        :return:
                Nothing.
        """

        if not os.path.exists(self.keyvalues_p):
            err_msg = self.localized_resource_obj.get_error_msg(11109)
            raise SquirrelError(err_msg, 11109)
Ejemplo n.º 20
0
    def _verify_asset_dir_exists(self):
        """
        Checks to make sure the asset directory exists.

        :return:
                Nothing.
        """

        if not os.path.exists(self.asset_d):
            err_msg = self.localized_resource_obj.get_error_msg(11208)
            raise SquirrelError(err_msg, 11208)
Ejemplo n.º 21
0
    def _validate_pin_exists(self):
        """
        Raises an error if the pin does not exist on disk.

        :return:
                Nothing.
        """

        if not self.exists():
            err_msg = self.localized_resource_obj.get_error_msg(11002)
            err_msg = err_msg.format(pin=self.pin_n)
            raise SquirrelError(err_msg, 11002)
Ejemplo n.º 22
0
    def _validate_cache_d(self):
        """
        Raises an error if cache_d is missing or not a directory.

        :return:
                Nothing.
        """

        if not os.path.isdir(self.cache_d):
            err_msg = self.localized_resource_obj.get_error_msg(800)
            err_msg = err_msg.format(cache_dir=self.cache_d)
            raise SquirrelError(err_msg, 800)
Ejemplo n.º 23
0
    def _validate_exists(self):
        """
        Validates that a version string references an actual, existing version on disk. Raises an error if the version
        does not properly validate.

        :return:
                Nothing.
        """

        if not self.exists():
            err_msg = self.localized_resource_obj.get_error_msg(11000)
            err_msg = err_msg.format(version=self.version_str)
            raise SquirrelError(err_msg, 11000)
Ejemplo n.º 24
0
    def _validate_max_version_value(self):
        """
        If the version int is greater than the max number of possible versions, raise an error.

        :return:
                Nothing.
        """

        max_versions = (10**VERSION_NUM_DIGITS) - 1

        if self.version_int > max_versions:
            err_msg = self.localized_resource_obj.get_error_msg(11004)
            err_msg = err_msg.format(max=max_versions)
            raise SquirrelError(err_msg, 11004)
Ejemplo n.º 25
0
    def _load_repos(self, repos):
        """
        Loads all of the repos given in the list repos. Kicks up an error if any are missing or corrupt AND
        warn_on_load_error OR fail_on_load_error is set to True in the config file.

        :param repos:
                A list of full paths to the repos to be loaded.

        :return:
                Nothing.
        """

        assert type(repos) is list

        warn_on_load_error = self.config_obj.get_boolean(
            "repo_settings", "warn_on_load_error")
        fail_on_load_error = self.config_obj.get_boolean(
            "repo_settings", "fail_on_load_error")

        for repo_path in repos:
            try:
                self._load_repo(repo_p=repo_path)
            except SquirrelError as e:
                if e.code in [301, 302]:
                    if fail_on_load_error:
                        err_msg = self.localized_resource_obj.get_error_msg(
                            310)
                        err_msg = err_msg.format(message=str(e))
                        raise SquirrelError(err_msg, 310)
                    if warn_on_load_error:  # <- rely on upstream to check the code and not actually quit.
                        err_msg = self.localized_resource_obj.get_error_msg(
                            311)
                        err_msg = err_msg.format(message=str(e))
                        raise SquirrelError(err_msg, 311)
                else:
                    raise
Ejemplo n.º 26
0
    def repo_obj_from_uri(self, uri):
        """
        Given a URI, return a repo object.

        :param uri:
                The URI.

        :return:
                A repo object.
        """

        if not urilib.validate_uri_format(uri):
            err_msg = self.localized_resource_obj.get_error_msg(201)
            err_msg = err_msg.format(uri=uri)
            raise SquirrelError(err_msg, 201)

        repo_n = urilib.repo_name_from_uri(uri)

        try:
            return self.repos[repo_n]
        except KeyError:
            err_msg = self.localized_resource_obj.get_error_msg(304)
            err_msg = err_msg.format(repo_name=repo_n)
            raise SquirrelError(err_msg, 304)
Ejemplo n.º 27
0
    def _create_version_dir(self):
        """
        Creates the version directory on disk.

        :return:
                Nothing.
        """

        try:
            os.mkdir(self.version_d)
        except OSError as e:
            if e.errno == errno.EEXIST and os.path.isdir(self.version_d):
                return
            else:
                err_msg = self.localized_resource_obj.get_error_msg(1234)
                err_msg = err_msg.format(version_p=self.version_d)
                raise SquirrelError(err_msg, 1234)
Ejemplo n.º 28
0
    def _create_thumbnails_dir(self):
        """
        Creates the "thumbnails" directory on disk.

        :return:
                Nothing.
        """

        try:
            os.mkdir(os.path.join(self.version_metadata_d, "thumbnails"))
        except OSError as e:
            if e.errno == errno.EEXIST and os.path.isdir(self.version_metadata_d):
                return
            else:
                err_msg = self.localized_resource_obj.get_error_msg(1234)
                err_msg = err_msg.format(metadata_p=self.version_metadata_d)
                raise SquirrelError(err_msg, 1234)
Ejemplo n.º 29
0
    def set_default_repo(self, repo_n):
        """
        Sets the default repository.

        :param repo_n:
                The name of the default repo. This repo must exist in the list of current repos.

        :return:
        """

        assert type(repo_n) is str and repo_n

        # The target repo must exist in the list of repos
        if repo_n not in self.repos.keys():
            err_msg = self.localized_resource_obj.get_error_msg(102)
            err_msg = err_msg.format(repo_name=repo_n)
            raise SquirrelError(err_msg, 102)

        self.default_repo = self.repos[repo_n].repo_n
Ejemplo n.º 30
0
    def unload_repo(self, repo_n):
        """
        Unloads a single repo.

        :param repo_n:
                The name of the repo to unload.

        :return:
                Nothing.
        """

        assert type(repo_n) is str and repo_n

        if repo_n not in self.repos.keys():
            err_msg = self.localized_resource_obj.get_error_msg(102)
            err_msg = err_msg.format(repo_name=repo_n)
            raise SquirrelError(err_msg, 102)

        del (self.repos[repo_n])