Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python3 support #43

Open
wants to merge 25 commits into
base: python3-support
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
4081f09
add support for file parameters
aicardi-obspm Feb 7, 2019
80f8440
python 3 support for cli
aicardi-obspm Mar 14, 2019
edd0fe2
Fix unicode
aicardi-obspm Jan 30, 2020
8f5f998
Fixes python version for Travis
aicardi-obspm Jan 30, 2020
0e325ff
Check type of xml
aicardi-obspm Jan 30, 2020
4861c39
Fix for travis ?
aicardi-obspm Jan 30, 2020
299f4ef
debug nosetests on travis
aicardi-obspm Jan 30, 2020
4337be4
ends debug on travis, should fix nosetests
aicardi-obspm Jan 30, 2020
6abc171
pylint first pass
aicardi-obspm Jan 31, 2020
1fe2338
python3 way of getting terminal size
aicardi-obspm Jan 31, 2020
e9ee193
full supression of terminalsize
aicardi-obspm Jan 31, 2020
5bcee76
pylint : long lines
aicardi-obspm Jan 31, 2020
d5c3d61
pylint : fix imports
aicardi-obspm Jan 31, 2020
226811f
pylint : fixes spaces
aicardi-obspm Jan 31, 2020
9393a76
pylint : fixes unnecessary parens after if
aicardi-obspm Jan 31, 2020
c48375f
pylint : fixes redefined-builtin
aicardi-obspm Jan 31, 2020
ff5a37f
pylint : fixes dangerous-default-value
aicardi-obspm Jan 31, 2020
85969a5
pylint : fixes bare-except
aicardi-obspm Jan 31, 2020
561b533
pylint: fixes deprecated-method
aicardi-obspm Jan 31, 2020
3d86a8f
pylint: fixes useless-object-inheritance
aicardi-obspm Jan 31, 2020
d148c15
pylint : fixes no-self-use
aicardi-obspm Jan 31, 2020
8d6cd0b
pylint: fixes inconsistent-return-statements
aicardi-obspm Jan 31, 2020
b3cc4da
pylint : fixes import-outside-toplevel
aicardi-obspm Jan 31, 2020
e63b1eb
pylint
aicardi-obspm Jan 31, 2020
1342e27
pylint: fixes invalid-name
aicardi-obspm Jan 31, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ cache:
directories:
- $HOME/virtualenv
python:
- 2.7
- 3.7
install:
- pip install -r requirements.pip
- pip install -r requirements-dev.pip
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
setup(
name='uws-client',
version=version,
url='http://github.com/aipescience/uws-client/',
download_url='http://github.com/aipescience/uws-client/archive/%s.tar.gz' % version,
url='http://github.com/aicardi-obspm/uws-client/',
download_url='http://github.com/aicardi-obspm/uws-client/archive/%s.tar.gz' % version,
packages=find_packages(),
license=u'Apache License (2.0)',
author=u'Adrian M. Partl',
author_email='[email protected]',
maintainer=u'AIP E-Science',
maintainer_email=u'[email protected]',
description=u'A command line client for IVOA UWS services, plus models for development',
long_description='This is a client for IVOA Virtual Observatroy UWS services. It can be used to access UWS services directly or through Basic Authentication. Please visit https://github.com/aipescience/uws-client/blob/master/README.md for how to use the software.',
long_description='This is a client for IVOA Virtual Observatroy UWS services. It can be used to access UWS services directly or through Basic Authentication. Please visit https://github.com/aicardi-obspm/uws-client/blob/master/README.md for how to use the software.',
include_package_data=True,
install_requires=install_requires,
entry_points={
Expand Down
1 change: 0 additions & 1 deletion uws/UWS/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@
from . import connection
from . import models
from .errors import UWSError

160 changes: 87 additions & 73 deletions uws/UWS/client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- coding: utf-8 -*-
from lxml.etree import XMLSyntaxError as XMLSyntaxError
from lxml.etree import XMLSyntaxError
import dateutil.parser
import pytz

#import connection as UWSConnection
#import models
Expand All @@ -8,12 +10,9 @@
from . import connection as UWSConnection
from . import models
from .errors import UWSError
from datetime import datetime
import dateutil.parser
import pytz


class Client(object):
class Client:
def __init__(self, url=None, user=None, password=None, connection=None):
if connection:
self.connection = connection
Expand All @@ -28,56 +27,61 @@ def get_job_list(self, filters=None):

try:
response = self.connection.get('', params)
except Exception as e:
except Exception as exc:
# Do not try to make a second request without parameters here,
# because cannot call self.connection.get() a second time and reusing the connection
# without calling a getresponse() or close() or something beforehand.
# (This would lead to a httplib CannotSendRequest() error!)
# Let's just raise the error immediately.
raise UWSError(str(e))
raise UWSError(str(exc))

raw = response.read()

try:
job_list = models.Jobs(raw)
except XMLSyntaxError as e:
raise UWSError("Malformatted response. Are you sure the host you specified is a IVOA UWS service?", raw)
except Exception as e:
raise e
except XMLSyntaxError as exc:
raise UWSError("Malformatted response. Are you sure the host you specified is a "
"IVOA UWS service?", raw)
except Exception as exc:
raise exc

return job_list

def _validate_and_parse_filters(self, filters):
@staticmethod
def _validate_and_parse_filters(filters):
filters_copy = filters.copy()
phases = filters_copy.pop('phases', None)
after = filters_copy.pop('after', None)
last = filters_copy.pop('last', None)

if filters_copy:
raise UWSError("Unknown filter properties %s", filters_copy.keys())
raise UWSError(f"Unknown filter properties {filters_copy.keys()}")

params = []

if phases:
for phase in phases:
if phase not in models.JobPhases.phases:
raise UWSError("Unknown phase %s in filter", phase)
raise UWSError(f"Unknown phase {phase} in filter")
params.append(("PHASE", phase))

if after:
# TODO: Allow to provide local time and convert here to UTC?
# TODO: We may encounter more troubles with microseconds, if ',' used instead of '.'(e.g. German systems)
# TODO: We may encounter more troubles with microseconds,
# if ',' used instead of '.'(e.g. German systems)

try:
date = dateutil.parser.parse(after)
# The day defaults to current day, not to '01', if no day is
# given (e.g. '2010-09'->'2010-09-06').
# Let's tell the user how the given value was interpreted:
if str(date) != str(after):
print("Note: Changed value for keyword 'after' from '%s' to '%s'." % (after, str(date)))
print(f"Note: Changed value for keyword 'after' from '{after}' "
f"to '{str(date)}'.")

except:
raise UWSError("Date time format could not be parsed, expecting UTC in ISO 8601:2004 format or compatible: %s" % (str(after)))
raise UWSError("Date time format could not be parsed, expecting UTC in "
"ISO 8601:2004 format or compatible: %s" % (str(after)))

# Convert from given time (with attached timezone information) to UTC time
if date.utcoffset() is not None:
Expand All @@ -92,15 +96,16 @@ def _validate_and_parse_filters(self, filters):
try:
last = int(last)
except:
raise UWSError("Value for 'last' argument must be a positive integer: %s" % (str(last)))
raise UWSError(f"Value for 'last' argument must be a positive integer: {str(last)}")

if last < 1:
raise UWSError("Value for 'last' argument must be a positive integer: %s" % (str(last)))
raise UWSError(f"Value for 'last' argument must be a positive integer: {str(last)}")
params.append(("LAST", last))

return params

def _validate_and_parse_wait(self, wait, phase=None):
@staticmethod
def _validate_and_parse_wait(wait, phase=None):
# wait must be positive integer or -1
if wait.isdigit() or wait == '-1':
duration = int(wait)
Expand All @@ -111,120 +116,129 @@ def _validate_and_parse_wait(self, wait, phase=None):

if phase:
if phase not in models.JobPhases.active_phases:
raise UWSError("Given phase '%s' is not an active phase, 'wait' with this phase is not supported." % phase)
raise UWSError(f"Given phase '{phase}' is not an active phase, "
"'wait' with this phase is not supported.")
params.append(("PHASE", phase))

return params

def get_job(self, id, wait=None, phase=None):
def get_job(self, jid, wait=None, phase=None):
params = None
if wait:
params = self._validate_and_parse_wait(wait, phase)

try:
response = self.connection.get(id, params)
except Exception as e:
response = self.connection.get(jid, params)
except Exception as exc:
# Do not make a second request without params, throw error
# immediately
raise UWSError(str(e))
raise UWSError(str(exc))

raw = response.read()
try:
result = models.Job(raw)
except XMLSyntaxError as e:
raise UWSError("Malformatted response. Are you sure the host you specified is a IVOA UWS service?", raw)
except Exception as e:
raise e
except XMLSyntaxError as exc:
raise UWSError("Malformatted response. Are you sure the host you specified is a "
"IVOA UWS service?", raw)
except Exception as exc:
raise exc

return result

def get_phase(self, id):
def get_phase(self, jid):
try:
response = self.connection.get(id + '/phase')
except Exception as e:
raise UWSError(str(e))
response = self.connection.get(jid + '/phase')
except Exception as exc:
raise UWSError(str(exc))

raw = response.read()
result = raw
result = str(raw, 'utf-8')

return result

def new_job(self, args={}):
def new_job(self, args=None):
args = args or {}
try:
response = self.connection.post('', args)
except Exception as e:
raise UWSError(str(e))
except Exception as exc:
raise UWSError(str(exc))

raw = response.read()
try:
result = models.Job(raw)
except XMLSyntaxError as e:
raise UWSError("Malformatted response. Are you sure the host you specified is a IVOA UWS service?", raw)
except Exception as e:
raise
except XMLSyntaxError as exc:
raise UWSError("Malformatted response. Are you sure the host you specified is a "
"IVOA UWS service?", raw)
except Exception as exc:
raise exc

return result

def set_parameters_job(self, id, args={}):
def set_parameters_job(self, jid, args=None):
args = args or {}
try:
response = self.connection.post(id, args)
except Exception as e:
raise UWSError(str(e))
response = self.connection.post(jid, args)
except Exception as exc:
raise UWSError(str(exc))

raw = response.read()
try:
result = models.Job(raw)
except XMLSyntaxError as e:
raise UWSError("Malformatted response. Are you sure the host you specified is a IVOA UWS service?", raw)
except Exception as e:
raise e
except XMLSyntaxError as exc:
raise UWSError("Malformatted response. Are you sure the host you specified is a "
"IVOA UWS service?", raw)
except Exception as exc:
raise exc

return result

def run_job(self, id):
def run_job(self, jid):
try:
response = self.connection.post(id + '/phase', {"PHASE": "RUN"})
except Exception as e:
raise UWSError(str(e))
response = self.connection.post(jid + '/phase', {"PHASE": "RUN"})
except Exception as exc:
raise UWSError(str(exc))

raw = response.read()
try:
result = models.Job(raw)
except XMLSyntaxError as e:
raise UWSError("Malformatted response. Are you sure the host you specified is a IVOA UWS service?", raw)
except Exception as e:
raise e
except XMLSyntaxError as exc:
raise UWSError("Malformatted response. Are you sure the host you specified is a "
"IVOA UWS service?", raw)
except Exception as exc:
raise exc

return result

def abort_job(self, id):
def abort_job(self, jid):
try:
response = self.connection.post(id, {"PHASE": "ABORT"})
except Exception as e:
raise UWSError(str(e))
response = self.connection.post(jid, {"PHASE": "ABORT"})
except Exception as exc:
raise UWSError(str(exc))

raw = response.read()
try:
result = models.Job(raw)
except XMLSyntaxError as e:
raise UWSError("Malformatted response. Are you sure the host you specified is a IVOA UWS service?", raw)
except Exception as e:
raise e
except XMLSyntaxError as exc:
raise UWSError("Malformatted response. Are you sure the host you specified is a IVOA "
"UWS service?", raw)
except Exception as exc:
raise exc

return result

def delete_job(self, id):
def delete_job(self, jid):
try:
response = self.connection.delete(id)
except Exception as e:
raise UWSError(str(e))
response = self.connection.delete(jid)
except Exception as exc:
raise UWSError(str(exc))

raw = response.read()
try:
result = True
except XMLSyntaxError as e:
raise UWSError("Malformatted response. Are you sure the host you specified is a IVOA UWS service?", raw)
except Exception as e:
raise e
except XMLSyntaxError as exc:
raise UWSError("Malformatted response. Are you sure the host you specified is a IVOA "
"UWS service?", raw)
except Exception as exc:
raise exc

return result
Loading