Skip to content

Commit

Permalink
Added cleanall option to clean script
Browse files Browse the repository at this point in the history
  • Loading branch information
ggatward committed Feb 26, 2017
1 parent dfc723e commit 65c3381
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
21 changes: 15 additions & 6 deletions clean_content_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def get_content_view_info(cvid):
return cvinfo


def cleanup(ver_list, ver_descr, dry_run, runuser, ver_keep):
def cleanup(ver_list, ver_descr, dry_run, runuser, ver_keep, cleanall):
"""Clean Content Views"""

# Set the task name to be displayed in the task monitoring stage
Expand Down Expand Up @@ -125,10 +125,16 @@ def cleanup(ver_list, ver_descr, dry_run, runuser, ver_keep):
helpers.log_msg(msg, 'DEBUG')

if float(version['version']) > float(lastver):
msg = "Skipping delete of version " + str(version['version'])
helpers.log_msg(msg, 'INFO')
print msg
continue
# If we have chosen to remove all orphans
if cleanall:
msg = "Removing version " + str(version['version'])
helpers.log_msg(msg, 'INFO')
print helpers.HEADER + msg + helpers.ENDC
else:
msg = "Skipping delete of version " + str(version['version'])
helpers.log_msg(msg, 'INFO')
print msg
continue
else:
if float(version['version']) < (lastver - float(ver_keep[cvid])):
msg = "Removing version " + str(version['version'])
Expand Down Expand Up @@ -195,6 +201,8 @@ def main(args):
required=False)
group.add_argument('-a', '--all', help='Clean ALL content views', required=False,
action="store_true")
parser.add_argument('-c', '--cleanall', help='Remove orphan versions between in-use views',
required=False, action="store_true")
parser.add_argument('-d', '--dryrun', help='Dry Run - Only show what will be cleaned',
required=False, action="store_true")

Expand All @@ -210,6 +218,7 @@ def main(args):
else:
org_name = helpers.ORG_NAME
dry_run = args.dryrun
cleanall = args.cleanall
if args.keep:
keep = args.keep
else:
Expand All @@ -234,7 +243,7 @@ def main(args):
(ver_list, ver_descr, ver_keep) = get_cv(org_id, cleanup_list, keep)

# Clean the content views. Returns a list of task IDs.
cleanup(ver_list, ver_descr, dry_run, runuser, ver_keep)
cleanup(ver_list, ver_descr, dry_run, runuser, ver_keep, cleanall)


if __name__ == "__main__":
Expand Down
13 changes: 13 additions & 0 deletions man/clean_content_views.8
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ file - see
If the keep value is not specified in either the config.yml or the --keep option, the default value is 0.
.RE
.PP
.BR "-c", " --cleanall"
.RS 3
Clean all orphaned versions of the content view.
By default the removal of versions between published, in-use versions is not performed.
.PP
For example, a given content view contains versions 1, 2 (Production), 3, 4, 5, 6 (Quality), 7, 8 (Library)
.br
By default versions 3-5 and 7 will not be deleted as they exist in between 'live' published versions.
Using the
.B -c
option will cause these versions to be cleaned up as well as any older than the oldest promoted version.
.RE
.PP
.BR "-d", " --dryrun"
.RS 3
Do not perform the actual cleanup activity, but show what would be done.
Expand Down

0 comments on commit 65c3381

Please sign in to comment.