コード例 #1
0
    def get_latest_published_versions(self, shot_path, file_type=None):
        """
        Returns all published version of the the different files of the given shot
        :param shot_path: str, path of the shot
        :param file_type: str, if given only paths of the given file type will be returned (model, rig, etc)
        :return: list(dict), number of version, name of version and version path
        """

        latest_version = list()

        versions = dict()
        status = artellalib.get_status(shot_path, as_json=True)

        status_data = status.get('data')
        if not status_data:
            LOGGER.info(
                'Impossible to retrieve data from Artella in file: "{}"'.
                format(shot_path))
            return

        for name, data in status_data.items():
            if name in ['latest', '_latest']:
                continue
            if file_type and file_type not in name:
                continue
            try:
                version = artellalib.split_version(name)[1]
                versions[version] = name
            except Exception as exc:
                pass

        ordered_versions = OrderedDict(sorted(versions.items()))

        current_index = -1
        valid_version = False
        version_found = None
        while not valid_version and current_index >= (len(ordered_versions) *
                                                      -1):
            version_found = ordered_versions[ordered_versions.keys()
                                             [current_index]]
            valid_version = self._check_valid_published_version(
                shot_path, version_found)
            if not valid_version:
                current_index -= 1
        if valid_version and version_found:
            version_path = path_utils.clean_path(
                os.path.join(shot_path, '__{}__'.format(version_found)))
            latest_version.append({
                'version':
                ordered_versions.keys()[current_index],
                'version_name':
                version_found,
                'version_path':
                version_path
            })

        return latest_version
コード例 #2
0
ファイル: abstract.py プロジェクト: ArtellaPipe/artellapipe
    def get_artella_data(self, force_update=False):
        """
        Retrieves status data of the asset from Artella
        :param force_update: bool, Whether to resync data if it is already synced
        :return: ArtellaAssetMetaData
        """

        if not force_update and self._artella_data:
            return self._artella_data

        self._artella_data = artellalib.get_status(file_path=self.get_path())

        return self._artella_data
コード例 #3
0
    def _get_latest_published_versions_indie(self, asset_path, file_type=None):
        """
        Internal function that implements get_latest_published_versions for Artella Indie
        """

        latest_version = list()

        versions = dict()
        status = artellalib.get_status(asset_path, as_json=True)

        status_data = status.get('data')
        if not status_data:
            LOGGER.info(
                'Impossible to retrieve data from Artella in file: "{}"'.
                format(asset_path))
            return

        for name, data in status_data.items():
            if name in ['latest', '_latest']:
                continue
            if file_type and file_type not in name:
                continue
            version = artellalib.split_version(name)[1]
            versions[version] = name

        ordered_versions = OrderedDict(sorted(versions.items()))

        current_index = -1
        valid_version = False
        version_found = None
        while not valid_version and current_index >= (len(ordered_versions) *
                                                      -1):
            version_found = ordered_versions[ordered_versions.keys()
                                             [current_index]]
            valid_version = self._check_valid_published_version(
                asset_path, version_found)
            if not valid_version:
                current_index -= 1
        if valid_version and version_found:
            version_path = path_utils.clean_path(
                os.path.join(asset_path, '__{}__'.format(version_found)))
            latest_version.append({
                'version':
                ordered_versions.keys()[current_index],
                'version_name':
                version_found,
                'version_path':
                version_path
            })
コード例 #4
0
    def _check_valid_published_version(self, file_path, version):
        """
        Returns whether the given version is a valid one or not
        :return: bool
        """

        version_valid = True
        version_path = os.path.join(file_path, '__{}__'.format(version))
        version_info = artellalib.get_status(version_path)
        if version_info:
            if isinstance(version_info, artellaclasses.ArtellaHeaderMetaData):
                version_valid = False
            else:
                for n, d in version_info.references.items():
                    if d.maximum_version_deleted and d.deleted:
                        version_valid = False

        return version_valid
コード例 #5
0
    def _get_published_data(self, check_validity=True):
        """
        Internal function that caches the published data of the asset if that info is not already cached
        """

        from artellapipe.libs.artella.core import artellalib

        self._published_folders = dict()
        self._published_folders_all = dict()
        self._latest_published_folders = dict()

        # for f in self._must_folders:
        #     self._published_folders[f] = dict()
        #     self._published_folders_all[f] = dict()

        # Retrieve asset published data
        for name, data in self._dict['data'].items():
            if name == '_latest' or name == 'latest':
                continue

            # Before doing nothing, check if the published version is valid (has not been deleted from Artella manually)
            version_valid = True

            if check_validity:
                # NOTE: This checks if a version has been deleted or not
                # NOTE: The problem is that this checking is too time consuming.
                # TODO: Find a better way to check this
                # TODO: (maybe get latest version first and check deletion to first version)
                version_path = os.path.join(self._path, '__{0}__'.format(name))
                version_info = artellalib.get_status(version_path)
                if version_info:
                    if isinstance(version_info, ArtellaHeaderMetaData):
                        version_valid = False
                    else:
                        for n, d in version_info.references.items():
                            if d.maximum_version_deleted and d.deleted:
                                version_valid = False
                                break
                else:
                    version_valid = False

            if version_valid:
                self._published_folders[name] = list()

            self._published_folders_all[name] = list()

            # Store all valid published folders
            split_version = artellalib.split_version(name)
            version = split_version[1]
            version_file_name = name.replace('_v{}'.format(split_version[2]),
                                             '')
            name_version = '__{0}__'.format(name)
            self._published_folders_all[name].append(
                (str(version), name_version,
                 os.path.join(self.path, name_version)))
            if version_valid:
                self._published_folders[name].append(
                    (str(version), name_version,
                     os.path.join(self.path, name_version)))
                if version_file_name not in self._latest_published_folders or version > \
                        int(self._latest_published_folders[version_file_name][0][0]):
                    self._latest_published_folders[version_file_name] = [
                        (str(version), name_version,
                         os.path.join(self.path, name_version))
                    ]