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

Adding the ability to exclude images by regex #103

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
/.vscode
*.pyc
venv/
pyvenv.cfg
pyvenv.cfg
Pipfile*
19 changes: 19 additions & 0 deletions registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,12 @@ def parse_args(args=None):
'Useful if your tag names are not in a fixed order.'),
action='store_true'
)
parser.add_argument(
'--keep-images-like',
help=('List of images (regex check) that will be omitted from deletion if used in combination with --delete or --delete-all'),
default=[],
required=False
)
return parser.parse_args(args)


Expand Down Expand Up @@ -720,6 +726,17 @@ def keep_images_like(image_list, regexp_list):
break
return result

def remove_images_like(image_list, regexp_list):
if image_list is None or regexp_list is None:
return []
result = []
regexp_list = list(map(re.compile, regexp_list))
for image in image_list:
for regexp in regexp_list:
if not re.search(regexp, image):
result.append(image)
break
return result

def get_ordered_tags(registry, image_name, tags_list, order_by_date=False):
if order_by_date:
Expand Down Expand Up @@ -784,6 +801,8 @@ def main_loop(args):
image_list = registry.list_images()
if args.images_like:
image_list = keep_images_like(image_list, args.images_like)
if args.keep_images_like:
image_list = remove_images_like(image_list,args.keep_images_like)

# loop through registry's images
# or through the ones given in command line
Expand Down