-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into DDS-1701-new-release-for-cli
- Loading branch information
Showing
5 changed files
with
348 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
import logging | ||
import typing | ||
import sys | ||
from dateutil.parser import parse | ||
|
||
# Installed | ||
import pytz | ||
|
@@ -148,6 +149,117 @@ 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, new_deadline=None): | ||
"""Extend the project deadline.""" | ||
# 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, | ||
error_message="Failed to extend project deadline", | ||
) | ||
|
||
# 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'}, | ||
# } | ||
|
||
# Check that the returned information was ok | ||
keys = ["project_info", "project_status", "default_unit_days"] | ||
( | ||
project_info, | ||
project_status, | ||
default_unit_days, | ||
*_, | ||
) = dds_cli.utils.get_required_in_response(keys=keys, response=response_json) | ||
|
||
# Check and extract the required information for the operation | ||
current_status, *_ = dds_cli.utils.get_required_in_response( | ||
keys=["current_status"], response=project_status | ||
) | ||
|
||
# if the project is still in progress it won't have a current_deadline parameter | ||
if not current_status == "Available": | ||
raise exceptions.DDSCLIException( | ||
"You can only extend the deadline for a project that has the status 'Available'." | ||
) | ||
|
||
current_deadline, *_ = dds_cli.utils.get_required_in_response( | ||
keys=["current_deadline"], response=project_status | ||
) | ||
project_id, *_ = dds_cli.utils.get_required_in_response( | ||
keys=["Project ID"], response=project_info | ||
) | ||
|
||
# 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=project_info) | ||
dds_cli.utils.console.print(table) | ||
dds_cli.utils.console.print(print_info) | ||
|
||
# If it wasnt provided during the command click, ask the user for the new deadline | ||
if not new_deadline: | ||
# Question number of days to extend the deadline | ||
prompt_question = ( | ||
"How many days would you like to extend the project deadline with? " | ||
"Leave empty in order to choose the default" | ||
) | ||
new_deadline = rich.prompt.IntPrompt.ask(prompt_question, default=default_unit_days) | ||
|
||
# Confirm operation question | ||
new_deadline_date = parse(current_deadline) + datetime.timedelta(days=new_deadline) | ||
new_deadline_date = new_deadline_date.strftime("%a,%d %b %Y %H:%M:%S") | ||
prompt_question = ( | ||
f"\nThe new deadline for project {project_id} will be: [b][blue]{new_deadline_date}[/b][/blue]" | ||
"\n\n[b][blue]Are you sure [/b][/blue]you want to perform this operation? " | ||
"\nYou can only extend the data availability a maximum of " | ||
"[b][blue]3 times[/b][/blue], this consumes one of those times." | ||
) | ||
|
||
if not rich.prompt.Confirm.ask(prompt_question): | ||
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": new_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, | ||
error_message="Failed to extend project deadline", | ||
) | ||
message = response_json.get("message") | ||
if not message: | ||
raise exceptions.DDSCLIException( | ||
"No message returned from API. Cannot verify extension of project deadline." | ||
) | ||
|
||
LOG.info(message) | ||
|
||
|
||
class ProjectBusyStatusManager(base.DDSBaseClass): | ||
"""Project Busy Status manager class.""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.