Beispiel #1
0
    def move(self, target_path):
        current_path = self.format_identifier()

        before_identifiers = list()
        folders = folder.get_folders(current_path, recursive=True, full_path=True)
        files = folder.get_files(current_path, recursive=True, full_path=True)
        for file_folder in folders + files:
            before_identifiers.append(file_folder)

        valid = folder.move_folder(current_path, target_path)
        if not valid:
            return None

        self._db.move(current_path, target_path)

        after_identifiers = list()
        folders = folder.get_folders(target_path, recursive=True, full_path=True)
        files = folder.get_files(target_path, recursive=True, full_path=True)
        for file_folder in folders + files:
            after_identifiers.append(file_folder)

        for identifier, new_identifier in zip(before_identifiers, after_identifiers):
            self._db.move(identifier, new_identifier)

        return target_path
Beispiel #2
0
def register_package_configs(package_name, config_path, config_extension=None):
    """
    Tries to find and registers all configuration paths of given path and in the given path
    :param package_name: str
    :param config_path: str
    :param config_extension: str, extension used by the configuration file
    """

    config_extension = config_extension or 'yml'
    if not config_extension.startswith('.'):
        config_extension = '.{}'.format(config_extension)

    if not config_path or not os.path.isdir(config_path):
        return

    for environment in ['development', 'production']:
        config_files = folder.get_files(
            config_path, full_path=False, recursive=True, pattern='*{}'.format(config_extension))
        if not config_files:
            continue
        module_names = [os.path.splitext(file_path)[0] for file_path in config_files]
        for module_name in module_names:
            register_package_path(
                package_name=package_name, config_path=config_path, module_name=module_name, environment=environment,
                config_extension=config_extension)
Beispiel #3
0
def get_all_resources_of_type(resource_type, key=None):
    """
    Returns a list with all available resources of given type
    :param resource_type: str
    :param key: str
    :return: dict()
    """

    resources_found = list()

    resource_paths = get_resources_paths(key=key)
    if not resource_paths:
        return dict()

    for resource_path in resource_paths:
        resource_files = folder.get_files(resource_path, recursive=True)
        for res_name in resource_files:
            res_name_no_extension = os.path.splitext(res_name)[0]
            try:
                res_file = get(res_name_no_extension,
                               key=key,
                               resource_type=resource_type)
            except Exception:
                continue
            if res_file:
                resources_found.append(res_file)

    return resources_found
Beispiel #4
0
def clean_folder(directory):
    """
    Removes everything in the given directory
    :param directory: str
    """

    from tpDcc.libs.python import path, fileio, folder

    base_name = path.get_basename(directory=directory)
    dir_name = path.get_dirname(directory=directory)

    if path.is_dir(directory):
        files = folder.get_files(directory)
        for f in files:
            fileio.delete_file(f, directory)

        delete_folder(base_name, dir_name)

    if not path.is_dir(directory):
        create_folder(base_name, dir_name)