Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,5 @@ integration_tests
# cli manifest data
./manifest.json
manifest.json
resumable_upload_log.json
test
11 changes: 8 additions & 3 deletions app/commands/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from app.utils.aggregated import get_file_info_by_geid
from app.utils.aggregated import get_zone
from app.utils.aggregated import identify_target_folder
from app.utils.aggregated import remove_the_output_file
from app.utils.aggregated import search_item


Expand Down Expand Up @@ -110,9 +111,9 @@ def cli():
@click.option(
'--output-path',
'-o',
default='./manifest.json',
default='./resumable_upload_log.json',
required=False,
help='The output path for the manifest file of resumable upload.',
help='The output path for the manifest file of resumable upload log.',
show_default=True,
)
@doc(file_help.file_help_page(file_help.FileHELP.FILE_UPLOAD))
Expand Down Expand Up @@ -226,6 +227,8 @@ def file_put(**kwargs): # noqa: C901
srv_manifest.attach_manifest(attribute, item_ids[0], zone) if attribute else None
message_handler.SrvOutPutHandler.all_file_uploaded()

remove_the_output_file(output_path)


@click.command(name='resume')
@click.option(
Expand All @@ -241,7 +244,7 @@ def file_put(**kwargs): # noqa: C901
'-r',
default=None,
required=True,
help='The manifest file for resumable upload',
help='The resumable upload log file',
show_default=True,
)
@doc(file_help.file_help_page(file_help.FileHELP.FILE_RESUME))
Expand Down Expand Up @@ -278,6 +281,8 @@ def file_resume(**kwargs): # noqa: C901
srv_manifest.attach_manifest(attribute, item_id, zone) if attribute else None
message_handler.SrvOutPutHandler.all_file_uploaded()

remove_the_output_file(resumable_manifest_file)


def validate_upload_event(event):
"""validate upload request, raise error when filed."""
Expand Down
2 changes: 1 addition & 1 deletion app/resources/custom_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Error:
'The upload ID may be invalid, or the upload may have been aborted or completed.'
),
'MANIFEST_OF_FOLDER_FILE_EXIST': (
'The manifest file of folder %s already exist. ' 'Do you want to overwrite the existing manifest file?'
'The manifest file of folder %s already exist. ' 'To continue and overwrite the resumable upload log, enter'
),
'INVALID_CHUNK_UPLOAD': (
'\nThe chunk number %d is not the same with previous etag.\n'
Expand Down
2 changes: 1 addition & 1 deletion app/resources/custom_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class HelpPage:
'FILE_LIST': 'List files and folders inside a given Project/folder.',
'FILE_SYNC': 'Download files/folders from a given Project/folder/file in core zone.',
'FILE_UPLOAD': 'Upload files/folders to a given Project path.',
'FILE_RESUME': 'Resume the upload process with given manifest file.',
'FILE_RESUME': 'Resume the upload process with a resumable upload log.',
'FILE_Z': 'Target Zone (i.e., core/greenroom).',
'FILE_ATTRIBUTE_P': 'Project Code',
'FILE_ATTRIBUTE_N': 'Attribute Template Name',
Expand Down
11 changes: 11 additions & 0 deletions app/utils/aggregated.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import httpx
import requests

import app.services.logger_services.log_functions as logger
from app.configs.app_config import AppConfig
from app.configs.config import ConfigClass
from app.configs.user_config import UserConfig
Expand Down Expand Up @@ -154,3 +155,13 @@ def batch_generator(iterable: List[Any], batch_size=1):
max_size = len(iterable)
for start_index in range(0, max_size, batch_size):
yield iterable[start_index : min(start_index + batch_size, max_size)]


def remove_the_output_file(filepath: str) -> None:
"""Remove the output file after each successful operation to avoid confusion."""
try:
os.remove(filepath)
except FileNotFoundError:
pass
except OSError:
logger.warning(f'Unable to remove "{filepath}".')
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "app"
version = "2.9.6"
version = "2.9.7"
description = "This service is designed to support pilot platform"
authors = ["Indoc Systems"]

Expand Down
15 changes: 9 additions & 6 deletions tests/app/commands/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def test_resumable_upload_command_success(mocker, cli_runner):
mocker.patch('builtins.open', mocked_open_data)
mocker.patch('json.load', return_value={'file_objects': {'test_item_id': {'file_name': 'test.json'}}, 'zone': 1})
mocker.patch('app.commands.file.resume_upload', return_value=None)
mocker.patch('os.remove', return_value=None)
result = cli_runner.invoke(file_resume, ['--resumable-manifest', 'test.json', '--thread', 1])
assert result.exit_code == 0

Expand All @@ -85,6 +86,8 @@ def test_resumable_upload_command_with_file_attribute_success(mocker, cli_runner
'app.services.file_manager.file_manifests.SrvFileManifests.attach_manifest', return_value=None
)

mocker.patch('os.remove', return_value=None)

result = cli_runner.invoke(file_resume, ['--resumable-manifest', 'test.json', '--thread', 1])
assert result.exit_code == 0
attribute_fun_mock.assert_called_once()
Expand Down Expand Up @@ -253,13 +256,13 @@ def test_download_file_metadata_file_duplicate_success(mocker, cli_runner):
with runner.isolated_filesystem():
file_meta_client = FileMetaClient('zone', file_path, metadata_loc, metadata_loc, metadata_loc)
# create all file to make duplicationn
makedirs(dirname(file_meta_client.general_location), exist_ok=True)
makedirs(dirname(file_meta_client.general_location), exist_ok=True, mode=0o0700)
with open(file_meta_client.general_location, 'w') as f:
f.write(file_meta_client.general_location)
makedirs(dirname(file_meta_client.attribute_location), exist_ok=True)
makedirs(dirname(file_meta_client.attribute_location), exist_ok=True, mode=0o0700)
with open(file_meta_client.attribute_location, 'w') as f:
f.write(file_meta_client.attribute_location)
makedirs(dirname(file_meta_client.tag_location), exist_ok=True)
makedirs(dirname(file_meta_client.tag_location), exist_ok=True, mode=0o0700)
with open(file_meta_client.tag_location, 'w') as f:
f.write(file_meta_client.tag_location)

Expand Down Expand Up @@ -303,13 +306,13 @@ def test_download_file_metadata_file_duplicate_abort(mocker, cli_runner):
with runner.isolated_filesystem():
file_meta_client = FileMetaClient('zone', file_path, metadata_loc, metadata_loc, metadata_loc)
# create all file to make duplicationn
makedirs(dirname(file_meta_client.general_location), exist_ok=True)
makedirs(dirname(file_meta_client.general_location), exist_ok=True, mode=0o0700)
with open(file_meta_client.general_location, 'w') as f:
f.write(file_meta_client.general_location)
makedirs(dirname(file_meta_client.attribute_location), exist_ok=True)
makedirs(dirname(file_meta_client.attribute_location), exist_ok=True, mode=0o0700)
with open(file_meta_client.attribute_location, 'w') as f:
f.write(file_meta_client.attribute_location)
makedirs(dirname(file_meta_client.tag_location), exist_ok=True)
makedirs(dirname(file_meta_client.tag_location), exist_ok=True, mode=0o0700)
with open(file_meta_client.tag_location, 'w') as f:
f.write(file_meta_client.tag_location)

Expand Down