Skip to content

Commit

Permalink
fixed recursive download: nested level support
Browse files Browse the repository at this point in the history
  • Loading branch information
unbekanntes-pferd committed Jul 3, 2022
1 parent 52af790 commit 97b9b5a
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions dccmd/main/download/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def __init__(self, file_list: NodeList, folder_list: NodeList, node: Node, targe
self.folder_list = folder_list
self.node = node
self.target_path = target_path
print(self.base_level)

def get_level(self, level: int) -> list[DownloadDirectoryItem]:
"""get all directories in a depth level"""
Expand Down Expand Up @@ -79,7 +80,7 @@ def file_paths(self) -> list[str]:
@property
def folder_paths(self) -> list[str]:
""" returns all folder paths in alphabetical order """
return sorted([f"{node.parentPath}{node.name}" for node in self.folder_list.items])
return sorted([f"{normalize_parent_path(parent_path=node.parentPath, level=self.base_level)}{node.name}" for node in self.folder_list.items])

@property
def folder_items(self) -> list[DownloadDirectoryItem]:
Expand All @@ -89,13 +90,30 @@ def folder_items(self) -> list[DownloadDirectoryItem]:
@property
def file_items(self) -> list[DownloadFileItem]:
""" returns folder item including level """
return [DownloadFileItem(dir_path=f"{node.parentPath}{node.name}", base_path=self.target_path, node_info=node) for node in self.file_list.items]
return [DownloadFileItem(dir_path=f"{normalize_parent_path(parent_path=node.parentPath, level=self.base_level)}{node.name}",
base_path=self.target_path, node_info=node) for node in self.file_list.items]

@property
def levels(self):
""" returns levels """
return set([dir.level for dir in self.folder_items])

@property
def base_level(self):
""" return base level of the source container """
path_comp = self.node.parentPath.split("/")

if len(path_comp) == 2:
return 0
elif len(path_comp) >= 3:
return len(path_comp) - 2

def normalize_parent_path(parent_path: str, level: int):
""" remove parent path components if root on specific level """
path_comp = parent_path.split('/')
normalized_comp = path_comp[level+1:]
return "/" + "/".join(normalized_comp)


def create_folder(name: str, target_dir_path: str):
""" creates a folder in a target directory """
Expand Down

0 comments on commit 97b9b5a

Please sign in to comment.