Commit 8f73b2ff authored by Thomas Jürges's avatar Thomas Jürges

Add Python3 compatibility

parent b2c2c615
......@@ -7,35 +7,46 @@
# !! This is to ensure that when we change the remote interface, your scripts don't break and you will only have to
# !! upgrade this module.
__version__ = "1.2"
__version__ = "1.3"
import xmlrpclib
import datetime
from os.path import expanduser
from astropy.utils.compat.futures import process
# Python2/3 dependent stuff
from sys import version_info
python_version = version_info.major
if python_version == 3:
import xmlrpc.client as xmlrpclib
string_types = str
else:
import xmlrpclib
string_types = basestring
#---
# Determine credentials and create proxy
user = None
passw = None
try:
with open(expanduser("~/.awe/Environment.cfg"),'r') as file:
print datetime.datetime.now(), "stager_access: Parsing user credentials from", expanduser("~/.awe/Environment.cfg")
f = expanduser("~/.awe/Environment.cfg")
with open(f,'r') as file:
print("%s - stager_access: Parsing user credentials from \"%s\"" % (datetime.datetime.now(), f))
for line in file:
if line.startswith("database_user"):
user = line.split(':')[1].strip()
if line.startswith("database_password"):
passw = line.split(':')[1].strip()
except IOError:
with open(expanduser("~/.stagingrc"),'r') as file:
print datetime.datetime.now(), "stager_access: Parsing user credentials from", expanduser("~/.stagingrc")
f = expanduser("~/.stagingrc")
with open(f,'r') as file:
print("%s - stager_access: Parsing user credentials from \"%s\"" % (datetime.datetime.now(), f))
for line in file:
if line.startswith("user"):
user = line.split('=')[1].strip()
if line.startswith("password"):
passw = line.split('=', 1)[1].strip()
print datetime.datetime.now(), "stager_access: Creating proxy"
print("%s - stager_access: Creating proxy" % (datetime.datetime.now()))
proxy = xmlrpclib.ServerProxy("https://"+user+':'+passw+"@webportal.astron.nl/service-public/xmlrpc")
LtaStager = proxy.LtaStager
......@@ -77,11 +88,15 @@ def get_progress(status=None, exclude=False):
excluded.
"""
all_requests = proxy.LtaStager.getprogress()
if status is not None and isinstance(status, basestring):
if status is not None and isinstance(status, string_types):
if python_version == 3:
all_items = all_requests.items()
else:
all_items = all_requests.iteritems()
if exclude is False:
requests = {key: value for key, value in all_requests.iteritems() if value["Status"] == status}
requests = {key: value for key, value in all_items if value["Status"] == status}
else:
requests = {key: value for key, value in all_requests.iteritems() if value["Status"] != status}
requests = {key: value for key, value in all_items if value["Status"] != status}
else:
requests = all_requests
return requests
......@@ -91,7 +106,7 @@ def reschedule_on_status(status=None):
:param status: The status that a request has to have in order to be
rescheduled.
"""
if status is not None and isinstance(status, basestring) and (status == "on hold" or status == "aborted"):
if status is not None and isinstance(status, string_types) and (status == "on hold" or status == "aborted"):
requests = get_progress(status)
for key in requests.keys():
reschedule(int(key))
......@@ -108,12 +123,12 @@ def prettyprint(dictionary, indent=""):
for key in sorted(dictionary.keys()):
item = dictionary.get(key)
if type(item) is dict:
print indent+'+ ' +str(key)
print("%s+ %s" % (indent, str(key)))
prettyprint(item, indent=indent+' ')
else:
print indent+'- '+str(key),'\t -> \t',str(item)
print("%s- %s\t->\t%s" % (indent, str(key), str(item)))
else:
print "stager_access: This prettyprint takes a dict only!"
print("stager_access: This prettyprint takes a dict only!")
def reschedule_on_hold():
""" Reschedule requests that are on hold.
......
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