-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added function cleanLast in run-*_container.sh; and sort releases lis…
…ting in run-atlas_container.sh
- Loading branch information
Shuwei Ye
authored and
Shuwei Ye
committed
Oct 26, 2023
1 parent
c4f3b3e
commit 3fb83e5
Showing
2 changed files
with
133 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#!/bin/bash | ||
# coding: utf-8 | ||
# version=2023-10-25-beta02 | ||
# version=2023-10-26-beta01 | ||
# author: Shuwei Ye <[email protected]> | ||
"true" '''\' | ||
myScript="${BASH_SOURCE:-$0}" | ||
|
@@ -60,7 +60,7 @@ import subprocess | |
from time import sleep | ||
import fnmatch | ||
from shutil import which | ||
from shutil import which, rmtree | ||
from subprocess import getstatusoutput | ||
from urllib.request import urlopen, Request | ||
|
@@ -71,6 +71,27 @@ ATLAS_PROJECTS = ['athena', 'analysisbase', 'athanalysis', 'analysistop', 'athan | |
DOCKERHUB_REPO = "https://hub.docker.com/v2/repositories/atlas" | ||
class Version(str): | ||
def __lt__(self, other): | ||
va = re.split('[.-]', self) | ||
vb = re.split('[.-]', other) | ||
# print("va=",va, "; vb=",vb) | ||
for i in range(min(len(va), len(vb))): | ||
ai = va[i] | ||
bi = vb[i] | ||
if ai.isdigit() and bi.isdigit(): | ||
if ai != bi: | ||
return int(ai) < int(bi) | ||
elif ai != bi: | ||
return ai < bi | ||
return len(va) < len(vb) | ||
def set_default_subparser(parser, default_subparser, index_action=1): | ||
"""default subparser selection. Call after setup, just before parse_args() | ||
|
@@ -225,6 +246,7 @@ def listReleases(args): | |
for tagKey in imageTags.keys(): | ||
if fnmatch.fnmatch(tagKey, release): | ||
tags += [ tagKey ] | ||
tags.sort(key=Version) | ||
if len(tags) > 0: | ||
pp = pprint.PrettyPrinter(indent=4, compact=True) | ||
print("Found the following release container list for the project=", project, releasePrint) | ||
|
@@ -431,6 +453,52 @@ eval $stopCmd | |
shellFile.close() | ||
def getMyImageInfo(filename): | ||
shellFile = open(filename, 'r') | ||
myImageInfo = {} | ||
for line in shellFile: | ||
if re.search(r'^(cont|image|docker|sand|runOpt|lines).*=', line): | ||
key, value = line.strip().split('=') | ||
myImageInfo[key] = value | ||
return myImageInfo | ||
def printMe(args): | ||
if not os.path.exists(args.shellFilename): | ||
print("No previous container/sandbox setup is found") | ||
return None | ||
myImageInfo = getMyImageInfo(args.shellFilename) | ||
contCmd = myImageInfo["contCmd"] | ||
if "runOpt" in myImageInfo: | ||
myImageInfo.pop("runOpt") | ||
pp = pprint.PrettyPrinter(indent=4) | ||
print("The image/container used in the current work directory:") | ||
pp.pprint(myImageInfo) | ||
def cleanLast(filename): | ||
if not os.path.exists(filename): | ||
return | ||
myImageInfo = getMyImageInfo(filename) | ||
if len(myImageInfo) > 0: | ||
contCmd = myImageInfo['contCmd'] | ||
if contCmd == 'singularity' or contCmd == 'apptainer': | ||
sandboxPath = myImageInfo['sandboxPath'] | ||
print("Removing the last sandbox=", sandboxPath) | ||
try: | ||
rmtree(sandboxPath) | ||
except: | ||
pass | ||
os.rename(filename, filename + '.last') | ||
else: | ||
contName = myImageInfo['contName'] | ||
print("Removing the last container=", contName) | ||
rmCmd = "%s rm -f %s" % (contCmd, contName) | ||
run_shellCmd(rmCmd, exitOnFailure=False) | ||
os.rename(filename, filename + '.last') | ||
def setup(args): | ||
releaseTags = parseArgTags(args.tags, requireRelease=True) | ||
project = releaseTags['project'] | ||
|
@@ -451,6 +519,8 @@ def setup(args): | |
print("Please install one of the above tool first") | ||
sys.exit(1) | ||
cleanLast(args.shellFilename) | ||
contCmd = contCmds[0] | ||
if args.contCmd is not None: | ||
if args.contCmd in contCmds: | ||
|
@@ -480,29 +550,6 @@ def setup(args): | |
sleep(1) | ||
def getMyImageInfo(filename): | ||
shellFile = open(filename, 'r') | ||
myImageInfo = {} | ||
for line in shellFile: | ||
if re.search(r'^(cont|image|docker|sand|runOpt|lines).*=', line): | ||
key, value = line.strip().split('=') | ||
myImageInfo[key] = value | ||
return myImageInfo | ||
def printMe(args): | ||
if not os.path.exists(args.shellFilename): | ||
print("No previous container/sandbox setup is found") | ||
return None | ||
myImageInfo = getMyImageInfo(args.shellFilename) | ||
contCmd = myImageInfo["contCmd"] | ||
if "runOpt" in myImageInfo: | ||
myImageInfo.pop("runOpt") | ||
pp = pprint.PrettyPrinter(indent=4) | ||
print("The image/container used in the current work directory:") | ||
pp.pprint(myImageInfo) | ||
def jupyter(args): | ||
if not os.path.exists(args.shellFilename): | ||
print("No previous container/sandbox setup is found") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters