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) stuff_in_folder = folder_utils.get_files_and_folders(fix_path) for file_or_folder in stuff_in_folder: folder_path = path_utils.join_path(fix_path, file_or_folder) files = folder_utils.get_files_with_extension('py', folder_path, full_path=False) if '__init__.py' in files: imports.append(str(file_or_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
def get_version_numbers(self): """ Returns numbers of all versions :return: list<int> """ version_folder = self._get_version_folder() version_files = folder.get_files_and_folders(version_folder) if not version_files: LOGGER.warning( 'Impossible to get version numbers because no version exist!') return None number_list = list() for f in version_files: if not f.startswith(self._version_name): continue split_name = f.split('.') if split_name[1] == 'json' or split_name[ 1] == 'default' or not len(split_name) == 2: continue version_number = int(split_name[1]) number_list.append(version_number) number_list.sort() return number_list
def _get_files(self, directory=None): """ Internal function taht returns all files located in the given directory. If not directory is given, stored variable directory will be used :return: list<str> """ if not directory: directory = self._directory return folder.get_files_and_folders(directory)
def get_versions(self, return_version_numbers=False): """ Get file paths of all versions :param return_version_numbers: bool, Whether to return also version numbers or only paths :return: variant, list<str> | list<str>, list<int> """ version_folder = self._get_version_folder() version_files = folder.get_files_and_folders(version_folder) if not version_files: LOGGER.warning( 'Impossible to get versions because no version exist!') return None number_list = list() pass_files = list() for f in version_files: if not f.startswith(self._version_name): continue split_name = f.split('.') if not len(split_name) == 2: continue version_number = int(split_name[1]) number_list.append(version_number) pass_files.append(f) if not pass_files: LOGGER.warning('No valid version files found in folder: {}'.format( version_folder)) return quick_sort = sort.QuickNumbersListSort(number_list) quick_sort.set_follower_list(pass_files) pass_files = quick_sort.run() pass_dict = dict() for i in range(len(number_list)): pass_dict[pass_files[0][i]] = pass_files[1][i] if return_version_numbers: return pass_dict, pass_files[0] else: return pass_dict
def get_versions(self, return_version_numbers_also=False): """ Get file paths of all version :param return_version_numbers_also: Whether the number of the versions should be returned also :return: list """ from tpDcc.libs.python import folder, sort version_folder = self._get_version_folder() files = folder.get_files_and_folders(directory=version_folder) if not files: return None number_list = list() pass_files = list() for file_path in files: if not file_path.startswith(self.version_name): continue split_name = file_path.split('.') if not len(split_name) == 2: continue number = int(split_name[1]) number_list.append(number) pass_files.append(file_path) if not pass_files: return quick_sort = sort.QuickNumbersListSort(list_of_numbers=number_list) quick_sort.set_follower_list(pass_files) pass_files = quick_sort.run() pass_dict = dict() for i in range(len(number_list)): pass_dict[pass_files[0][i]] = pass_files[1][i] if not return_version_numbers_also: return pass_dict else: return pass_dict, pass_files[0]
def get_version_numbers(self): """ Return file version numbers of all versions :return: list<int>, list of version numbers """ from tpDcc.libs.python import folder version_folder = self._get_version_folder() files = folder.get_files_and_folders(directory=version_folder) if not files: return number_list = list() for file_path in files: if not file_path.startswith(self.version_name): continue split_name = file_path.split('.') if not len(split_name) == 2: continue num = int(split_name[1]) number_list.append(num) return number_list
def _add_item(self, file_name, parent=None): """ Function that adds given file into the tree :param file_name: str, name of the file new item will store :param parent: QTreeWidgetItem, parent item to append new item into :return: QTreeWidet, new item added """ try: self.blockSignals(True) self.clearSelection() finally: self.blockSignals(False) path_name = file_name found = False # Check if item exists if parent: parent_path = self.get_tree_item_path_string(parent) path_name = '{}/{}'.format(parent_path, file_name) for i in range(parent.childCount()): item = parent.child(i) if item.text(0) == file_name: found = item else: for i in range(self.topLevelItemCount()): item = self.topLevelItem(i) if item.text(0) == file_name: found = item # Check if the item should be excluded or not from the tree exclude = self.EXCLUDE_EXTENSIONS if exclude: split_name = file_name.split('.') extension = split_name[-1] if extension in exclude: return if found: item = found else: item = self.create_item_widget(file_name) # Constrain item size if necessary size = self.ITEM_WIDGET_SIZE if size: size = QSize(*size) item.setSizeHint(self._title_text_index, size) # Set item text item_path = path.join_path(self._directory, path_name) sub_files = folder.get_files_and_folders(item_path) item.setText(self._title_text_index, file_name) # Retrieve file properties if self.header().count() > 1: if path.is_file(item_path): size = fileio.get_file_size(item_path) date = fileio.get_last_modified_date(item_path) item.setText(self._title_text_index + 1, str(size)) item.setText(self._title_text_index + 2, str(date)) # Update valid sub files # NOTE: Sub files are added dynamically when the user expands an item if sub_files: self._delete_children(item) exclude_extensions = self.EXCLUDE_EXTENSIONS exclude_count = 0 if exclude_extensions: for f in sub_files: for exclude in exclude_extensions: if f.endswith(exclude): exclude_count += 1 break if exclude_count != len(sub_files): QTreeWidgetItem(item) # Add item to tree hierarchy if parent: parent.addChild(item) try: self.blockSignals(True) self.setCurrentItem(item) finally: self.blockSignals(False) else: self.addTopLevelItem(item) return item
def _get_scope_list(self): return folder.get_files_and_folders(directory=self.parent_path)