Commit c51340c6 authored by echel0n's avatar echel0n
Browse files

Refactored task action_id property to action

Added is_loading and is_removing properties to TV show object
parent 011d469d
......@@ -355,11 +355,11 @@ class WorkerThread(threading.Thread):
class Task(object):
def __init__(self, name, action_id=0, depend=None):
def __init__(self, name, action=0, depend=None):
super(Task, self).__init__()
self.name = name.replace(" ", "-").upper()
self.id = None
self.action_id = action_id
self.action = action
self.priority = TaskPriority.NORMAL
self.status = TaskStatus.QUEUED
self.added = None
......
......@@ -126,8 +126,8 @@ class PostProcessorQueue(Queue):
class PostProcessorTask(Task):
def __init__(self, dirName, nzbName=None, process_method=None, force=False, is_priority=None, delete_on=False, failed=False, proc_type="auto"):
action_id = (PostProcessorTaskActions.MANUAL, PostProcessorTaskActions.AUTO)[proc_type == "auto"]
super(PostProcessorTask, self).__init__(action_id.value, action_id)
action = (PostProcessorTaskActions.MANUAL, PostProcessorTaskActions.AUTO)[proc_type == "auto"]
super(PostProcessorTask, self).__init__(action.value, action)
self.dirName = dirName
self.nzbName = nzbName
......
......@@ -50,14 +50,14 @@ class ShowQueue(Queue):
def _is_in_queue(self, indexer_id, actions):
for task in self.tasks.copy().values():
if task.is_queued() and task.indexer_id == indexer_id and task.action_id in actions:
if task.is_queued() and task.indexer_id == indexer_id and task.action in actions:
return True
return False
def _is_being(self, indexer_id, actions):
for task in self.tasks.copy().values():
if task.is_started() and task.indexer_id == indexer_id and task.action_id in actions:
if task.is_started() and task.indexer_id == indexer_id and task.action in actions:
return True
return False
......@@ -196,8 +196,8 @@ class ShowTask(Task):
- show being subtitled
"""
def __init__(self, indexer_id, action_id):
super(ShowTask, self).__init__(action_id.value, action_id)
def __init__(self, indexer_id, action):
super(ShowTask, self).__init__(action.value, action)
self.indexer_id = indexer_id
def is_in_queue(self):
......@@ -216,11 +216,15 @@ class ShowTask(Task):
show_obj = find_show(self.indexer_id)
if show_obj:
WebSocketMessage('SHOW_QUEUE_STATUS_UPDATED', {'series_id': show_obj.indexer_id, 'show_queue_status': show_obj.show_queue_status}).push()
else:
WebSocketMessage('SHOW_QUEUE_STATUS_UPDATED', {'series_id': self.indexer_id, 'action': self.action.name}).push()
def finish(self):
show_obj = find_show(self.indexer_id)
if show_obj:
WebSocketMessage('SHOW_QUEUE_STATUS_UPDATED', {'series_id': show_obj.indexer_id, 'show_queue_status': show_obj.show_queue_status}).push()
else:
WebSocketMessage('SHOW_QUEUE_STATUS_UPDATED', {'series_id': self.indexer_id, 'action': self.action.name}).push()
class ShowTaskAdd(ShowTask):
......@@ -535,8 +539,8 @@ class ShowTaskSubtitle(ShowTask):
class ShowTaskUpdate(ShowTask):
def __init__(self, indexer_id=None, indexer_update_only=False, force=False, action_id=ShowTaskActions.UPDATE):
super(ShowTaskUpdate, self).__init__(indexer_id, action_id if not force else ShowTaskActions.FORCEUPDATE)
def __init__(self, indexer_id=None, indexer_update_only=False, force=False, action=ShowTaskActions.UPDATE):
super(ShowTaskUpdate, self).__init__(indexer_id, action if not force else ShowTaskActions.FORCEUPDATE)
self.indexer_update_only = indexer_update_only
self.force = force
......
......@@ -306,11 +306,11 @@ class TVEpisode(object):
for search_task in sickrage.app.search_queue.get_all_tasks_from_queue_by_show(self.showid):
if search_task.season == self.season and search_task.episode == self.episode:
if search_task.action_id in [SearchTaskActions.MANUAL_SEARCH, SearchTaskActions.FAILED_SEARCH]:
if search_task.action in [SearchTaskActions.MANUAL_SEARCH, SearchTaskActions.FAILED_SEARCH]:
search_queue_status['manual'] = search_task.status.name
elif search_task.action_id == SearchTaskActions.DAILY_SEARCH:
elif search_task.action == SearchTaskActions.DAILY_SEARCH:
search_queue_status['daily'] = search_task.status.name
elif search_task.action_id == SearchTaskActions.BACKLOG_SEARCH:
elif search_task.action == SearchTaskActions.BACKLOG_SEARCH:
search_queue_status['backlog'] = search_task.status.name
return search_queue_status
......
......@@ -575,6 +575,11 @@ class TVShow(object):
'action': 'ADD',
'message': _('This show is in the process of being downloaded - the info below is incomplete.')
}
elif sickrage.app.show_queue.is_being_removed(self.indexer_id):
return {
'action': 'REMOVE',
'message': _('This show is in the process of being removed.')
}
elif sickrage.app.show_queue.is_being_updated(self.indexer_id):
return {
'action': 'UPDATE',
......@@ -606,6 +611,16 @@ class TVShow(object):
'message': _('This show is queued and awaiting subtitles download.')
}
return {}
@property
def is_loading(self):
return self.show_queue_status.get('action') == 'ADD'
@property
def is_removing(self):
return self.show_queue_status.get('action') == 'REMOVE'
def save(self):
with self.lock, sickrage.app.main_db.session() as session:
sickrage.app.log.debug("{0:d}: Saving to database: {1}".format(self.indexer_id, self.name))
......@@ -1393,6 +1408,9 @@ class TVShow(object):
series = session.query(MainDB.TVShow).filter_by(indexer_id=self.indexer_id).one_or_none()
json_data = TVShowSchema().dump(series)
json_data['is_loading'] = self.is_loading
json_data['is_removing'] = self.is_removing
# images section
json_data['images'] = {
'poster': self.poster,
......
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
......@@ -141,7 +141,7 @@
<% showname = task.show_name %>
<td>${showname}</td>
% except Exception:
% if task.action_id == ShowTaskActions.ADD:
% if task.action == ShowTaskActions.ADD:
<td>${task.showDir}</td>
% else:
<td></td>
......@@ -160,7 +160,7 @@
<td>${task.priority}</td>
% endif
<td>${task.added.strftime(dateTimeFormat)}</td>
<td>${ShowTaskActions(task.action_id).value}</td>
<td>${ShowTaskActions(task.action).value}</td>
</tr>
% endfor
</tbody>
......
......@@ -68,6 +68,7 @@ class WebSocketMessage(object):
# message_queue.put(self.json())
for client in clients.copy():
try:
client.write_message(self.json())
message = self.json()
sickrage.app.wserver.io_loop.add_callback(client.write_message, message)
except AssertionError:
continue
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