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

feat!: add conflict resolution option to configuration file #76

Merged
merged 1 commit into from
Oct 24, 2023
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
6 changes: 6 additions & 0 deletions src/deadline/client/cli/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ def _apply_cli_options_to_config(
auto_accept = args.pop("yes", None)
if auto_accept:
config_file.set_setting("settings.auto_accept", "true", config=config)

conflict_resolution = args.pop("conflict_resolution", None)
if conflict_resolution:
config_file.set_setting(
"settings.conflict_resolution", conflict_resolution, config=config
)
else:
# Remove the standard option names from the args list
for name in ["profile", "farm_id", "queue_id", "job_id"]:
Expand Down
14 changes: 6 additions & 8 deletions src/deadline/client/cli/_groups/job_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ def _download_job_output(
job_id: str,
step_id: Optional[str],
task_id: Optional[str],
conflict_resolution: Optional[str] = None,
is_json_format: bool = False,
):
"""
Expand All @@ -232,6 +231,7 @@ def _download_job_output(
auto_accept = config_file.str2bool(
config_file.get_setting("settings.auto_accept", config=config)
)
conflict_resolution = config_file.get_setting("settings.conflict_resolution", config=config)

job = deadline.get_job(farmId=farm_id, queueId=queue_id, jobId=job_id)

Expand Down Expand Up @@ -330,10 +330,10 @@ def _download_job_output(
)
output_paths_by_root = job_output_downloader.get_output_paths_by_root()

# If the conflict resolution option was not provided as a command option, auto-accept is false,
# and if there are any conflicting files in local, prompt users to select a resolution method.
# If the conflict resolution option was not specified, auto-accept is false, and
# if there are any conflicting files in local, prompt users to select a resolution method.
# (skip, overwrite, or make a copy.)
if conflict_resolution:
if conflict_resolution != FileConflictResolution.NOT_SELECTED.name:
file_conflict_resolution = FileConflictResolution[conflict_resolution]
elif auto_accept:
file_conflict_resolution = FileConflictResolution.CREATE_COPY
Expand Down Expand Up @@ -565,7 +565,7 @@ def _is_path_in_windows_format(path_str: str) -> bool:
"parsed/consumed by custom scripts.",
)
@_handle_error
def job_download_output(step_id, task_id, conflict_resolution, output, **args):
def job_download_output(step_id, task_id, output, **args):
"""
Download the output attached to an Amazon Deadline Cloud Job.
"""
Expand All @@ -582,9 +582,7 @@ def job_download_output(step_id, task_id, conflict_resolution, output, **args):
is_json_format = True if output == "json" else False

try:
_download_job_output(
config, farm_id, queue_id, job_id, step_id, task_id, conflict_resolution, is_json_format
)
_download_job_output(config, farm_id, queue_id, job_id, step_id, task_id, is_json_format)
except Exception as e:
if is_json_format:
error_one_liner = str(e).replace("\n", ". ")
Expand Down
7 changes: 6 additions & 1 deletion src/deadline/client/config/config_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
from pathlib import Path
from typing import Any, Dict, List, Optional

import boto3 # type: ignore[import]
import boto3
from deadline.job_attachments.models import FileConflictResolution

from ..exceptions import DeadlineOperationError
import re
Expand Down Expand Up @@ -98,6 +99,10 @@
"settings.auto_accept": {
"default": "false",
},
"settings.conflict_resolution": {
"default": FileConflictResolution.NOT_SELECTED.name,
"description": "How to handle duplicate files when downloading (if a file with the same path/name already exists.)",
},
"settings.log_level": {
"default": "WARNING",
"description": "The logging level to use in the CLI and GUIs.",
Expand Down
10 changes: 10 additions & 0 deletions src/deadline/client/ui/dialogs/deadline_config_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import boto3 # type: ignore[import]
from botocore.exceptions import ProfileNotFound # type: ignore[import]
from deadline.job_attachments.models import FileConflictResolution
from PySide2.QtCore import QSize, Qt, Signal
from PySide2.QtWidgets import ( # pylint: disable=import-error; type: ignore
QCheckBox,
Expand Down Expand Up @@ -276,6 +277,15 @@ def _build_general_settings_ui(self, group, layout):
group, layout, "settings.auto_accept", "Auto Accept Confirmation Prompts"
)

self._conflict_resolution_options = [option.name for option in FileConflictResolution]
self.conflict_resolution_box = self._init_combobox_setting(
group,
layout,
"settings.conflict_resolution",
"Conflict Resolution Option",
self._conflict_resolution_options,
)

self._log_levels = ["ERROR", "WARNING", "INFO", "DEBUG"]
self.log_level_box = self._init_combobox_setting(
group,
Expand Down
1 change: 1 addition & 0 deletions src/deadline/job_attachments/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ class FileSystemLocationType(str, Enum):


class FileConflictResolution(Enum):
NOT_SELECTED = 0
SKIP = 1
OVERWRITE = 2
CREATE_COPY = 3
Expand Down
4 changes: 3 additions & 1 deletion test/unit/deadline_client/cli/test_cli_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def test_cli_config_show_defaults(fresh_deadline_config):
assert fresh_deadline_config in result.output

# Assert the expected number of settings
assert len(settings.keys()) == 13
assert len(settings.keys()) == 14

for setting_name in settings.keys():
assert setting_name in result.output
Expand Down Expand Up @@ -98,6 +98,7 @@ def test_cli_config_show_modified_config(fresh_deadline_config):
config.set_setting("defaults.queue_id", "queue-389348u234jhk34")
config.set_setting("defaults.job_id", "job-239u40234jkl234nkl23")
config.set_setting("settings.auto_accept", "False")
config.set_setting("settings.conflict_resolution", "CREATE_COPY")
config.set_setting("defaults.job_attachments_file_system", "VIRTUAL")
config.set_setting("settings.log_level", "DEBUG")
config.set_setting("telemetry.opt_out", "True")
Expand All @@ -119,6 +120,7 @@ def test_cli_config_show_modified_config(fresh_deadline_config):
assert "farm-82934h23k4j23kjh" in result.output
assert "queue-389348u234jhk34" in result.output
assert "job-239u40234jkl234nkl23" in result.output
assert "settings.conflict_resolution:\n CREATE_COPY" in result.output
assert "settings.log_level:\n DEBUG" in result.output
assert "user-id-123abc-456def" in result.output
# It shouldn't say anywhere that there is a default setting
Expand Down