Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dds 1690 -- New cli command: dds project status extend #661

Merged
merged 36 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
b995218
started command
rv0lt Oct 16, 2023
89c7144
second call
rv0lt Oct 16, 2023
0f58043
added tests
rv0lt Oct 17, 2023
363f153
docstring
rv0lt Oct 17, 2023
2e25400
pylint
rv0lt Oct 17, 2023
4a12d23
tests!
rv0lt Oct 17, 2023
9b27bda
missing test
rv0lt Oct 17, 2023
7503833
missing test
rv0lt Oct 17, 2023
baaa98f
sprintlog
rv0lt Oct 17, 2023
ed779e8
prettier
rv0lt Oct 18, 2023
67db194
better coments
rv0lt Oct 18, 2023
b8cc80b
line too long
rv0lt Oct 18, 2023
31fbb36
Merge branch 'dev' into DDS-1690-New-CLI-command-dds-project-status-e…
rv0lt Oct 19, 2023
9167102
prettier
rv0lt Oct 19, 2023
f5829a0
Update SPRINTLOG.md
rv0lt Oct 20, 2023
fd469d7
Update dds_cli/project_status.py
rv0lt Oct 20, 2023
86039bd
Update dds_cli/project_status.py
rv0lt Oct 20, 2023
68d317c
Update dds_cli/project_status.py
rv0lt Oct 20, 2023
f83a1cf
feedback
rv0lt Oct 20, 2023
06949d5
pylint
rv0lt Oct 20, 2023
f047fb0
pylint
rv0lt Oct 20, 2023
3f514d3
pylint
rv0lt Oct 20, 2023
c1206f7
Update dds_cli/__main__.py
rv0lt Oct 20, 2023
42cd8bd
Update dds_cli/project_status.py
rv0lt Oct 20, 2023
ddb2db7
Update dds_cli/project_status.py
rv0lt Oct 20, 2023
12ade91
Update dds_cli/project_status.py
rv0lt Oct 20, 2023
693155a
feedback
rv0lt Oct 23, 2023
59e42f7
Update dds_cli/project_status.py
rv0lt Oct 23, 2023
ff58777
Update dds_cli/project_status.py
rv0lt Oct 23, 2023
d81c251
Update dds_cli/project_status.py
rv0lt Oct 23, 2023
61835ab
Update dds_cli/project_status.py
rv0lt Oct 23, 2023
2f10d1f
feedback
rv0lt Oct 23, 2023
8a20679
Update dds_cli/project_status.py
rv0lt Oct 23, 2023
ea57cef
black
rv0lt Oct 23, 2023
a47159b
Update dds_cli/project_status.py
rv0lt Oct 24, 2023
eaa7e4a
format date
rv0lt Oct 24, 2023
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 SPRINTLOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -305,4 +305,5 @@ _Nothing merged in CLI during this sprint_

# 2023-10-16 - 2023-10-27

- Added a new command to match with the new extend deadline endpoint ([#661])(https://github.com/ScilifelabDataCentre/dds_cli/pull/661)
- Change "Checksum verification successful. File integrity verified." logging level from INFO to DEBUG in order to not print for all files ([#662])(https://github.com/ScilifelabDataCentre/dds_cli/pull/661)
rv0lt marked this conversation as resolved.
Show resolved Hide resolved
29 changes: 29 additions & 0 deletions dds_cli/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1243,6 +1243,35 @@ def delete_project(click_ctx, project: str):
sys.exit(1)


# -- dds project status extend -- #
@project_status.command(name="extend", no_args_is_help=True)
# Options
@project_option(required=True)
rv0lt marked this conversation as resolved.
Show resolved Hide resolved
@click.pass_obj
def extend_deadline(click_ctx, project: str):
"""Extend a project deadline by an specified number of days.

This operation has the same effect as expiring and re-releasing a project
Therefore it consumes one of the possible expiring times.
rv0lt marked this conversation as resolved.
Show resolved Hide resolved
"""
try:
with dds_cli.project_status.ProjectStatusManager(
project=project,
no_prompt=click_ctx.get("NO_PROMPT", False),
token_path=click_ctx.get("TOKEN_PATH"),
) as updater:
updater.extend_deadline()
except (
dds_cli.exceptions.APIError,
dds_cli.exceptions.AuthenticationError,
dds_cli.exceptions.DDSCLIException,
dds_cli.exceptions.ApiResponseError,
dds_cli.exceptions.ApiRequestError,
) as err:
LOG.error(err)
sys.exit(1)


# -- dds project status busy -- #
@project_status.command(name="busy", no_args_is_help=False)
# Flags
Expand Down
106 changes: 106 additions & 0 deletions dds_cli/project_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,112 @@ def update_status(self, new_status, deadline=None, is_aborted=False, no_mail=Fal

dds_cli.utils.console.print(f"Project {response_json.get('message')}")

def extend_deadline(self):
rv0lt marked this conversation as resolved.
Show resolved Hide resolved
"""
Extend the project deadline
"""
rv0lt marked this conversation as resolved.
Show resolved Hide resolved
# Define initial parameters
extra_params = {"send_email": False}

# Fetch project status and default deadline
response_json, _ = dds_cli.utils.perform_request(
endpoint=DDSEndpoint.UPDATE_PROJ_STATUS,
headers=self.token,
method="patch",
params={"project": self.project},
json=extra_params,
)
rv0lt marked this conversation as resolved.
Show resolved Hide resolved

# Structure of the response:
# {
# 'default_unit_days': 30,
# 'project_info': {
# 'Created by': 'First Unit User',
# 'Description': 'This is a test project',
# 'Last updated': 'Wed, 18 Oct 2023 08:40:43 GMT',
# 'PI': '[email protected]',
# 'Project ID': 'project_1',
# 'Size': 0,
# 'Status': 'Available',
# 'Title': 'First Project'
# },
# 'project_status': {
# 'current_deadline': 'Sat, 04 Nov 2023 23:59:59 GMT',
# 'current_status': 'Available'},
# 'warning': 'Operation must be confirmed before proceding.'
# }

# Extract default unit days and current deadline
default_unit_days = response_json.get("default_unit_days")
current_deadline = response_json.get("project_status").get("current_deadline")

# print information about the project status and table with the project info
print_info = (
f"\nCurrent deadline: [b][green]{current_deadline}[/green][/b]\n"
f"Default deadline extension: [b][green]{default_unit_days}[/green][/b] days\n"
)
table = self.generate_project_table(project_info=response_json.get("project_info"))
rv0lt marked this conversation as resolved.
Show resolved Hide resolved
dds_cli.utils.console.print(table)
dds_cli.utils.console.print(print_info)

# First question, number of days to extend the deadline
prompt_question = (
f"Enter the number of days you want to extend the project, "
f"the number of days has to be equal or same as "
f"[b][green]{default_unit_days}[/green][/b].\n"
f"Or leave it empty to apply the default "
f"[b][green]{default_unit_days} days [/green][/b]"
)

dds_cli.utils.console.print(prompt_question)
extend_deadline = rich.prompt.Prompt.ask("-")
if not extend_deadline:
# Set extend_deadline to default
extend_deadline = default_unit_days
rv0lt marked this conversation as resolved.
Show resolved Hide resolved
try:
# the input was an string --> convert to integer
extend_deadline = int(extend_deadline)
if extend_deadline > default_unit_days:
dds_cli.utils.console.print(
"\n[b][red]The number of days has to be lower than "
"the default deadline extension number[/b][/red]\n"
)
LOG.info("Exiting the function, try again")
sys.exit(0)

except ValueError:
dds_cli.utils.console.print(
"\n[b][red]Remember to write the number of days "
"using numbers (dont use letters)[/b][/red]\n"
)
LOG.info("Exiting the function, try again")
sys.exit(0)
rv0lt marked this conversation as resolved.
Show resolved Hide resolved

# Second question, confirm operation
prompt_question = (
rv0lt marked this conversation as resolved.
Show resolved Hide resolved
f"\n\n[b][blue]Are you sure [/b][/blue]you want to perform this operation?. "
f"\nThis will extend the deadline by [b][blue]{extend_deadline} days[/b][/blue]."
"\nYou can only extend the data availability a maximum of "
"[b][blue]3 times[/b][/blue], this consumes one of those times."
)

dds_cli.utils.console.print(prompt_question)
if not rich.prompt.Confirm.ask("-"):
rv0lt marked this conversation as resolved.
Show resolved Hide resolved
LOG.info("Probably for the best. Exiting.")
sys.exit(0)

# Update parameters for the second request
extra_params = {**extra_params, "confirmed": True, "new_deadline_in": extend_deadline}

response_json, _ = dds_cli.utils.perform_request(
endpoint=DDSEndpoint.UPDATE_PROJ_STATUS,
headers=self.token,
method="patch",
params={"project": self.project},
json=extra_params,
rv0lt marked this conversation as resolved.
Show resolved Hide resolved
)
dds_cli.utils.console.print(f"Project {response_json.get('message')}")
rv0lt marked this conversation as resolved.
Show resolved Hide resolved


class ProjectBusyStatusManager(base.DDSBaseClass):
"""Project Busy Status manager class."""
Expand Down
2 changes: 2 additions & 0 deletions dds_cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ def perform_request(
request_method = requests.post
elif method == "delete":
request_method = requests.delete
elif method == "patch":
request_method = requests.patch

def transform_paths(json_input):
"""Make paths serializable."""
Expand Down
Loading
Loading