Commit 9b004fb0 authored by Koren, Gerbrand's avatar Koren, Gerbrand
Browse files

Revert "Change to python 3"

This reverts commit d55eb3bd.
parent f7701848
......@@ -48,7 +48,7 @@ WEEKDAYS = (MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY)
def validate_rc(rcfile, needed_items):
""" validate the contents of an rc-file given a dictionary of required keys """
for k, v in list(rcfile.items()):
for k, v in rcfile.items():
if v == 'True' :
rcfile[k] = True
if v == 'False':
......@@ -57,7 +57,7 @@ def validate_rc(rcfile, needed_items):
rcfile[k] = datetime.datetime.strptime(v, '%Y-%m-%d %H:%M:%S')
for key in needed_items:
if key not in rcfile:
if not rcfile.has_key(key):
msg = 'Missing a required value in rc-file : %s' % key
logging.error(msg)
raise IOError(msg)
......@@ -116,8 +116,8 @@ def to_datetime(datestring, fmt=None):
return datetime.datetime.strptime(datestring, '%Y-%m-%d %H:%M:%S')
except:
date, time = datestring.split(' ')
year, month, day = list(map(int, date.split('-')))
hour, minute, second = list(map(int, time.split(':')))
year, month, day = map(int, date.split('-'))
hour, minute, second = map(int, time.split(':'))
return datetime.datetime(year, month, day, hour, minute, second)
......@@ -156,14 +156,14 @@ def name_convert(name=None, to=None):
except:
return ""
platform_num = [ v for k, v in list(platform_dict.items()) if platform.lower() == k ]
platform_num = [ v for k, v in platform_dict.items() if platform.lower() == k ]
if len(platform_num) == 0:
print(('%s: Platform %s not found in platform dict.' % (identifier, platform)))
print('%s: Platform %s not found in platform dict.' % (identifier, platform))
return ""
strategy_char = [ v for k, v in list(strategy_dict.items()) if strategy.lower() == k ]
strategy_char = [ v for k, v in strategy_dict.items() if strategy.lower() == k ]
if len(strategy_char) == 0:
print(('%s: Strategy %s not found in strategy dict.' % (identifier, strategy)))
print('%s: Strategy %s not found in strategy dict.' % (identifier, strategy))
return ""
return "%s_%2.2d%1s%1d" % (code, lab_num, strategy_char[0].upper(), int(platform_num[0]))
......@@ -181,15 +181,15 @@ def name_convert(name=None, to=None):
except:
return ""
platform = [ k for k, v in list(platform_dict.items()) if v == platform_num ]
platform = [ k for k, v in platform_dict.items() if v == platform_num ]
if len(platform) == 0:
print(('%s: Platform number %s not found in platform dict.' % (identifier, platform_num)))
print('%s: Platform number %s not found in platform dict.' % (identifier, platform_num))
return ""
pattern = re.compile(strategy_char, re.IGNORECASE)
strategy = [ k for k, v in list(strategy_dict.items()) if pattern.search(v) ]
strategy = [ k for k, v in strategy_dict.items() if pattern.search(v) ]
if len(strategy) == 0:
print(('%s: Strategy character %s not found in strategy list.' % (identifier, strategy_char)))
print('%s: Strategy character %s not found in strategy list.' % (identifier, strategy_char))
return ""
return "%s_%s-%s_%d" % (code, platform[0], strategy[0], lab_num)
......
......@@ -138,7 +138,7 @@ class CycleControl(dict):
"""
rcdata = rc.read(rcfilename)
for k, v in list(rcdata.items()):
for k, v in rcdata.items():
self[k] = v
logging.info('DA Cycle rc-file (%s) loaded successfully' % rcfilename)
......@@ -150,7 +150,7 @@ class CycleControl(dict):
Currently required keys are :attr:`~da.tools.initexit.needed_da_items`
"""
for k, v in list(self.items()):
for k, v in self.items():
if v in ['True', 'true', 't', 'T', 'y', 'yes']:
self[k] = True
if v in ['False', 'false', 'f', 'F', 'n', 'no']:
......
......@@ -95,7 +95,7 @@ class CT_CDF(netCDF4.Dataset):
def add_params_dim(self,nparams):
if 'nparameters' in list(self.dimensions.keys()):
if 'nparameters' in self.dimensions.keys():
pass
else:
dimparams=self.createDimension('nparameters',size=nparams)
......@@ -104,7 +104,7 @@ class CT_CDF(netCDF4.Dataset):
def add_members_dim(self,nmembers):
if 'nmembers' in list(self.dimensions.keys()):
if 'nmembers' in self.dimensions.keys():
pass
else:
dimmembers=self.createDimension('nmembers',size=nmembers)
......@@ -113,7 +113,7 @@ class CT_CDF(netCDF4.Dataset):
def add_lag_dim(self,nlag,unlimited=True):
if 'nlag' in list(self.dimensions.keys()):
if 'nlag' in self.dimensions.keys():
pass
else:
if unlimited:
......@@ -125,7 +125,7 @@ class CT_CDF(netCDF4.Dataset):
def add_obs_dim(self,nobs):
if 'nobs' in list(self.dimensions.keys()):
if 'nobs' in self.dimensions.keys():
pass
else:
dimobs = self.createDimension('nobs',size=nobs)
......@@ -136,7 +136,7 @@ class CT_CDF(netCDF4.Dataset):
from numpy import arange, float64
if 'latitude' in list(self.dimensions.keys()): return ('latitude','longitude',)
if 'latitude' in self.dimensions.keys(): return ('latitude','longitude',)
lons=-180+arange(360)*1.0+0.5
lats=-90+arange(180)*1.0+0.5
......@@ -171,7 +171,7 @@ class CT_CDF(netCDF4.Dataset):
dimname='regions_%s' % type
if dimname in list(self.dimensions.keys()):
if dimname in self.dimensions.keys():
return (dimname,)
if type == 'olson':
......@@ -207,7 +207,7 @@ class CT_CDF(netCDF4.Dataset):
def add_date_dim(self,unlimited=False):
if 'date' in list(self.dimensions.keys()):
if 'date' in self.dimensions.keys():
pass
else:
dimdate = self.createDimension('date',size=None)
......@@ -216,7 +216,7 @@ class CT_CDF(netCDF4.Dataset):
def add_date_dim_format(self):
if 'yyyymmddhhmmss' in list(self.dimensions.keys()):
if 'yyyymmddhhmmss' in self.dimensions.keys():
pass
else:
dimdateformat = self.createDimension('yyyymmddhhmmss',size=6)
......@@ -224,7 +224,7 @@ class CT_CDF(netCDF4.Dataset):
def add_dim(self,dimname,dimsize):
if dimname in list(self.dimensions.keys()):
if dimname in self.dimensions.keys():
pass
else:
newdim = self.createDimension(dimname,dimsize)
......@@ -260,7 +260,7 @@ class CT_CDF(netCDF4.Dataset):
""" return properties of standard variables """
from . import standardvariables
if varname in list(standardvariables.standard_variables.keys()):
if varname in standardvariables.standard_variables.keys():
return standardvariables.standard_variables[varname]
else:
return standardvariables.standard_variables['unknown']
......@@ -269,7 +269,7 @@ class CT_CDF(netCDF4.Dataset):
""" return lenght of unlimited dimenion(s) """
unlims=()
for dimname, dimobj in list(self.dimensions.items()):
for dimname, dimobj in self.dimensions.items():
if dimobj.isunlimited() : unlims += (len(dimobj),)
return unlims
......@@ -277,7 +277,7 @@ class CT_CDF(netCDF4.Dataset):
def has_unlimlen(self,dims):
""" return T/F whether dimensions include an unlimited dimenion(s) """
for dimname, dimobj in list(self.dimensions.items()):
for dimname, dimobj in self.dimensions.items():
if dimname in dims:
if dimobj.isunlimited() : return True
......@@ -292,7 +292,7 @@ class CT_CDF(netCDF4.Dataset):
if datadict['name'] in existing_vars:
return
else:
if not silent: print(('Creating new dataset: '+datadict['name']))
if not silent: print('Creating new dataset: '+datadict['name'])
if 'dtype' in datadict:
if datadict['dtype'] == 'int':
......@@ -310,7 +310,7 @@ class CT_CDF(netCDF4.Dataset):
else:
var = self.createVariable(datadict['name'],'f4',datadict['dims'])
for k,v in list(datadict.items()):
for k,v in datadict.items():
if k not in ['name','dims','values','_FillValue','count']:
var.setncattr(k,v)
......@@ -348,7 +348,7 @@ class CT_CDF(netCDF4.Dataset):
raise ValueError
else:
if not silent: print(('Creating new dataset: '+datadict['name']))
if not silent: print('Creating new dataset: '+datadict['name'])
if 'dtype' in datadict:
if datadict['dtype'] == 'int':
......@@ -366,7 +366,7 @@ class CT_CDF(netCDF4.Dataset):
else:
var = self.createVariable(datadict['name'],'f4',datadict['dims'])#,fill_value=datadict['_FillValue'])
for k,v in list(datadict.items()):
for k,v in datadict.items():
if k not in ['name','dims','values','_FillValue','count']:
var.setncattr(k,v)
......@@ -426,7 +426,7 @@ try:
""" return properties of standard variables """
from . import standardvariables
if varname in list(standardvariables.standard_variables.keys()):
if varname in standardvariables.standard_variables.keys():
return standardvariables.standard_variables[varname]
else:
return standardvariables.standard_variables['unknown']
......@@ -468,7 +468,7 @@ if __name__ == '__main__':
import numpy as np
ncf=CT_CDF('test.nc','create')
print((ncf.file_format))
print(ncf.file_format)
dimmembers=ncf.add_members_dim(200)
dimparams=ncf.add_params_dim(200)
......
......@@ -938,7 +938,7 @@ class RcFile(object) :
def keys(self) :
# from dictionairy:
return list(self.values.keys())
return self.values.keys()
#enddef
......@@ -1171,7 +1171,7 @@ def write(filename, rcdict) :
f = open(filename, 'w')
# loop over key/value pairs:
for k, v in list(rcdict.items()):
for k, v in rcdict.items():
# add line; at least the specified number of characters
# is used for the key:
f.write('%-20s:%s\n' % (k, v))
......@@ -1248,7 +1248,7 @@ if __name__ == '__main__':
# print pre-processed file ?
if opts.write :
for line in rcf.outfile : print((line.strip()))
for line in rcf.outfile : print(line.strip())
sys.exit(0)
#endif
......@@ -1284,9 +1284,9 @@ if __name__ == '__main__':
# default value provided ?
if opts.default != None :
# display:
print((opts.default))
print(opts.default)
else :
print(('ERROR - key "%s" not found in rcfile "%s" and no default specified' % (rckey, rcfile)))
print('ERROR - key "%s" not found in rcfile "%s" and no default specified' % (rckey, rcfile))
sys.exit(1)
#endif
......
......@@ -260,7 +260,7 @@ class RcFile(object) :
# check ...
if not os.path.exists(filename) :
msg = 'rcfile not found : %s' % filename ; logging.error(msg)
raise IOError(msg)
raise IOError, msg
#endif
# store file name:
......@@ -516,14 +516,14 @@ class RcFile(object) :
# remove enclosing characters:
key = pat.lstrip(start_mark).rstrip(close_mark)
# test some dictionaries for matching key:
if key in self.values :
if self.values.has_key(key) :
# get previously defined value:
val = self.values[key]
# substitute value:
line = line.replace(pat, val)
# set flag:
something_done = True
elif key in os.environ :
elif os.environ.has_key(key) :
# get value from environment:
val = os.environ[key]
# substitute value:
......@@ -579,7 +579,7 @@ class RcFile(object) :
if not os.path.exists(inc_file) :
logging.error('include file not found : %s' % inc_file)
msg = 'ERROR - include file not found : %s' % inc_file
raise IOError(msg)
raise IOError, msg
#endif
# read content:
inc_f = open(inc_file, 'r')
......@@ -718,7 +718,7 @@ class RcFile(object) :
val = val.strip()
# already defined ?
if key in self.values :
if self.values.has_key(key) :
# no problem if values are the same, but otherwise ...
if self.values[key] != val :
logging.error('key found twice in "%s" :' % filename)
......@@ -792,7 +792,7 @@ class RcFile(object) :
def has_key(self, key) :
# from dictionairy:
return key in self.values
return self.values.has_key(key)
#enddef
......@@ -803,7 +803,7 @@ class RcFile(object) :
def keys(self) :
# from dictionairy:
return list(self.values.keys())
return self.values.keys()
#enddef
......@@ -828,7 +828,7 @@ class RcFile(object) :
"""
# element found ?
if key in self.values :
if self.values.has_key(key) :
# copy value:
value = self.values[key]
# convert ?
......@@ -961,7 +961,7 @@ class RcFile(object) :
# remove enclosing characters:
key = pat.lstrip(start_mark).rstrip(close_mark)
# test dictionary for matching key:
if key in self.values :
if self.values.has_key(key) :
# get previously defined value:
val = self.values[key]
# substitute value:
......@@ -1023,7 +1023,7 @@ def write(filename, rcdict):
f = open(filename, 'w')
# loop over key/value pairs:
for k, v in list(rcdict.items()):
for k, v in rcdict.items():
# add line; at least the specified number of characters
# is used for the key:
f.write('%-20s:%s\n' % (k, v))
......@@ -1075,7 +1075,7 @@ if __name__ == '__main__':
# print documentation ?
if opts.doc :
print(__doc__)
print __doc__
sys.exit(0)
#endif
......@@ -1096,7 +1096,7 @@ if __name__ == '__main__':
# print pre-processed file ?
if opts.write :
for line in rcf.outfile : print(line.strip())
for line in rcf.outfile : print line.strip()
sys.exit(0)
#endif
......@@ -1108,7 +1108,7 @@ if __name__ == '__main__':
rckey = args[1]
# key present ?
if rckey in rcf :
if rcf.has_key(rckey) :
# print requested value:
if opts.boolean :
......@@ -1116,15 +1116,15 @@ if __name__ == '__main__':
flag = rcf.get(rckey, 'bool')
# print result:
if flag :
print('True')
print 'True'
else :
print('False')
print 'False'
#endif
else :
# extract value:
value = rcf.get(rckey)
# display:
print(value)
print value
#endif
else :
......@@ -1132,9 +1132,9 @@ if __name__ == '__main__':
# default value provided ?
if opts.default != None :
# display:
print(opts.default)
print opts.default
else :
print('ERROR - key "%s" not found in rcfile "%s" and no default specified' % (rckey, rcfile))
print 'ERROR - key "%s" not found in rcfile "%s" and no default specified' % (rckey, rcfile)
sys.exit(1)
#endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment