Example #1
0
    def _get_available_modules(self, paths=None):
        imports = list()
        if not paths:
            paths = sys.path
        if paths:
            paths = python.force_list(paths)

        for path in paths:
            fix_path = path_utils.normalize_path(path)
            if not path.is_dir(fix_path):
                continue
            folders = folder_utils.get_folders(fix_path)
            for folder in folders:
                folder_path = path_utils.join_path(fix_path, folder)
                files = folder_utils.get_files_with_extension('py',
                                                              folder_path,
                                                              full_path=False)
                if '__init__.py' in files:
                    imports.append(str(folder))

            python_files = folder_utils.get_files_with_extension(
                'py', fix_path, full_path=False)
            for python_file in python_files:
                if python_file.startswith('__'):
                    continue
                python_file_name = python_file.split('.')[0]
                imports.append(str(python_file_name))

        if imports:
            imports = list(set(imports))

        return imports
Example #2
0
    def _on_import_alembic(self, as_reference=False):
        """
        Internal callback function that is called when Import/Reference Alembic button is clicked
        :param as_reference: bool
        """

        abc_file = self._alembic_path_line.text()
        if not abc_file or not os.path.isfile(abc_file):
            tp.Dcc.confirm_dialog(
                title='Error',
                message=
                'No Alembic File is selected or file is not currently available in disk'
            )
            return None

        abc_name = os.path.basename(abc_file).split('.')[0]
        tag_json_file = os.path.join(
            os.path.dirname(abc_file),
            os.path.basename(abc_file).replace('.abc', '_abc.info'))
        valid_tag_info = True
        if os.path.isfile(tag_json_file):
            with open(tag_json_file, 'r') as f:
                tag_info = json.loads(f.read())
            if not tag_info:
                LOGGER.warning('No Alembic Info loaded!')
                valid_tag_info = False
        else:
            LOGGER.warning('No Alembic Info file found!')
            valid_tag_info = False

        if as_reference:
            reference_nodes = self._reference_alembic(alembic_file=abc_file,
                                                      namespace=abc_name)
        else:
            reference_nodes = self._import_alembic(
                alembic_file=abc_file, valid_tag_info=valid_tag_info)
        reference_nodes = python.force_list(reference_nodes)

        added_tag = False
        for key in tag_info.keys():
            if reference_nodes:
                for obj in reference_nodes:
                    short_obj = tp.Dcc.node_short_name(obj)
                    if key == short_obj:
                        self._add_tag_info_data(self._project, tag_info[key],
                                                obj)
                        added_tag = True

        if not added_tag:
            self._add_tag_info_data(self._project, tag_info,
                                    reference_nodes[0])

        if reference_nodes:
            if as_reference:
                self.showOk.emit('Alembic file referenced successfully!')
            else:
                self.showOk.emit('Alembic file imported successfully!')

        return reference_nodes
Example #3
0
    def set_accepted_files(self, list_files):

        list_files = python.force_list(list_files)

        for f in list_files:
            if not f.startswith('.'):
                f = '.' + f
            self._accepted_files.append(f)
Example #4
0
    def remove(self, objects):
        """
        Removes the given objecst from the transfer object
        :param objects: str or list(str)
        """

        objects = python.force_list(objects)

        for obj in objects:
            del self.objects()[obj]
Example #5
0
    def add(self, objects):
        """
        Adds the given objects to the transfer object
        :param objects: str or list(str)
        """

        objects = python.force_list(objects)

        for name in objects:
            self.objects()[name] = self.create_object_data(name)
Example #6
0
def get_file(directory, parent=None):
    """
    Show a open file dialog
    :param directory: str, root directory
    :param parent: QWidget
    :return: str, selected folder or None if no folder is selected
    """

    file_dialog = QFileDialog(parent)
    if directory:
        file_dialog.setDirectory(directory)
    directory = file_dialog.getOpenFileName()
    directory = python.force_list(directory)
    if directory:
        return directory
Example #7
0
    def set(self, breadcrumbs):
        """
        Populates the breadcrumb control with a list of breadcrumbs
        :param breadcrumbs: each breadcrumb should derive from Breadcrumb class
        """

        breadcrumbs = python.force_list(breadcrumbs)
        self._widgets = list()
        for b in breadcrumbs:
            if not isinstance(b, Breadcrumb):
                if type(b) in [str, unicode]:
                    self._widgets.append(Breadcrumb(b))
                else:
                    tp.logger.warning('Impossible to convert {} to Breadcrumb'.format(b))
            else:
                self._widgets.append(b)

        path = "<span style='color:#E2AC2C'> &#9656; </span>".join([crumb.label for crumb in self._widgets])
        path = "<big>%s</big>" % path

        self._path_label.setText(path)
Example #8
0
    def save(self, asset_files, override_files):
        """
        Saves shot file
        :param asset_files: list
        :param override_files: list
        :return: bool
        """

        asset_files = python.force_list(asset_files)
        override_files = python.force_list(override_files)

        shot_data = {
            'data_version': self._project.DataVersions.SHOT,
            'assembler_version': ShotAssembler.VERSION,
            'root': '',
            'files': {},
            'overrides': {}
        }

        # Store Asset Files
        for asset_file in asset_files:
            asset_file_path = asset_file.asset_file
            if not os.path.isfile(asset_file_path):
                logger.warning(
                    'Asset File {} does not exists!'.format(asset_file_path))
                continue
            rel_path = os.path.relpath(asset_file_path,
                                       os.path.dirname(self._file_path))

            project_path = os.path.relpath(asset_file_path,
                                           self._project.get_path())
            shot_data['files'][project_path] = dict()
            shot_data['files'][project_path]['...'] = '<{}>'.format(rel_path)

        # Store Override Files
        for override_file in override_files:
            override_file_path = override_file.file_path
            if not override_file_path or not os.path.isfile(
                    override_file_path):
                logger.warning('Override File {} does not exists!'.format(
                    override_file_path))
                continue
            rel_path = os.path.relpath(override_file_path,
                                       os.path.dirname(self._file_path))
            override_name = os.path.basename(
                os.path.relpath(override_file_path, self._project.get_path()))
            if override_name in shot_data['overrides']:
                logger.warning(
                    'Override {} is already stored. Skipping ...!'.format(
                        override_name))
            shot_data['overrides'][override_name] = dict()
            shot_data['overrides'][override_name]['...'] = '<{}>'.format(
                rel_path)

        # We update data taking into account root shot data
        if self._root:
            root_rel_path = os.path.relpath(self._root,
                                            os.path.dirname(self._file_path))
            shot_data['root'] = root_rel_path

            # if not os.path.isfile(self._root):
            #     artellapipe.logger.warning('Root Shot File does not exists: "{}"!'.format(self._root))
            #     return dict()
            # root_data = ShotFile(project=self._project, file_path=self._root).load()
            # if not root_data:
            #     artellapipe.logger.warning('Root Shot File "{}" has not data!'.format(self._root))
            #     return dict()
            #
            # root_files = root_data.get('files', dict())
            # root_overrides = root_data.get('overrides', dict())
            #
            # print('Root Files: {}'.format(root_files))
            # print('Root Overrides: {}'.format(root_overrides))

        try:
            with open(self._file_path, 'w') as f:
                json.dump(shot_data, f)
        except Exception as e:
            exceptions.capture_exception(e)
            logger.error('{} | {}'.format(e, traceback.format_exc()))