|
|
@ -19,17 +19,13 @@ |
|
|
|
import datetime |
|
|
|
import sickbeard |
|
|
|
|
|
|
|
from tornado.web import RequestHandler |
|
|
|
|
|
|
|
MESSAGE = 'notice' |
|
|
|
ERROR = 'error' |
|
|
|
|
|
|
|
|
|
|
|
class Notifications(object): |
|
|
|
""" |
|
|
|
A queue of Notification objects. |
|
|
|
""" |
|
|
|
|
|
|
|
def __init__(self): |
|
|
|
self._messages = [] |
|
|
|
self._errors = [] |
|
|
@ -37,9 +33,9 @@ class Notifications(object): |
|
|
|
def message(self, title, message=''): |
|
|
|
""" |
|
|
|
Add a regular notification to the queue |
|
|
|
|
|
|
|
|
|
|
|
title: The title of the notification |
|
|
|
message: The message portion of the notification |
|
|
|
message: The message portion of the notification |
|
|
|
""" |
|
|
|
self._messages.append(Notification(title, message, MESSAGE)) |
|
|
|
|
|
|
@ -48,24 +44,24 @@ class Notifications(object): |
|
|
|
Add an error notification to the queue |
|
|
|
|
|
|
|
title: The title of the notification |
|
|
|
message: The message portion of the notification |
|
|
|
message: The message portion of the notification |
|
|
|
""" |
|
|
|
self._errors.append(Notification(title, message, ERROR)) |
|
|
|
|
|
|
|
def get_notifications(self): |
|
|
|
def get_notifications(self, remote_ip='127.0.0.1'): |
|
|
|
""" |
|
|
|
Return all the available notifications in a list. Marks them all as seen |
|
|
|
as it returns them. Also removes timed out Notifications from the queue. |
|
|
|
|
|
|
|
|
|
|
|
Returns: A list of Notification objects |
|
|
|
""" |
|
|
|
|
|
|
|
# filter out expired notifications |
|
|
|
# filter out expired notifications |
|
|
|
self._errors = [x for x in self._errors if not x.is_expired()] |
|
|
|
self._messages = [x for x in self._messages if not x.is_expired()] |
|
|
|
|
|
|
|
# return any notifications that haven't been shown to the client already |
|
|
|
return [x.see() for x in self._errors + self._messages if x.is_new()] |
|
|
|
return [x.see(remote_ip) for x in self._errors + self._messages if x.is_new(remote_ip)] |
|
|
|
|
|
|
|
# static notification queue object |
|
|
|
notifications = Notifications() |
|
|
@ -76,7 +72,6 @@ class Notification(object): |
|
|
|
Represents a single notification. Tracks its own timeout and a list of which clients have |
|
|
|
seen it before. |
|
|
|
""" |
|
|
|
|
|
|
|
def __init__(self, title, message='', type=None, timeout=None): |
|
|
|
self.title = title |
|
|
|
self.message = message |
|
|
@ -94,11 +89,11 @@ class Notification(object): |
|
|
|
else: |
|
|
|
self._timeout = datetime.timedelta(minutes=1) |
|
|
|
|
|
|
|
def is_new(self): |
|
|
|
def is_new(self, remote_ip='127.0.0.1'): |
|
|
|
""" |
|
|
|
Returns True if the notification hasn't been displayed to the current client (aka IP address). |
|
|
|
""" |
|
|
|
return sickbeard.REMOTE_IP not in self._seen |
|
|
|
return remote_ip not in self._seen |
|
|
|
|
|
|
|
def is_expired(self): |
|
|
|
""" |
|
|
@ -107,25 +102,24 @@ class Notification(object): |
|
|
|
return datetime.datetime.now() - self._when > self._timeout |
|
|
|
|
|
|
|
|
|
|
|
def see(self): |
|
|
|
def see(self, remote_ip='127.0.0.1'): |
|
|
|
""" |
|
|
|
Returns this notification object and marks it as seen by the client ip |
|
|
|
""" |
|
|
|
self._seen.append(sickbeard.REMOTE_IP) |
|
|
|
self._seen.append(remote_ip) |
|
|
|
return self |
|
|
|
|
|
|
|
|
|
|
|
class ProgressIndicator(): |
|
|
|
|
|
|
|
def __init__(self, percentComplete=0, currentStatus={'title': ''}): |
|
|
|
self.percentComplete = percentComplete |
|
|
|
self.currentStatus = currentStatus |
|
|
|
|
|
|
|
|
|
|
|
class ProgressIndicators(): |
|
|
|
_pi = {'massUpdate': [], |
|
|
|
'massAdd': [], |
|
|
|
'dailyUpdate': [] |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@staticmethod |
|
|
|
def getIndicator(name): |
|
|
@ -144,12 +138,10 @@ class ProgressIndicators(): |
|
|
|
def setIndicator(name, indicator): |
|
|
|
ProgressIndicators._pi[name].append(indicator) |
|
|
|
|
|
|
|
|
|
|
|
class QueueProgressIndicator(): |
|
|
|
""" |
|
|
|
A class used by the UI to show the progress of the queue or a part of it. |
|
|
|
""" |
|
|
|
|
|
|
|
def __init__(self, name, queueItemList): |
|
|
|
self.queueItemList = queueItemList |
|
|
|
self.name = name |
|
|
@ -164,8 +156,7 @@ class QueueProgressIndicator(): |
|
|
|
return len([x for x in self.queueItemList if x.isInQueue()]) |
|
|
|
|
|
|
|
def nextName(self): |
|
|
|
for curItem in [ |
|
|
|
sickbeard.showQueueScheduler.action.currentItem] + sickbeard.showQueueScheduler.action.queue: #@UndefinedVariable |
|
|
|
for curItem in [sickbeard.showQueueScheduler.action.currentItem]+sickbeard.showQueueScheduler.action.queue: #@UndefinedVariable |
|
|
|
if curItem in self.queueItemList: |
|
|
|
return curItem.name |
|
|
|
|
|
|
@ -178,12 +169,9 @@ class QueueProgressIndicator(): |
|
|
|
if numTotal == 0: |
|
|
|
return 0 |
|
|
|
else: |
|
|
|
return int(float(numFinished) / float(numTotal) * 100) |
|
|
|
|
|
|
|
return int(float(numFinished)/float(numTotal)*100) |
|
|
|
|
|
|
|
class LoadingTVShow(): |
|
|
|
def __init__(self, dir): |
|
|
|
self.dir = dir |
|
|
|
self.show = None |
|
|
|
|
|
|
|
|
|
|
|
self.show = None |