Skip to content
Snippets Groups Projects
Commit a4b6cef4 authored by Anne Philipp's avatar Anne Philipp
Browse files

pep8 changes on install.py

parent b780393a
No related branches found
No related tags found
No related merge requests found
......@@ -44,21 +44,20 @@ from getMARSdata import getMARSdata
from prepareFLEXPART import prepareFLEXPART
def main():
calledfromdir=os.getcwd()
'''
'''
# calledfromdir = os.getcwd()
os.chdir(localpythonpath)
args, c = install_args_and_control()
# if c.outputdir[0]!='/':
# c.outputdir=os.path.join(calledfromdir,c.outputdir)
# c.inputdir=c.outputdir
if args.install_target!=None:
if args.install_target is not None:
install_via_gateway(c, args.install_target)
else:
print 'Please specify installation target (local|ecgate|cca)'
print 'use -h or --help for help'
print('Please specify installation target (local|ecgate|cca)')
print('use -h or --help for help')
sys.exit()
def install_via_gateway(c, target):
......@@ -67,6 +66,8 @@ def install_via_gateway(c,target):
template = ecd + 'python/compilejob.temp'
job = ecd + 'python/compilejob.ksh'
fo = open(job, 'w')
#AP could do with open(template) as f, open(job, 'w') as fo:
#AP or nested with statements
with open(template) as f:
fdata = f.read().split('\n')
for data in fdata:
......@@ -75,38 +76,43 @@ def install_via_gateway(c,target):
data = 'export MAKEFILE=' + c.makefile
if 'FLEXPART_ROOT_SCRIPTS=' in data:
if c.flexpart_root_scripts != '../':
data='export FLEXPART_ROOT_SCRIPTS='+c.flexpart_root_scripts
data = 'export FLEXPART_ROOT_SCRIPTS=' + \
c.flexpart_root_scripts
else:
data='export FLEXPART_ROOT_SCRIPTS=$HOME'
if target.lower() != 'local':
if '--workdir' in data:
data='#SBATCH --workdir=/scratch/ms/'+c.ecgid+'/'+c.ecuid
data = '#SBATCH --workdir=/scratch/ms/' + c.ecgid + \
'/' + c.ecuid
if '##PBS -o' in data:
data='##PBS -o /scratch/ms/'+c.ecgid+'/'+c.ecuid+'flex_ecmwf.$Jobname.$Job_ID.out'
data = '##PBS -o /scratch/ms/' + c.ecgid + '/' + c.ecuid + \
'flex_ecmwf.$Jobname.$Job_ID.out'
if 'FLEXPART_ROOT_SCRIPTS=' in data:
if c.ec_flexpart_root_scripts != '../':
data='export FLEXPART_ROOT_SCRIPTS='+c.ec_flexpart_root_scripts
data = 'export FLEXPART_ROOT_SCRIPTS=' + \
c.ec_flexpart_root_scripts
else:
data = 'export FLEXPART_ROOT_SCRIPTS=$HOME'
fo.write(data + '\n')
f.close()
fo.close()
if target.lower() != 'local':
template = ecd + 'python/job.temp.o'
#AP hier eventuell Zeile fr Zeile lesen und dann if Entscheidung
with open(template) as f:
fdata = f.read().split('\n')
f.close()
fo = open(template[:-2], 'w')
for data in fdata:
if '--workdir' in data:
data='#SBATCH --workdir=/scratch/ms/'+c.ecgid+'/'+c.ecuid
data = '#SBATCH --workdir=/scratch/ms/' + c.ecgid + \
'/' + c.ecuid
if '##PBS -o' in data:
data='##PBS -o /scratch/ms/'+c.ecgid+'/'+c.ecuid+'flex_ecmwf.$Jobname.$Job_ID.out'
data = '##PBS -o /scratch/ms/' + c.ecgid + '/' + \
c.ecuid + 'flex_ecmwf.$Jobname.$Job_ID.out'
if 'export PATH=${PATH}:' in data:
data += c.ec_flexpart_root_scripts + '/ECMWFDATA7.0/python'
if 'cat>>' in data or 'cat >>' in data:
i = data.index('>')
fo.write(data[:i] + data[i+1:] + '\n')
......@@ -118,7 +124,7 @@ def install_via_gateway(c,target):
fo.close()
job = ecd + 'python/ECMWF_ENV'
fo=open(job,'w')
with open(job, 'w') as fo:
fo.write('ECUID ' + c.ecuid + '\n')
fo.write('ECGID ' + c.ecgid + '\n')
fo.write('GATEWAY ' + c.gateway + '\n')
......@@ -129,25 +135,32 @@ def install_via_gateway(c,target):
if target.lower() == 'local':
# compile CONVERT2
if c.flexpart_root_scripts==None or c.flexpart_root_scripts=='../':
print 'Warning: FLEXPART_ROOT_SCRIPTS has not been specified'
print 'Only CONVERT2 will be compiled in '+ecd+'/../src'
if c.flexpart_root_scripts is None or c.flexpart_root_scripts == '../':
print('Warning: FLEXPART_ROOT_SCRIPTS has not been specified')
print('Only CONVERT2 will be compiled in ' + ecd + '/../src')
else:
c.flexpart_root_scripts=os.path.expandvars(os.path.expanduser(c.flexpart_root_scripts))
c.flexpart_root_scripts = os.path.expandvars(os.path.expanduser(
c.flexpart_root_scripts))
if os.path.abspath(ecd) != os.path.abspath(c.flexpart_root_scripts):
os.chdir('/')
p=subprocess.check_call(['tar','-cvf',ecd+'../ECMWFDATA7.0.tar',ecd+'python',ecd+'grib_templates',ecd+'src'])
p = subprocess.check_call(['tar', '-cvf',
ecd + '../ECMWFDATA7.0.tar',
ecd + 'python',
ecd + 'grib_templates',
ecd + 'src'])
try:
os.makedirs(c.flexpart_root_scripts + '/ECMWFDATA7.0')
except:
pass
os.chdir(c.flexpart_root_scripts + '/ECMWFDATA7.0')
p=subprocess.check_call(['tar','-xvf',ecd+'../ECMWFDATA7.0.tar'])
p = subprocess.check_call(['tar', '-xvf',
ecd + '../ECMWFDATA7.0.tar'])
os.chdir(c.flexpart_root_scripts + '/ECMWFDATA7.0/src')
os.chdir('../src')
print 'install ECMWFDATA7.0 software on '+target+' in directory '+os.getcwd()
if c.makefile==None:
print(('install ECMWFDATA7.0 software on ' + target + ' in directory '
+ os.getcwd()))
if c.makefile is None:
makefile = 'Makefile.local.ifort'
else:
makefile = c.makefile
......@@ -155,41 +168,71 @@ def install_via_gateway(c,target):
if flist:
p = subprocess.check_call(['rm'] + flist)
try:
print 'Using makefile: '+makefile
print(('Using makefile: ' + makefile))
p = subprocess.check_call(['make', '-f', makefile])
p = subprocess.check_call(['ls', '-l',' CONVERT2'])
except:
print 'compile failed - please edit '+makefile+' or try another Makefile in the src directory.'
print 'most likely GRIB_API_INCLUDE_DIR, GRIB_API_LIB and EMOSLIB must be adapted.'
print 'Available Makefiles:'
print glob.glob('Makefile*')
print('compile failed - please edit ' + makefile +
' or try another Makefile in the src directory.')
print('most likely GRIB_API_INCLUDE_DIR, GRIB_API_LIB \
and EMOSLIB must be adapted.')
print('Available Makefiles:')
print(glob.glob('Makefile*'))
elif target.lower() == 'ecgate':
os.chdir('/')
p=subprocess.check_call(['tar','-cvf',ecd+'../ECMWFDATA7.0.tar',ecd+'python',ecd+'grib_templates',ecd+'src'])
p = subprocess.check_call(['tar', '-cvf',
ecd + '../ECMWFDATA7.0.tar',
ecd + 'python',
ecd + 'grib_templates',
ecd + 'src'])
try:
p=subprocess.check_call(['ecaccess-file-put',ecd+'../ECMWFDATA7.0.tar','ecgate:/scratch/ms/'+c.ecgid+'/'+c.ecuid+'/ECMWFDATA7.0.tar'])
p = subprocess.check_call(['ecaccess-file-put',
ecd + '../ECMWFDATA7.0.tar',
'ecgate:/scratch/ms/' + c.ecgid + '/' +
c.ecuid + '/ECMWFDATA7.0.tar'])
except:
print 'ecaccess-file-put failed! Probably the eccert key has expired.'
print('ecaccess-file-put failed! Probably the eccert key has expired.')
exit(1)
p=subprocess.check_call(['ecaccess-job-submit','-queueName',target,ecd+'python/compilejob.ksh'])
print 'compilejob.ksh has been submitted to ecgate for installation in '+c.ec_flexpart_root_scripts+'/ECMWFDATA7.0'
print 'You should get an email with subject flexcompile within the next few minutes'
p = subprocess.check_call(['ecaccess-job-submit',
'-queueName',
target,
ecd + 'python/compilejob.ksh'])
print('compilejob.ksh has been submitted to ecgate for \
installation in ' + c.ec_flexpart_root_scripts +
'/ECMWFDATA7.0')
print('You should get an email with subject flexcompile within \
the next few minutes')
elif target.lower() == 'cca':
os.chdir('/')
p=subprocess.check_call(['tar','-cvf',ecd+'../ECMWFDATA7.0.tar',ecd+'python',ecd+'grib_templates',ecd+'src'])
p = subprocess.check_call(['tar', '-cvf',
ecd + '../ECMWFDATA7.0.tar',
ecd + 'python',
ecd + 'grib_templates',
ecd + 'src'])
try:
p=subprocess.check_call(['ecaccess-file-put',ecd+'../ECMWFDATA7.0.tar','cca:/scratch/ms/'+c.ecgid+'/'+c.ecuid+'/ECMWFDATA7.0.tar'])
p = subprocess.check_call(['ecaccess-file-put',
ecd + '../ECMWFDATA7.0.tar',
'cca:/scratch/ms/' + c.ecgid + '/' +
c.ecuid + '/ECMWFDATA7.0.tar'])
except:
print 'ecaccess-file-put failed! Probably the eccert key has expired.'
print('ecaccess-file-put failed! \
Probably the eccert key has expired.')
exit(1)
p=subprocess.check_call(['ecaccess-job-submit','-queueName',target,ecd+'python/compilejob.ksh'])
print 'compilejob.ksh has been submitted to cca for installation in '+c.ec_flexpart_root_scripts+'/ECMWFDATA7.0'
print 'You should get an email with subject flexcompile within the next few minutes'
p=subprocess.check_call(['ecaccess-job-submit',
'-queueName',
target,
ecd + 'python/compilejob.ksh']))
print('compilejob.ksh has been submitted to cca for installation in ' +
c.ec_flexpart_root_scripts + '/ECMWFDATA7.0')
print('You should get an email with subject flexcompile \
within the next few minutes')
else:
print 'ERROR: unknown installation target ',target
print 'Valid targets: ecgate, cca, local'
print('ERROR: unknown installation target ', target)
print('Valid targets: ecgate, cca, local')
return
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment