Skip to content

Commit

Permalink
Fixed bug where task logs could not be retrieved
Browse files Browse the repository at this point in the history
  • Loading branch information
jjjake committed Jun 28, 2018
1 parent db5ef8a commit 0c555a7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
22 changes: 10 additions & 12 deletions internetarchive/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class Catalog(object):

def __init__(self, archive_session,
identifier=None,
task_ids=None,
task_id=None,
params=None,
config=None,
verbose=None,
Expand All @@ -78,8 +78,8 @@ def __init__(self, archive_session,
:param identifier: (optional) The Archive.org identifier for which to retrieve
tasks for.
:type task_ids: int or str
:param task_ids: (optional) The task_ids to retrieve from the Archive.org catalog.
:type task_id: int or str
:param task_id: (optional) The task_id to retrieve from the Archive.org catalog.
:type params: dict
:param params: (optional) The URL parameters to send with each request sent to the
Expand All @@ -93,7 +93,7 @@ def __init__(self, archive_session,
each catalog task returned. Verbose is set to ``True`` by default.
"""
task_ids = [] if not task_ids else task_ids
task_id = [] if not task_id else task_id
params = {} if not params else params
config = {} if not config else config
verbose = '1' if verbose is None or verbose is True else '0'
Expand Down Expand Up @@ -124,23 +124,21 @@ def __init__(self, archive_session,
)
self.params.update(params)
# Return user's current tasks as default.
if not identifier and not task_ids and not params:
if not identifier and not task_id and not params:
self.params['justme'] = 1

if task_ids:
if not isinstance(task_ids, (set, list)):
task_ids = [task_ids]
task_ids = [str(t) for t in task_ids]
if task_id:
task_id = str(task_id)
self.params.update(dict(
where='task_id in({tasks})'.format(tasks=','.join(task_ids)),
search_task_id=task_id,
history=999999999999999999999, # TODO: is there a better way?
))

if identifier:
self.url = '{0}//archive.org/history/{1}'.format(self.session.protocol,
identifier)
elif task_ids:
self.url = '{0}//cat-tracey.archive.org/catalog.php'.format(
elif task_id:
self.url = '{0}//catalogd.archive.org/catalog.php'.format(
self.session.protocol)
else:
self.url = '{0}//archive.org/catalog.php'.format(self.session.protocol)
Expand Down
4 changes: 2 additions & 2 deletions internetarchive/cli/ia_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def main(argv, session):
task_type=task_type,
params=params)
elif args['--get-task-log']:
task = session.get_tasks(task_ids=args['--get-task-log'], params=params)
task = session.get_tasks(task_id=args['--get-task-log'], params=params)
if task:
log = task[0].task_log()
sys.exit(print(log))
Expand All @@ -85,7 +85,7 @@ def main(argv, session):
'for {0}\n'.format(args['--get-task-log']), file=sys.stderr)
sys.exit(1)
elif args['--task']:
tasks = session.get_tasks(task_ids=args['--task'], params=params)
tasks = session.get_tasks(task_id=args['--task'], params=params)
else:
tasks = session.get_tasks(task_type=task_type, params=params)
except ValueError as exc:
Expand Down
8 changes: 4 additions & 4 deletions internetarchive/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def search_items(self, query,

def get_tasks(self,
identifier=None,
task_ids=None,
task_id=None,
task_type=None,
params=None,
config=None,
Expand All @@ -303,8 +303,8 @@ def get_tasks(self,
:param identifier: (optional) The Archive.org identifier for which to retrieve
tasks for.
:type task_ids: int or str
:param task_ids: (optional) The task_ids to retrieve from the Archive.org catalog.
:type task_id: int or str
:param task_id: (optional) The task_id to retrieve from the Archive.org catalog.
:type task_type: str
:param task_type: (optional) The type of tasks to retrieve from the Archive.org
Expand All @@ -328,7 +328,7 @@ def get_tasks(self,
request_kwargs = {} if not request_kwargs else request_kwargs
_catalog = Catalog(self,
identifier=identifier,
task_ids=task_ids,
task_id=task_id,
params=params,
config=config,
verbose=verbose,
Expand Down

0 comments on commit 0c555a7

Please sign in to comment.