Skip to content

Commit

Permalink
Finished the function listReleases in run-atlas_container.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
Shuwei Ye authored and Shuwei Ye committed Oct 24, 2023
1 parent 403ded9 commit 90b4359
Showing 1 changed file with 39 additions and 19 deletions.
58 changes: 39 additions & 19 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=2023-10-21-alpha01
# version=2023-10-24-alpha01
# author: Shuwei Ye <yesw@bnl.gov>
"true" '''\'
myScript="${BASH_SOURCE:-$0}"
Expand Down Expand Up @@ -58,6 +58,7 @@ import pprint
import re
import subprocess
from time import sleep
import fnmatch
from shutil import which
from subprocess import getstatusoutput
Expand Down Expand Up @@ -126,10 +127,10 @@ def parseArgTags(inputArgs, requireRelease=False):
for tag in argTags:
if tag in ATLAS_PROJECTS:
releaseTags['project'] = tag
elif tag == 'latest' or tag[0].isdigit():
releaseTags['release'] = tag
# elif tag == 'latest' or tag[0].isdigit():
else:
print("!!Warning!! Unrecognized input arg=", tag)
releaseTags['release'] = tag
# print("!!Warning!! Unrecognized input arg=", tag)
if 'project' not in releaseTags:
print("!!Warning!! No project is provided from the choice of ", ATLAS_PROJECTS)
Expand Down Expand Up @@ -161,7 +162,7 @@ def selfUpdate(args):
print("Keep the current version")
os.rename(myScript + '.old', myScript)
else:
print("No update is available")
print("Already up-to-date, no update needed")
def run_shellCmd(shellCmd, exitOnFailure=True):
Expand All @@ -173,16 +174,6 @@ def run_shellCmd(shellCmd, exitOnFailure=True):
return out
def list_FoundImages(name):
images = list(IMAGE_CONFIG.keys())
images_found = []
for imageFullName in images:
imageBaseName = imageFullName.split(':')[0]
if imageFullName == name or imageBaseName == name:
images_found += [imageFullName]
return images_found
def listImageTags(project):
url_tags = DOCKERHUB_REPO + '/' + project + '/tags?page_size=5000'
response = urlopen(url_tags)
Expand Down Expand Up @@ -210,6 +201,31 @@ def listImageTags(project):
return imageTags
def listReleases(args):
releaseTags = parseArgTags(args.tags, requireRelease=False)
project = releaseTags['project']
if 'release' in releaseTags:
release = releaseTags['release']
else:
release = None
imageTags = listImageTags(project)
releasePrint = ""
if release is None:
tags = list(imageTags.keys())
else:
tags = []
releasePrint = " matching release=%s" % release
for tagKey in imageTags.keys():
if fnmatch.fnmatch(tagKey, release):
tags += [ tagKey ]
if len(tags) > 0:
pp = pprint.PrettyPrinter(indent=4, compact=True)
print("Found the following release container list for the project=", project, releasePrint)
pp.pprint(tags)
else:
print("No release container found for the project=", project, releasePrint)
def getImageInfo(project, release, printOut=True):
imageInfo = {}
imageTags = listImageTags(project)
Expand All @@ -223,7 +239,9 @@ def getImageInfo(project, release, printOut=True):
if len(imageInfo) > 0 and printOut:
print("Found an image")
print("\tdockerPath=", imageInfo['dockerPath'], "; image compressed size=", imageInfo['imageCompressedSize'])
print("\tdockerPath=", imageInfo['dockerPath'],
"; image compressed size=", imageInfo['imageCompressedSize'],
"\n\tlast update time=", imageInfo['lastUpdate'])
return imageInfo
Expand Down Expand Up @@ -490,9 +508,10 @@ def main():
example_global = """Examples:

source %s listReleases AthAnalysis
source %s listReleases AthAnalysis,"21.2.2*"
source %s AnalysisBase:21.2.132
source %s # Empty arg to rerun the already setup container
source %s setup AnalysisBase,21.2.132""" % (myScript, myScript, myScript, myScript)
source %s setup AnalysisBase,21.2.132""" % ((myScript,)*5)
example_setup = """Examples:

Expand All @@ -506,8 +525,9 @@ def main():
sp = parser.add_subparsers(dest='command', help='Default=setup')
sp_listReleases = sp.add_parser('listReleases', help='list all available ATLAS releases of a given project')
sp_listReleases.add_argument('projectName', metavar='<ProjectName>', help='Project name to list releases')
# sp_listReleases.set_defaults(func=listReleases)
# sp_listReleases.add_argument('projectName', metavar='<ProjectName>', help='Project name to list releases')
sp_listReleases.add_argument('tags', nargs='+', metavar='<ReleaseTags>', help='Project name to list releases, and release number with wildcard *')
sp_listReleases.set_defaults(func=listReleases)
sp_printImageInfo = sp.add_parser('printImageInfo', help='print the image size and last update date of the given image')
sp_printImageInfo.add_argument('tags', nargs='+', metavar='<ReleaseTags>')
Expand Down

0 comments on commit 90b4359

Please sign in to comment.