Skip to content

Commit

Permalink
Merge pull request #480 from PCMDI/pmp_demo_fix
Browse files Browse the repository at this point in the history
Pmp demo fix
  • Loading branch information
zshaheen committed Mar 8, 2017
2 parents e635d86 + fcc93c8 commit 3fd77dd
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 26 deletions.
64 changes: 38 additions & 26 deletions demo/pmp_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import sys
import shlex
import genutil

import argparse

class bgcolor:
HEADER = '\033[95m'
Expand Down Expand Up @@ -59,6 +59,11 @@ def describe(demo_file,colorized=True):
comment(bc+"This ends this parameter file"+bgcolor.ENDC)

def demo(demo_file,title,colorized=True):
parser = argparse.ArgumentParser(description='Just used for pointing to demo data')
parser.add_argument('-d', dest='demo_data_path',
help='Path to the tarball of demo data')
args = parser.parse_args()

comment("""
PMP Demo: %s
Expand All @@ -78,34 +83,41 @@ def demo(demo_file,title,colorized=True):
if not os.path.exists(demo_pth):
os.makedirs(demo_pth)
# http:https://oceanonly.llnl.gov/gleckler1/pmp-demo-data/pmpv1.1_demodata.tar
tar_filename = "pmpv1.1_demodata.tar"
tar_pth = os.path.join(demo_pth,tar_filename)

good_md5 = "a6ef8f15457378ff36fd46e8fbf5f157"

attempts = 0
while attempts < 3:
md5 = hashlib.md5()
if os.path.exists(tar_filename):
f = open(tar_filename)
md5.update(f.read())

if args.demo_data_path:
tar_pth = os.path.abspath(args.demo_data_path)
if not os.path.exists(tar_pth):
raise IOError('%s does not exist' % tar_pth)

else:
tar_filename = "pmpv1.1_demodata.tar"
tar_pth = os.path.join(demo_pth,tar_filename)

good_md5 = "a6ef8f15457378ff36fd46e8fbf5f157"

attempts = 0
while attempts < 3:
md5 = hashlib.md5()
if os.path.exists(tar_filename):
f = open(tar_filename)
md5.update(f.read())
if md5.hexdigest() == good_md5:
attempts = 5
continue
print "Downloading: ", tar_filename
r = requests.get("http:https://oceanonly.llnl.gov/gleckler1/pmp-demo-data/pmpv1.1_demodata.tar", stream=True)
with open(tar_pth, 'wb') as f:
for chunk in r.iter_content(chunk_size=1024):
if chunk: # filter local_filename keep-alive new chunks
f.write(chunk)
md5.update(chunk)
f.close()
if md5.hexdigest() == good_md5:
attempts = 5
continue
print "Downloading: ", tar_filename
r = requests.get("http:https://oceanonly.llnl.gov/gleckler1/pmp-demo-data/pmpv1.1_demodata.tar", stream=True)
with open(tar_pth, 'wb') as f:
for chunk in r.iter_content(chunk_size=1024):
if chunk: # filter local_filename keep-alive new chunks
f.write(chunk)
md5.update(chunk)
f.close()
if md5.hexdigest() == good_md5:
attempts = 5
else:
attempts += 1
else:
attempts += 1

comment("Successfuly downloaded demo tarball\nNow untarring it", None)
comment("Successfuly downloaded demo tarball\nNow untarring it", None)

tar_process = subprocess.Popen(shlex.split("tar xvf %s"%tar_pth),cwd=demo_pth)
tar_process.wait()
Expand Down
1 change: 1 addition & 0 deletions src/python/pcmdi/scripts/driver/pmp_parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def __init__(self):

self.metrics_output_path = ''
self.filename_output_template = ''
self.dry_run = False

def check_str(self, str_var, str_var_name):
if type(str_var) is not str:
Expand Down

0 comments on commit 3fd77dd

Please sign in to comment.