Skip to content

Commit

Permalink
remove --display-format and include hash by default instead
Browse files Browse the repository at this point in the history
  • Loading branch information
christianwaldmann committed Jun 28, 2024
1 parent 383ff6f commit 3c611b8
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 41 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ artifactory-cleanup --help
configuration for multiple repositories and some of them are not found.
- Use `--worker-count=<WORKER_NUM>` to increase the number of workers. By default, it's 1. It's useful when you have a lot of
artifacts and you want to speed up the process.
- Use `--display-format` to customize the printed information when deleting a file. The default format is "'{path}' - {size}". Supported options are "{path}", "{size}" and "{hash}".

## Commands ##

Expand Down
4 changes: 1 addition & 3 deletions artifactory_cleanup/artifactorycleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@ def __init__(
today: date,
ignore_not_found: bool,
worker_count: int,
display_format: str,
):
self.session = session
self.policies = policies
self.destroy = destroy
self.ignore_not_found = ignore_not_found
self.worker_count = worker_count
self.display_format = display_format

self._init_policies(today)

Expand Down Expand Up @@ -63,7 +61,7 @@ def cleanup(self, block_ctx_mgr, test_ctx_mgr) -> Iterator[CleanupSummary]:
# Delete artifacts
def _delete(artifact):
with test_ctx_mgr(get_name_for_ci(artifact)):
policy.delete(artifact, destroy=self.destroy, display_format=self.display_format, ignore_not_found=self.ignore_not_found)
policy.delete(artifact, destroy=self.destroy, ignore_not_found=self.ignore_not_found)

with ThreadPoolExecutor(max_workers=int(self.worker_count)) as executor:
for artifact in artifacts_to_remove:
Expand Down
9 changes: 0 additions & 9 deletions artifactory_cleanup/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,6 @@ class ArtifactoryCleanupCLI(cli.Application):
mandatory=False,
)

_display_format = cli.SwitchAttr(
"--display-format",
help="Set format of the printed message when deleting a file",
default="'{path}' ({hash}) - {size}",
mandatory=False,
envname="ARTIFACTORY_CLEANUP_DISPLAY_FORMAT",
)

@property
def VERSION(self):
# To prevent circular imports
Expand Down Expand Up @@ -180,7 +172,6 @@ def main(self):
today=today,
ignore_not_found=self._ignore_not_found,
worker_count=self._worker_count,
display_format=self._display_format,
)

# Filter policies by name
Expand Down
8 changes: 3 additions & 5 deletions artifactory_cleanup/rules/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def filter(self, artifacts: ArtifactsList) -> ArtifactsList:
print()
return artifacts

def delete(self, artifact: ArtifactDict, destroy: bool, display_format: str, ignore_not_found: bool = False) -> None:
def delete(self, artifact: ArtifactDict, destroy: bool, ignore_not_found: bool = False) -> None:
"""
Delete the artifact
:param artifact: artifact to remove
Expand All @@ -314,12 +314,10 @@ def delete(self, artifact: ArtifactDict, destroy: bool, display_format: str, ign
artifact_size = artifact.get("size", 0) or 0
artifact_hash = artifact.get("actual_sha1", "")

file_string = display_format.replace("{path}", artifact_path).replace("{size}", size(artifact_size)).replace("{hash}", artifact_hash)

if not destroy:
print(f"DEBUG - we would delete {file_string}")
print(f"DEBUG - we would delete '{artifact_path}' ({artifact_hash}) - {size(artifact_size)}")
return
print(f"DESTROY MODE - delete {file_string}")
print(f"DESTROY MODE - delete '{artifact_path}' ({artifact_hash}) - {size(artifact_size)}")
r = self.session.delete(artifact_path)
try:
r.raise_for_status()
Expand Down
23 changes: 0 additions & 23 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,26 +190,3 @@ def test_display_format_default(capsys, shared_datadir, requests_mock):
"DEBUG - we would delete 'repo-name-here/path/to/file/filename1.json' (11827853eed40e8b60f5d7e45f2a730915d7704d) - 528B\n"
in stdout
)


@pytest.mark.usefixtures("requests_repo_name_here")
def test_display_format(capsys, shared_datadir, requests_mock):
_, code = ArtifactoryCleanupCLI.run(
[
"ArtifactoryCleanupCLI",
"--config",
str(shared_datadir / "cleanup.yaml"),
"--load-rules",
str(shared_datadir / "myrule.py"),
"--display-format",
"'{path}'",
],
exit=False,
)
stdout, stderr = capsys.readouterr()
print(stdout)
assert code == 0, stdout
assert (
"DEBUG - we would delete 'repo-name-here/path/to/file/filename1.json'\n"
in stdout
)

0 comments on commit 3c611b8

Please sign in to comment.