Skip to content

Commit

Permalink
Some changes in function selfUpdate and getVersion in run-ml_containe…
Browse files Browse the repository at this point in the history
…r.sh and run-atlas_container.sh
  • Loading branch information
Shuwei Ye authored and Shuwei Ye committed Oct 25, 2023
1 parent 91095d5 commit c4f3b3e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
8 changes: 6 additions & 2 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-25-beta01
# version=2023-10-25-beta02
# author: Shuwei Ye <yesw@bnl.gov>
"true" '''\'
myScript="${BASH_SOURCE:-$0}"
Expand Down Expand Up @@ -103,6 +103,10 @@ def getVersion(myFile=None):
myScript = os.path.abspath(sys.argv[0])
myFile = open(myScript, 'r')
isFileOpen = True
else:
if isinstance(myFile, str):
myFile = myFile.split('\n')
no = 0
version = None
for line in myFile:
Expand Down Expand Up @@ -147,7 +151,7 @@ def selfUpdate(args):
resource = urlopen(URL_MYSELF)
content = resource.read().decode('utf-8')
latestVersion = getVersion(content.split('\n'))
latestVersion = getVersion(content)
if latestVersion is not None:
if currentVersion is None or latestVersion > currentVersion:
print("Update available, updating the script itself")
Expand Down
13 changes: 10 additions & 3 deletions run-ml_container.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
# coding: utf-8
# version=2023-10-11-r01
# version=2023-10-25-r01
"true" '''\'
myScript="${BASH_SOURCE:-$0}"
ret=0
Expand Down Expand Up @@ -128,6 +128,10 @@ def getVersion(myFile=None):
myScript = os.path.abspath(sys.argv[0])
myFile = open(myScript, 'r')
isFileOpen = True
else:
if isinstance(myFile, str):
myFile = myFile.split('\n')
no = 0
version = None
for line in myFile:
Expand All @@ -152,19 +156,22 @@ def selfUpdate(args):
latestVersion = getVersion(content)
if latestVersion is not None:
if currentVersion is None or latestVersion > currentVersion:
print("Update available, updating the script itself")
myScript = os.path.abspath(sys.argv[0])
os.rename(myScript, myScript + '.old')
try:
myfile = open(myScript, 'w')
myfile.write(content)
myfile.close()
print("Update finished")
except Exception:
err = sys.exc_info()[1]
print("Failed to write out the latest version of this script\n", err)
print("Keep the current version")
os.rename(myScript + '.old', myScript)
else:
print("No update is available")
return
print("Already up-to-date, no update needed")
def run_shellCmd(shellCmd, exitOnFailure=True):
Expand Down

0 comments on commit c4f3b3e

Please sign in to comment.