Skip to content

Commit

Permalink
Replaced the walrus operations with something compatible with python-…
Browse files Browse the repository at this point in the history
…3.6; Changed pprint in the dynamic width same as the terminal width; Added 'digest' info into the imageInfo printout; Added a guide to start the corresponding image if a sole image is found
  • Loading branch information
Shuwei Ye authored and Shuwei Ye committed Mar 2, 2024
1 parent 9ac93d9 commit e7f357d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 11 deletions.
26 changes: 21 additions & 5 deletions run-atlas_container.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
# coding: utf-8
# version=2024-02-27-r01
# version=2024-03-02-r01
# author: Shuwei Ye <yesw@bnl.gov>
"true" '''\'
myScript="${BASH_SOURCE:-$0}"
Expand Down Expand Up @@ -213,13 +213,24 @@ def parseArgTags(inputArgs, requireRelease=False):
print("The input arg tags=", argTags)
print("!!Warning!! No project is given from the available choices:", ATLAS_PROJECTS)
for argTag in argTags:
if closeProject := difflib.get_close_matches(argTag.lower(), ATLAS_PROJECTS, n=1, cutoff=0.8):
closeProject = None
argTag_1 = re.split(r'[-.=;]', argTag, 1)[0].lower()
if argTag_1 in ATLAS_PROJECTS:
closeProject = argTag_1
if not closeProject:
closeMatch = difflib.get_close_matches(argTag.lower(), ATLAS_PROJECTS, n=1, cutoff=0.8)
if closeMatch:
closeProject = closeMatch[0]
if closeProject:
print()
print("The closest matched project=", closeProject[0])
if isinstance(closeProject, list):
closeProject = closeProject[0]
print("The closest matched project=", closeProject)
print(" against the input arg tag=", argTag)
print("\nPlease correct it, then rerun\n")
break
sys.exit(1)
if requireRelease and 'releases' not in releaseTags:
print("!!Warning!! No release is given")
sys.exit(1)
Expand Down Expand Up @@ -333,12 +344,15 @@ def listReleases(args):
tags += [ tagName ]
tags.sort(key=Version)
if len(tags) > 0:
pp = pprint.PrettyPrinter(indent=4, compact=True)
columns = os.get_terminal_size().columns
pp = pprint.PrettyPrinter(indent=4, compact=True, width=columns)
print("Found the following release containers for the project= %s, %s\n" % (project, releasePrint))
pp.pprint(tags)
if len(tags) == 1:
print()
getImageInfo(project, tags[0])
print("\nTo run the above image, just run")
print("\tsource %s %s,%s" % (sys.argv[0], project, tags[0]))
else:
print("No release container found for the project=%s, and %s" % (project, releasePrint))
Expand All @@ -357,12 +371,14 @@ def getImageInfo(project, release, printOut=True):
imageInfo['dockerPath' ] = json_obj['location']
imageInfo['imageCompressedSize'] = json_obj['total_size']
imageInfo['lastUpdate'] = json_obj['created_at']
imageInfo['digest'] = json_obj['digest']
if len(imageInfo) > 0 and printOut:
print("The matched image info:")
print("\tdockerPath=", imageInfo['dockerPath'],
"\n\timage compressed size=", imageInfo['imageCompressedSize'],
"\n\tlast update time=", imageInfo['lastUpdate'])
"\n\tlast update time=", imageInfo['lastUpdate'],
"\n\tdigest=", imageInfo['digest'])
return imageInfo
Expand Down
27 changes: 21 additions & 6 deletions run-atlas_container.sh-dockerhub
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
# coding: utf-8
# version=2024-02-27-r01
# version=2024-03-02-r01
# author: Shuwei Ye <yesw@bnl.gov>
"true" '''\'
myScript="${BASH_SOURCE:-$0}"
Expand Down Expand Up @@ -185,13 +185,24 @@ def parseArgTags(inputArgs, requireRelease=False):
print("The input arg tags=", argTags)
print("!!Warning!! No project is given from the available choices:", ATLAS_PROJECTS)
for argTag in argTags:
if closeProject := difflib.get_close_matches(argTag.lower(), ATLAS_PROJECTS, n=1, cutoff=0.8):
closeProject = None
argTag_1 = re.split(r'[-.=;]', argTag, 1)[0].lower()
if argTag_1 in ATLAS_PROJECTS:
closeProject = argTag_1
if not closeProject:
closeMatch = difflib.get_close_matches(argTag.lower(), ATLAS_PROJECTS, n=1, cutoff=0.8)
if closeMatch:
closeProject = closeMatch[0]
if closeProject:
print()
print("The closest matched project=", closeProject[0])
if isinstance(closeProject, list):
closeProject = closeProject[0]
print("The closest matched project=", closeProject)
print(" against the input arg tag=", argTag)
print("\nPlease correct it, then rerun\n")
break
sys.exit(1)
if requireRelease and 'releases' not in releaseTags:
print("!!Warning!! No release is given")
sys.exit(1)
Expand Down Expand Up @@ -249,7 +260,7 @@ def listImageTags(project):
digest = tagObj['images'][0]['digest']
imageSize = tagObj['full_size']
lastUpdate = tagObj['tag_last_pushed']
imageTags[name] = {'imageCompressedSize':imageSize, 'lastUpdate':lastUpdate, 'releaseName':name}
imageTags[name] = {'imageCompressedSize':imageSize, 'lastUpdate':lastUpdate, 'releaseName':name, 'digest':digest}
if name == 'latest':
latest_digest = digest
elif latest_digest != '':
Expand Down Expand Up @@ -314,12 +325,15 @@ def listReleases(args):
tags += [ tagName ]
tags.sort(key=Version)
if len(tags) > 0:
pp = pprint.PrettyPrinter(indent=4, compact=True)
columns = os.get_terminal_size().columns
pp = pprint.PrettyPrinter(indent=4, compact=True, width=columns)
print("Found the following release containers for the project= %s, %s\n" % (project, releasePrint))
pp.pprint(tags)
if len(tags) == 1:
print()
getImageInfo(project, tags[0])
print("\nTo run the above image, just run")
print("\tsource %s %s,%s" % (sys.argv[0], project, tags[0]))
else:
print("No release container found for the project=%s, and %s" % (project, releasePrint))
Expand All @@ -339,7 +353,8 @@ def getImageInfo(project, release, printOut=True):
print("The matched image info:")
print("\tdockerPath=", imageInfo['dockerPath'],
"\n\timage compressed size=", imageInfo['imageCompressedSize'],
"\n\tlast update time=", imageInfo['lastUpdate'])
"\n\tlast update time=", imageInfo['lastUpdate'],
"\n\tdigest=", imageInfo['digest'])
return imageInfo
Expand Down

0 comments on commit e7f357d

Please sign in to comment.