|
@ -19,17 +19,13 @@ |
|
|
import datetime |
|
|
import datetime |
|
|
import sickbeard |
|
|
import sickbeard |
|
|
|
|
|
|
|
|
from tornado.web import RequestHandler |
|
|
|
|
|
|
|
|
|
|
|
MESSAGE = 'notice' |
|
|
MESSAGE = 'notice' |
|
|
ERROR = 'error' |
|
|
ERROR = 'error' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Notifications(object): |
|
|
class Notifications(object): |
|
|
""" |
|
|
""" |
|
|
A queue of Notification objects. |
|
|
A queue of Notification objects. |
|
|
""" |
|
|
""" |
|
|
|
|
|
|
|
|
def __init__(self): |
|
|
def __init__(self): |
|
|
self._messages = [] |
|
|
self._messages = [] |
|
|
self._errors = [] |
|
|
self._errors = [] |
|
@ -52,7 +48,7 @@ class Notifications(object): |
|
|
""" |
|
|
""" |
|
|
self._errors.append(Notification(title, message, ERROR)) |
|
|
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 |
|
|
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. |
|
|
as it returns them. Also removes timed out Notifications from the queue. |
|
@ -65,7 +61,7 @@ class Notifications(object): |
|
|
self._messages = [x for x in self._messages 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 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 |
|
|
# static notification queue object |
|
|
notifications = Notifications() |
|
|
notifications = Notifications() |
|
@ -76,7 +72,6 @@ class Notification(object): |
|
|
Represents a single notification. Tracks its own timeout and a list of which clients have |
|
|
Represents a single notification. Tracks its own timeout and a list of which clients have |
|
|
seen it before. |
|
|
seen it before. |
|
|
""" |
|
|
""" |
|
|
|
|
|
|
|
|
def __init__(self, title, message='', type=None, timeout=None): |
|
|
def __init__(self, title, message='', type=None, timeout=None): |
|
|
self.title = title |
|
|
self.title = title |
|
|
self.message = message |
|
|
self.message = message |
|
@ -94,11 +89,11 @@ class Notification(object): |
|
|
else: |
|
|
else: |
|
|
self._timeout = datetime.timedelta(minutes=1) |
|
|
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). |
|
|
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): |
|
|
def is_expired(self): |
|
|
""" |
|
|
""" |
|
@ -107,20 +102,19 @@ class Notification(object): |
|
|
return datetime.datetime.now() - self._when > self._timeout |
|
|
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 |
|
|
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 |
|
|
return self |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ProgressIndicator(): |
|
|
class ProgressIndicator(): |
|
|
|
|
|
|
|
|
def __init__(self, percentComplete=0, currentStatus={'title': ''}): |
|
|
def __init__(self, percentComplete=0, currentStatus={'title': ''}): |
|
|
self.percentComplete = percentComplete |
|
|
self.percentComplete = percentComplete |
|
|
self.currentStatus = currentStatus |
|
|
self.currentStatus = currentStatus |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ProgressIndicators(): |
|
|
class ProgressIndicators(): |
|
|
_pi = {'massUpdate': [], |
|
|
_pi = {'massUpdate': [], |
|
|
'massAdd': [], |
|
|
'massAdd': [], |
|
@ -144,12 +138,10 @@ class ProgressIndicators(): |
|
|
def setIndicator(name, indicator): |
|
|
def setIndicator(name, indicator): |
|
|
ProgressIndicators._pi[name].append(indicator) |
|
|
ProgressIndicators._pi[name].append(indicator) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class QueueProgressIndicator(): |
|
|
class QueueProgressIndicator(): |
|
|
""" |
|
|
""" |
|
|
A class used by the UI to show the progress of the queue or a part of it. |
|
|
A class used by the UI to show the progress of the queue or a part of it. |
|
|
""" |
|
|
""" |
|
|
|
|
|
|
|
|
def __init__(self, name, queueItemList): |
|
|
def __init__(self, name, queueItemList): |
|
|
self.queueItemList = queueItemList |
|
|
self.queueItemList = queueItemList |
|
|
self.name = name |
|
|
self.name = name |
|
@ -164,8 +156,7 @@ class QueueProgressIndicator(): |
|
|
return len([x for x in self.queueItemList if x.isInQueue()]) |
|
|
return len([x for x in self.queueItemList if x.isInQueue()]) |
|
|
|
|
|
|
|
|
def nextName(self): |
|
|
def nextName(self): |
|
|
for curItem in [ |
|
|
for curItem in [sickbeard.showQueueScheduler.action.currentItem]+sickbeard.showQueueScheduler.action.queue: #@UndefinedVariable |
|
|
sickbeard.showQueueScheduler.action.currentItem] + sickbeard.showQueueScheduler.action.queue: #@UndefinedVariable |
|
|
|
|
|
if curItem in self.queueItemList: |
|
|
if curItem in self.queueItemList: |
|
|
return curItem.name |
|
|
return curItem.name |
|
|
|
|
|
|
|
@ -180,10 +171,7 @@ class QueueProgressIndicator(): |
|
|
else: |
|
|
else: |
|
|
return int(float(numFinished)/float(numTotal)*100) |
|
|
return int(float(numFinished)/float(numTotal)*100) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class LoadingTVShow(): |
|
|
class LoadingTVShow(): |
|
|
def __init__(self, dir): |
|
|
def __init__(self, dir): |
|
|
self.dir = dir |
|
|
self.dir = dir |
|
|
self.show = None |
|
|
self.show = None |
|
|
|
|
|
|
|
|
|
|
|
|
|
|