implemented to remove file or folder commnand rm
.
This commit is contained in:
parent
fd2238f5ca
commit
8ee220137f
@ -60,8 +60,11 @@ class FileCommand(BaseCommand):
|
||||
move_parser.add_argument("src_path", help="Source remote path (remote:/lab/path/src)")
|
||||
move_parser.add_argument("dest_path", help="Destination remote path (remote:/lab/path/dest)")
|
||||
move_parser.set_defaults(func=FileCommand.move)
|
||||
# remove
|
||||
remove_parser = top_level_subparsers.add_parser("remove", help="remove a file")
|
||||
# rm
|
||||
remove_parser = top_level_subparsers.add_parser("rm", help="remove file or folder")
|
||||
remove_parser.add_argument(
|
||||
"-r", "--recursive", help="Remove folders and their contents recursive", action="store_true"
|
||||
)
|
||||
remove_parser.add_argument("remote_path", help="Remote file path (remote:/lab/path/file)")
|
||||
remove_parser.set_defaults(func=FileCommand.remove)
|
||||
# file-metadata
|
||||
@ -136,11 +139,11 @@ class FileCommand(BaseCommand):
|
||||
file_path = os.path.join(local_path, file_name)
|
||||
download_files.append(DownloadFile(file, file_path))
|
||||
else:
|
||||
if not args.recursive:
|
||||
raise IllegalArgumentException(f"Cannot download `{args.remote_path}`: Is a folder.")
|
||||
sub_folder = parent_folder.find_sub_folder(file_name)
|
||||
if sub_folder is None:
|
||||
raise IllegalArgumentException(f"File or Folder`{file_name}` not found.")
|
||||
if not args.recursive:
|
||||
raise IllegalArgumentException(f"Cannot download `{path}`: Is a folder.")
|
||||
folder_api = FolderApi(connection)
|
||||
sub_folder_dirname = os.path.join(local_path, sub_folder.name)
|
||||
FileCommand._multiple_download_pickup_recursive_files(
|
||||
@ -218,12 +221,19 @@ class FileCommand(BaseCommand):
|
||||
file_name = os.path.basename(path)
|
||||
connection = create_connection(remote)
|
||||
laboratory = find_laboratory(connection, laboratory_name)
|
||||
folder = find_folder(connection, laboratory, parent_path)
|
||||
file = folder.find_file(file_name)
|
||||
if file is None:
|
||||
raise IllegalArgumentException(f"File `{file_name}` not found.")
|
||||
file_api = FileApi(connection)
|
||||
file_api.destroy(file)
|
||||
parent_folder = find_folder(connection, laboratory, parent_path)
|
||||
file = parent_folder.find_file(file_name)
|
||||
if file is not None:
|
||||
file_api = FileApi(connection)
|
||||
file_api.destroy(file)
|
||||
else:
|
||||
folder = parent_folder.find_sub_folder(file_name)
|
||||
if folder is None:
|
||||
raise IllegalArgumentException(f"File `{file_name}` not found.")
|
||||
if not args.recursive:
|
||||
raise IllegalArgumentException(f"Cannot remove `{path}`: Is a folder.")
|
||||
folder_api = FolderApi(connection)
|
||||
folder_api.destroy(folder.id)
|
||||
|
||||
@staticmethod
|
||||
def metadata(args: Namespace) -> None:
|
||||
|
@ -22,10 +22,6 @@ class FolderCommand(BaseCommand):
|
||||
mkdir_parser = top_level_subparsers.add_parser("mkdir", help="create a new folder")
|
||||
mkdir_parser.add_argument("remote_path", help="Remote folder path (remote:/lab/path/)")
|
||||
mkdir_parser.set_defaults(func=FolderCommand.mkdir)
|
||||
# rmdir
|
||||
rmdir_parser = top_level_subparsers.add_parser("rmdir", help="remove a existing folder")
|
||||
rmdir_parser.add_argument("remote_path", help="Remote folder path (remote:/lab/path/)")
|
||||
rmdir_parser.set_defaults(func=FolderCommand.rmdir)
|
||||
# metadata
|
||||
metadata_parser = top_level_subparsers.add_parser("metadata", help="get a folder metadata")
|
||||
metadata_parser.add_argument("remote_path", help="Remote folder path (remote:/lab/path/)")
|
||||
@ -97,15 +93,6 @@ class FolderCommand(BaseCommand):
|
||||
folder_api = FolderApi(connection)
|
||||
folder_api.create(folder_name, folder.id)
|
||||
|
||||
@staticmethod
|
||||
def rmdir(args: Namespace) -> None:
|
||||
(remote, laboratory_name, path) = parse_remote_host_with_path(args.remote_path)
|
||||
connection = create_connection(remote)
|
||||
laboratory = find_laboratory(connection, laboratory_name)
|
||||
folder = find_folder(connection, laboratory, path)
|
||||
folder_api = FolderApi(connection)
|
||||
folder_api.destroy(folder.id)
|
||||
|
||||
@staticmethod
|
||||
def metadata(args: Namespace) -> None:
|
||||
(remote, laboratory_name, path) = parse_remote_host_with_path(args.remote_path)
|
||||
|
Loading…
Reference in New Issue
Block a user