Skip to content

Commit

Permalink
implement download fallback for traditional make build
Browse files Browse the repository at this point in the history
  • Loading branch information
akohlmey committed Feb 1, 2023
1 parent 5d16bea commit 89b37c5
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 84 deletions.
3 changes: 3 additions & 0 deletions lib/hdnnp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/includelink
/liblink
/n2p2-*
17 changes: 12 additions & 5 deletions lib/hdnnp/Install.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from argparse import ArgumentParser

sys.path.append('..')
from install_helpers import get_cpus, fullpath, geturl, checkmd5sum
from install_helpers import get_cpus, fullpath, geturl, checkmd5sum, getfallback

parser = ArgumentParser(prog='Install.py',
description="LAMMPS library build wrapper script")
Expand Down Expand Up @@ -76,14 +76,21 @@

if buildflag:
url = "https://github.com/CompPhysVienna/n2p2/archive/v%s.tar.gz" % (version)
filename = "n2p2-%s.tar.gz" %version
print("Downloading n2p2 ...")
geturl(url, filename)
filename = "n2p2-%s.tar.gz" % version
fallback = getfallback('n2p2', url)
print("Downloading n2p2 from", url)
try:
geturl(url, filename)
except:
geturl(fallback, filename)

# verify downloaded archive integrity via md5 checksum, if known.
if version in checksums:
if not checkmd5sum(checksums[version], filename):
sys.exit("Checksum for n2p2 library does not match")
print("Checksum did not match. Trying fallback URL", fallback)
geturl(fallback, filename)
if not checkmd5sum(checksums[version], filename):
sys.exit("Checksum for n2p2 library does not match for fallback, too.")

print("Unpacking n2p2 source tarball ...")
if os.path.exists("%s/n2p2-%s" % (homepath, version)):
Expand Down
24 changes: 15 additions & 9 deletions lib/install_helpers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import hashlib,os,subprocess
import hashlib
import os
import re
import subprocess

# try to auto-detect the maximum number of available CPUs
def get_cpus():
Expand Down Expand Up @@ -32,31 +35,31 @@ def is_exe(fpath):

return None

def geturl(url,fname):
def geturl(url, fname):
success = False

if which('curl') != None:
cmd = 'curl -L -o "%s" %s' % (fname,url)
cmd = 'curl -L -o "%s" %s' % (fname, url)
try:
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True)
success = True
except subprocess.CalledProcessError as e:
print("Calling curl failed with: %s" % e.output.decode('UTF-8'))

if not success and which('wget') != None:
cmd = 'wget -O "%s" %s' % (fname,url)
cmd = 'wget -O "%s" %s' % (fname, url)
try:
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True)
success = True
except subprocess.CalledProcessError as e:
print("Calling wget failed with: %s" % e.output.decode('UTF-8'))

if not success:
error("Failed to download source code with 'curl' or 'wget'")
raise Exception("Failed to download source code with 'curl' or 'wget' from " + url)
return

def checkmd5sum(md5sum,fname):
with open(fname,'rb') as fh:
def checkmd5sum(md5sum, fname):
with open(fname, 'rb') as fh:
m = hashlib.md5()
while True:
data = fh.read(81920)
Expand All @@ -66,3 +69,6 @@ def checkmd5sum(md5sum,fname):
fh.close()
return m.hexdigest() == md5sum

def getfallback(lib, url):
archive = re.sub(r'^https://.*/([^/]+gz)', r'-\1', url)
return 'https://download.lammps.org/thirdparty/' + lib + archive
16 changes: 12 additions & 4 deletions lib/latte/Install.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from argparse import ArgumentParser

sys.path.append('..')
from install_helpers import fullpath, geturl, checkmd5sum
from install_helpers import fullpath, geturl, checkmd5sum, getfallback

parser = ArgumentParser(prog='Install.py',
description="LAMMPS library build wrapper script")
Expand Down Expand Up @@ -86,17 +86,25 @@
url = "https://github.com/lanl/LATTE/archive/v%s.tar.gz" % version
lattepath = fullpath(homepath)
lattedir = os.path.join(lattepath, homedir)
fallback = getfallback('latte', url)
filename = 'LATTE.tar.gz'

# download and unpack LATTE tarball

if buildflag:
print("Downloading LATTE ...")
geturl(url, "LATTE.tar.gz")
try:
geturl(url, filename)
except:
geturl(fallback, filename)

# verify downloaded archive integrity via md5 checksum, if known.
if version in checksums:
if not checkmd5sum(checksums[version], 'LATTE.tar.gz'):
sys.exit("Checksum for LATTE library does not match")
if not checkmd5sum(checksums[version], filename):
print("Checksum did not match. Trying fallback URL", fallback)
geturl(fallback, filename)
if not checkmd5sum(checksums[version], filename):
sys.exit("Checksum for LATTE library does not match for fallback, too.")

print("Unpacking LATTE ...")
if os.path.exists(lattedir):
Expand Down
61 changes: 12 additions & 49 deletions lib/mdi/Install.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import glob

sys.path.append('..')
from install_helpers import checkmd5sum
from install_helpers import fullpath, geturl, checkmd5sum, getfallback

# help message

Expand Down Expand Up @@ -51,49 +51,6 @@ def error(str=None):
# expand to full path name
# process leading '~' or relative path

def fullpath(path):
return os.path.abspath(os.path.expanduser(path))

def which(program):
def is_exe(fpath):
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)

fpath, fname = os.path.split(program)
if fpath:
if is_exe(program):
return program
else:
for path in os.environ["PATH"].split(os.pathsep):
path = path.strip('"')
exe_file = os.path.join(path, program)
if is_exe(exe_file):
return exe_file

return None

def geturl(url,fname):
success = False

if which('curl') != None:
cmd = 'curl -L -o "%s" %s' % (fname,url)
try:
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
success = True
except subprocess.CalledProcessError as e:
print("Calling curl failed with: %s" % e.output.decode('UTF-8'))

if not success and which('wget') != None:
cmd = 'wget -O "%s" %s' % (fname,url)
try:
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
success = True
except subprocess.CalledProcessError as e:
print("Calling wget failed with: %s" % e.output.decode('UTF-8'))

if not success:
error("Failed to download source code with 'curl' or 'wget'")
return

# parse args

args = sys.argv[1:]
Expand Down Expand Up @@ -123,17 +80,24 @@ def geturl(url,fname):

# download and unpack MDI_Library tarball

homepath = "."
homepath = fullpath('.')
homedir = "%s/MDI_Library" % homepath

print("Downloading MDI_Library ...")
mditar = "%s/v%s.tar.gz" % (homepath,version)
geturl(url, mditar)
mditar = "%s/v%s.tar.gz" % (homepath, version)
fallback = getfallback('mdi', url)
try:
geturl(url, mditar)
except:
geturl(fallback, mditar)

# verify downloaded archive integrity via md5 checksum, if known.
if version in checksums:
if not checkmd5sum(checksums[version], mditar):
sys.exit("Checksum for MDI library does not match")
print("Checksum did not match. Trying fallback URL", fallback)
geturl(fallback, mditar)
if not checkmd5sum(checksums[version], mditar):
sys.exit("Checksum for MDI library does not match")

print("Unpacking MDI_Library tarball ...")
if os.path.exists("%s/v%s" % (homepath,version)):
Expand Down Expand Up @@ -199,7 +163,6 @@ def geturl(url,fname):
makefile_lammps.write(str(rpath_option) + "\n")
makefile_lammps.close()


shared_files = glob.glob( os.path.join( homepath, "liblink", "lib%s.a" % lib) )
if len(shared_files) > 0:
print("Build was successful")
Expand Down
16 changes: 14 additions & 2 deletions lib/mscg/Install.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from argparse import ArgumentParser

sys.path.append('..')
from install_helpers import fullpath, geturl
from install_helpers import fullpath, geturl, checkmd5sum, getfallback

parser = ArgumentParser(prog='Install.py',
description="LAMMPS library build wrapper script")
Expand Down Expand Up @@ -84,7 +84,19 @@
if buildflag:
print("Downloading MS-CG ...")
tarname = os.path.join(homepath, tarname)
geturl(url, tarname)
fallback = getfallback('mscg', url)
try:
geturl(url, tarname)
except:
geturl(fallback, tarname)

# verify downloaded archive integrity via md5 checksum, if known.
if mscgver in checksums:
if not checkmd5sum(checksums[mscgver], tarname):
print("Checksum did not match. Trying fallback URL", fallback)
geturl(fallback, tarname)
if not checkmd5sum(checksums[mscgver], tarname):
sys.exit("Checksum for LATTE library does not match for fallback, too.")

print("Unpacking MS-CG tarfile ...")

Expand Down
15 changes: 11 additions & 4 deletions lib/pace/Install.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from argparse import ArgumentParser

sys.path.append('..')
from install_helpers import fullpath, geturl, checkmd5sum
from install_helpers import fullpath, geturl, checkmd5sum, getfallback

# settings

Expand Down Expand Up @@ -77,14 +77,21 @@
print("Downloading pace tarball ...")
archive_filename = "%s.%s" % (version, archive_extension)
download_filename = "%s/%s" % (thisdir, archive_filename)
fallback = getfallback('pacelib', url)
print("Downloading from ", url, " to ", download_filename, end=" ")
geturl(url, download_filename)
try:
geturl(url, download_filename)
except:
geturl(fallback, download_filename)
print(" done")

# verify downloaded archive integrity via md5 checksum, if known.
if version in checksums:
if not checkmd5sum(checksums[version], archive_filename):
sys.exit("Checksum for pace library does not match")
if not checkmd5sum(checksums[version], download_filename):
print("Checksum did not match. Trying fallback URL", fallback)
geturl(fallback, download_filename)
if not checkmd5sum(checksums[version], download_filename):
sys.exit("Checksum for pace library does not match for fallback, too.")

print("Unpacking pace tarball ...")
src_folder = thisdir + "/src"
Expand Down
16 changes: 12 additions & 4 deletions lib/plumed/Install.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from argparse import ArgumentParser

sys.path.append('..')
from install_helpers import get_cpus, fullpath, geturl, checkmd5sum
from install_helpers import get_cpus, fullpath, geturl, checkmd5sum, getfallback

parser = ArgumentParser(prog='Install.py',
description="LAMMPS library build wrapper script")
Expand Down Expand Up @@ -86,6 +86,7 @@
pathflag = args.path is not None
plumedpath = args.path
mode = args.mode
version = args.version

homepath = fullpath('.')
homedir = "%s/plumed2" % (homepath)
Expand All @@ -101,14 +102,21 @@

if buildflag:
url = "https://github.com/plumed/plumed2/releases/download/v%s/plumed-src-%s.tgz" % (version, version)
filename = "plumed-src-%s.tar.gz" %version
filename = "plumed-src-%s.tar.gz" % version
fallback = getfallback('plumed', url)
print("Downloading plumed ...")
geturl(url, filename)
try:
geturl(url, filename)
except:
geturl(fallback, filename)

# verify downloaded archive integrity via md5 checksum, if known.
if version in checksums:
if not checkmd5sum(checksums[version], filename):
sys.exit("Checksum for plumed2 library does not match")
print("Checksum did not match. Trying fallback URL", fallback)
geturl(fallback, filename)
if not checkmd5sum(checksums[version], filename):
sys.exit("Checksum for plumed2 library does not match for fallback, too.")

print("Unpacking plumed2 source tarball ...")
if os.path.exists("%s/plumed-%s" % (homepath, version)):
Expand Down
21 changes: 14 additions & 7 deletions lib/scafacos/Install.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@
from argparse import ArgumentParser

sys.path.append('..')
from install_helpers import fullpath, geturl, get_cpus, checkmd5sum
from install_helpers import fullpath, geturl, get_cpus, checkmd5sum, getfallback

parser = ArgumentParser(prog='Install.py',
description="LAMMPS library build wrapper script")
parser = ArgumentParser(prog='Install.py', description="LAMMPS library build wrapper script")

# settings

version = "1.0.1"
url = "https://github.com/scafacos/scafacos/releases/download/v%s/scafacos-%s.tar.gz" % (version, version)

# known checksums for different ScaFaCoS versions. used to validate the download.
checksums = { \
Expand Down Expand Up @@ -59,6 +57,7 @@
buildflag = args.build
pathflag = args.path is not None
version = args.version
url = "https://github.com/scafacos/scafacos/releases/download/v%s/scafacos-%s.tar.gz" % (version, version)

homepath = fullpath(".")
scafacospath = os.path.join(homepath, "scafacos-%s" % version)
Expand All @@ -76,12 +75,20 @@

if buildflag:
print("Downloading ScaFaCoS ...")
geturl(url, "%s/scafacos-%s.tar.gz" % (homepath, version))
filename = "%s/scafacos-%s.tar.gz" % (homepath, version)
fallback = getfallback('scafacos', url)
try:
geturl(url, filename)
except:
geturl(fallback, filename)

# verify downloaded archive integrity via md5 checksum, if known.
if version in checksums:
if not checkmd5sum(checksums[version], '%s/scafacos-%s.tar.gz' % (homepath, version)):
sys.exit("Checksum for ScaFaCoS library does not match")
if not checkmd5sum(checksums[version], filename):
print("Checksum did not match. Trying fallback URL", fallback)
geturl(fallback, filename)
if not checkmd5sum(checksums[version], filename):
sys.exit("Checksum for ScaFaCoS library does not match for fallback, too.")

print("Unpacking ScaFaCoS tarball ...")
if os.path.exists(scafacospath):
Expand Down

0 comments on commit 89b37c5

Please sign in to comment.