Skip to content

Commit

Permalink
Fixes from review
Browse files Browse the repository at this point in the history
  • Loading branch information
roytev committed Mar 26, 2024
1 parent 3403d88 commit 5e9ac94
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ artifactory-cleanup --output=myfile.txt
artifactory-cleanup --output=myfile.txt --output-format=json
# Save the summary and removed artifacts list in a Json file
artifactory-cleanup --output=myfile.txt --output-format=json --save-removed-artifacts
artifactory-cleanup --output=myfile.txt --output-format=json --output-artifacts
```

# Rules
Expand Down
9 changes: 5 additions & 4 deletions artifactory_cleanup/artifactorycleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class CleanupSummary:
policy_name: str
artifacts_removed: int
artifacts_size: int
removed_artifacts_list: Optional[dict]
removed_artifacts_list: Optional[dict] = None


class ArtifactoryCleanup:
Expand Down Expand Up @@ -71,13 +71,14 @@ def cleanup(self, block_ctx_mgr, test_ctx_mgr) -> Iterator[CleanupSummary]:
try:
artifacts_size = sum([x["size"] for x in artifacts_to_remove])
print("Summary size: {}".format(artifacts_size))
yield CleanupSummary(
summary = CleanupSummary(
policy_name=policy.name,
artifacts_size=artifacts_size,
artifacts_removed=len(artifacts_to_remove),
removed_artifacts_list=artifacts_to_remove if self.save_removed_artifacts_list else None,
)

if self.save_removed_artifacts_list:
summary.removed_artifacts_list = artifacts_to_remove
yield summary
except KeyError:
print("Summary size not defined")
yield None
Expand Down
29 changes: 14 additions & 15 deletions artifactory_cleanup/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from datetime import timedelta, date

import requests
import yaml
from hurry.filesize import size
from plumbum import cli
from plumbum.cli.switches import Set
Expand All @@ -15,12 +14,12 @@
ArtifactoryCleanup,
)
from artifactory_cleanup.base_url_session import BaseUrlSession
from artifactory_cleanup.context_managers import get_context_managers
from artifactory_cleanup.errors import InvalidConfigError
from artifactory_cleanup.loaders import (
PythonLoader,
YamlConfigLoader,
)
from artifactory_cleanup.context_managers import get_context_managers

requests.packages.urllib3.disable_warnings()

Expand Down Expand Up @@ -88,13 +87,13 @@ class ArtifactoryCleanupCLI(cli.Application):
mandatory=False,
)

_save_removed_artifacts_list = cli.Flag(
"--save-removed-artifacts-list",
help="Save removed artifacts list to file",
_output_artifacts = cli.Flag(
"--output-artifacts",
help="Save artifacts list to file",
mandatory=False,
default=False,
requires=["--output"],
envname="ARTIFACTORY_CLEANUP_SAVE_REMOVED_ARTIFACTS_LIST",
envname="ARTIFACTORY_OUTPUT_ARTIFACTS",
)

@property
Expand Down Expand Up @@ -172,7 +171,7 @@ def main(self):
destroy=self._destroy,
today=today,
ignore_not_found=self._ignore_not_found,
save_removed_artifacts_list=self._save_removed_artifacts_list,
save_removed_artifacts_list=self._output_artifacts,
)

# Filter policies by name
Expand All @@ -190,14 +189,14 @@ def main(self):
continue
total_size += summary.artifacts_size

result["policies"].append(
{
"name": summary.policy_name,
"file_count": summary.artifacts_removed,
"size": summary.artifacts_size,
**({"removed_artifacts_list": summary.removed_artifacts_list} if summary.removed_artifacts_list is not None else {})
}
)
policy = {
"name": summary.policy_name,
"file_count": summary.artifacts_removed,
"size": summary.artifacts_size
}
if summary.removed_artifacts_list is not None:
policy["artifacts_list"] = summary.removed_artifacts_list
result["policies"].append(policy)
result["total_size"] = total_size

self._print_table(result)
Expand Down

0 comments on commit 5e9ac94

Please sign in to comment.