Skip to content

Commit 18133c7

Browse files
author
dnichol
committed
Added deletion of associated code locations when deleting old project versions
1 parent 37f3db7 commit 18133c7

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

examples/delete_older_versions_system_wide.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
parser.add_argument("-e", "--excluded_phases", default=excluded_phases_defaults, help=f"Set the phases to exclude from deletion (defaults to {excluded_phases_defaults})")
4242
parser.add_argument("-a", "--age", type=int, help=f"Project-versions older than this age (days) will be deleted unless their phase is in the list of excluded phases ({excluded_phases_defaults})")
4343
parser.add_argument("-d", "--delete", action='store_true', help=f"Because this script can, and will, delete project-versions we require the caller to explicitly ask to delete things. Otherwise, the script runs in a 'test mode' and just says what it would do.")
44+
parser.add_argument("-ncl", "--do_not_delete_code_locations", action='store_true', help=f"By default the script will delete code locations mapped to project versions being deleted. Pass this flag if you do not want to delete code locations.")
4445
args = parser.parse_args()
4546

4647
logging.basicConfig(format='%(asctime)s:%(levelname)s:%(module)s: %(message)s', stream=sys.stderr, level=logging.DEBUG)
@@ -66,6 +67,10 @@
6667
# TODO: What to do if/when this is the last version in a project to avoid having empty projects being left around
6768
logging.debug(f"Deleting version {version['versionName']} from project {project['name']} cause it is {version_age} days old which is greater than {args.age} days")
6869
url = version['_meta']['href']
70+
if not args.do_not_delete_code_locations:
71+
logging.debug(f"Deleting code locations for version {version['versionName']} from project {project['name']}")
72+
hub.delete_project_version_codelocations(version)
73+
6974
response = hub.execute_delete(url)
7075
if response.status_code == 204:
7176
logging.info(f"Successfully deleted version {version['versionName']} from project {project['name']}")

0 commit comments

Comments
 (0)