Skip to content

Commit

Permalink
Merge pull request #15 from unbekanntes-pferd/bugfixes/0.4.1
Browse files Browse the repository at this point in the history
bugfixes/0.4.1
  • Loading branch information
unbekanntes-pferd authored May 2, 2023
2 parents 06317b8 + 5c398bb commit 03e6404
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 125 deletions.
4 changes: 2 additions & 2 deletions dccmd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""

__version__ = "0.4.0-SNAPSHOT"
__version__ = "0.4.2-SNAPSHOT"

# std imports
import sys
Expand Down Expand Up @@ -936,7 +936,7 @@ def version():
"""

typer.echo(
"@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@ @@@@@@@@@ @@@@@@@@@ @@@@@@@@@@@@@@@@@@\n"
"@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@ @@@@@@@@@ @@@@@@@@@ @@@@@@@@@@@@@@@@@@\n"
"@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@ @@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@\n"
"@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@ @@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@\n"
"@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@ @@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@\n"
Expand Down
4 changes: 2 additions & 2 deletions dccmd/main/rooms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ async def _list_users():
csv_print_user_perms(user_permissions=user_permissions)
else:
pretty_print_user_perms(user_permissions=user_permissions)

await dracoon.logout()

asyncio.run(_list_users())
Expand Down Expand Up @@ -343,7 +343,7 @@ async def _list_groups():
csv_print_group_perms(group_permissions=group_permissions)
else:
pretty_print_group_perms(group_permissions=group_permissions)

await dracoon.logout()

asyncio.run(_list_groups())
Expand Down
8 changes: 4 additions & 4 deletions dccmd/main/rooms/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ async def add_room_group(room_id: int, name: str, permission_template: Permissio
permissions = create_permissions(permissions=permission_template, dracoon=dracoon)
#group_update = dracoon.nodes.make_permission_update(id=group.id, permission=permissions)
groups_update = UpdateRoomGroups(items=[UpdateRoomGroupItem(id=group.id, permissions=permissions)])
dracoon.logger.debug(groups_update)

try:
await dracoon.nodes.update_room_groups(room_id=room_id, groups_update=groups_update)
except HTTPForbiddenError:
Expand Down Expand Up @@ -276,8 +276,8 @@ def set_room_admin_perms(permissions: Permissions):
def create_permissions(permissions: PermissionTemplate, dracoon: DRACOON) -> Permissions:
""" create permission payload from template """

perms = dracoon.nodes.make_permissions(manage=False, read=False, create=False, change=False, delete=False, manage_shares=False,
manage_file_requests=False, delete_recycle_bin=False, restore_recycle_bin=False,
perms = dracoon.nodes.make_permissions(manage=False, read=False, create=False, change=False, delete=False, manage_shares=False,
manage_file_requests=False, delete_recycle_bin=False, restore_recycle_bin=False,
read_recycle_bin=False)

if not isinstance(permissions, PermissionTemplate):
Expand All @@ -295,7 +295,7 @@ def create_permissions(permissions: PermissionTemplate, dracoon: DRACOON) -> Per
set_read_perms(permissions=perms)
set_read_perms(permissions=perms)
set_room_admin_perms(permissions=perms)

return perms

def parse_permissions_template(perms: str) -> PermissionTemplate:
Expand Down
31 changes: 25 additions & 6 deletions dccmd/main/upload/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ def __init__(self, dir_path: str, base_path: str):
self.size = os.path.getsize(self.dir_path)
self.x_size = self.x_path.stat().st_size


class FileItemList:
"""object representing all files in a path (recursively)"""

Expand All @@ -100,6 +99,11 @@ def __init__(self, source_path: str):
FileItem(dir_path, source_path)
for dir_path in fast_scanfile(dirname=source_path)
]

self.ignored_files = [file_item for file_item in self.file_list if not validate_file_name(file_item.name)]
# reject invalid file names
self.file_list = [file_item for file_item in self.file_list if validate_file_name(file_item.name)]

# get unique levels
self.levels = set([file_item.level for file_item in self.file_list])

Expand All @@ -120,7 +124,7 @@ def file_count(self):
def total_size(self):
""" return total size in bytes """
return sum([item.size for item in self.file_list])

def convert_to_dir_items(dir_list: list[str], base_dir: str) -> list[DirectoryItem]:
"""convert a list of paths to a list of directory items (helper class)"""

Expand Down Expand Up @@ -180,7 +184,7 @@ async def create_folder_struct(source: str, target: str, dracoon: DRACOON, veloc
async def process_batch(batch):
"""process a batch of folders to create"""

path = target + '/' + batch[0].parent_path
path = target.rstrip('/') + '/' + batch[0].parent_path.lstrip('/')
parent_node = await dracoon.nodes.get_node_from_path(path)

if parent_node is None:
Expand Down Expand Up @@ -258,6 +262,12 @@ async def bulk_upload(
"""upload a list of files in a given source path"""

file_list = FileItemList(source_path=source)

dracoon.logger.info(f"Ignored files: {len(file_list.ignored_files)}")

for file in file_list.ignored_files:
dracoon.logger.info(f"Ignoring file: {file.dir_path}")

file_list.sort_by_size()
transfer_list = DCTransferList(total=file_list.total_size, file_count=file_list.file_count)

Expand All @@ -272,11 +282,12 @@ async def bulk_upload(

for item in file_list.file_list:
upload_job = DCTransfer(transfer=transfer_list)
dracoon.logger.info(target + '/' + item.parent_path)
dracoon.logger.info(item.dir_path)
dracoon.logger.debug(target + '/' + item.parent_path)
dracoon.logger.debug(item.dir_path)
target_path = target.rstrip('/') + '/' + item.parent_path.lstrip('/')
req = dracoon.upload(
file_path=item.dir_path,
target_path=(target + '/' + item.parent_path),
target_path=(target_path),
resolution_strategy=resolution_strategy,
callback_fn=upload_job.update
)
Expand Down Expand Up @@ -317,3 +328,11 @@ def create_folder(name: str, parent_id: int, dracoon: DRACOON):

folder = dracoon.nodes.make_folder(name=name, parent_id=parent_id)
return dracoon.nodes.create_folder(folder=folder, raise_on_err=True)

def validate_file_name(name: str) -> str:
""" validate file name """
# return false if name length is more than 150 chars
if len(name) > 150:
return False

return True
Loading

0 comments on commit 03e6404

Please sign in to comment.