This commit is contained in:
Janez Troha committed 2012-07-01 01:57:47 +02:00
commit 615a781be4
18 files changed
+219 -139

No files matched your search

+11 -1
View File
@@ -18,7 +18,10 @@ log = CPLog(__name__)
class Core(Plugin):
ignore_restart = ['Core.restart', 'Core.shutdown', 'Updater.check']
ignore_restart = [
'Core.restart', 'Core.shutdown',
'Updater.check', 'Updater.autoUpdate',
]
shutdown_started = False
def __init__(self):
@@ -43,6 +46,7 @@ class Core(Plugin):
addEvent('app.base_url', self.createBaseUrl)
addEvent('app.api_url', self.createApiUrl)
addEvent('app.version', self.version)
addEvent('app.load', self.checkDataDir)
addEvent('setting.save.core.password', self.md5Password)
addEvent('setting.save.core.api_key', self.checkApikey)
@@ -54,6 +58,12 @@ class Core(Plugin):
def checkApikey(self, value):
return value if value and len(value) > 3 else uuid4().hex
def checkDataDir(self):
if Env.get('app_dir') in Env.get('data_dir'):
log.error('You should NOT use your CouchPotato directory to save your settings in. Files will get overwritten or be deleted.')
return True
def available(self):
return jsonified({
'succes': True
+15 -2
View File
@@ -20,6 +20,8 @@ log = CPLog(__name__)
class Updater(Plugin):
available_notified = False
def __init__(self):
if Env.get('desktop'):
@@ -64,13 +66,18 @@ class Updater(Plugin):
fireEventAsync('app.restart')
return True
return False
def check(self):
if self.isDisabled():
return
if self.updater.check():
if self.conf('notification') and not self.conf('automatic'):
if not self.available_notified and self.conf('notification') and not self.conf('automatic'):
fireEvent('updater.available', message = 'A new update is available', data = self.updater.info())
self.available_notified = True
return True
return False
@@ -168,7 +175,6 @@ class GitUpdater(BaseUpdater):
self.repo.saveStash()
log.info('Updating to latest version')
info = self.info()
self.repo.pull()
# Delete leftover .pyc files
@@ -302,6 +308,13 @@ class SourceUpdater(BaseUpdater):
except Exception, e:
log.error('Failed overwriting file: %s', e)
if Env.get('app_dir') not in Env.get('data_dir'):
for still_exists in existing_files:
try:
os.remove(still_exists)
except:
log.error('Failed removing non-used file: %s', traceback.format_exc())
def removeDir(self, path):
try:
@@ -22,8 +22,10 @@ var UpdaterBase = new Class({
if(json.update_available)
self.doUpdate();
else
App.unBlockPage()
else {
App.unBlockPage();
App.fireEvent('message', 'No updates available');
}
}
})
+5 -4
View File
@@ -136,23 +136,24 @@ class CoreNotifier(Notification):
#db.close()
return True
def frontend(self, type = 'notification', data = {}):
def frontend(self, type = 'notification', data = {}, message = None):
self.m_lock.acquire()
message = {
notification = {
'message_id': str(uuid.uuid4()),
'time': time.time(),
'type': type,
'data': data,
'message': message,
}
self.messages.append(message)
self.messages.append(notification)
while len(self.listeners) > 0 and not self.shuttingDown():
try:
listener, last_id = self.listeners.pop()
listener({
'success': True,
'result': [message],
'result': [notification],
})
except:
break
@@ -11,6 +11,7 @@ var NotificationBase = new Class({
App.addEvent('unload', self.stopPoll.bind(self));
App.addEvent('reload', self.startInterval.bind(self, [true]));
App.addEvent('notification', self.notify.bind(self));
App.addEvent('message', self.showMessage.bind(self));
// Add test buttons to settings page
App.addEvent('load', self.addTestButtons.bind(self));
@@ -86,7 +87,7 @@ var NotificationBase = new Class({
startInterval: function(force){
var self = this;
if(self.stopped && !force){
self.stopped = false;
return;
@@ -126,11 +127,12 @@ var NotificationBase = new Class({
processData: function(json){
var self = this;
// Process data
if(json){
Array.each(json.result, function(result){
App.fireEvent(result.type, result)
App.fireEvent(result.type, result);
if(result.message && result.read === undefined)
self.showMessage(result.message);
})
if(json.result.length > 0)
@@ -141,6 +143,30 @@ var NotificationBase = new Class({
self.startPoll()
},
showMessage: function(message){
var self = this;
if(!self.message_container)
self.message_container = new Element('div.messages').inject(document.body);
var new_message = new Element('div.message', {
'text': message
}).inject(self.message_container);
setTimeout(function(){
new_message.addClass('show')
}, 10);
setTimeout(function(){
new_message.addClass('hide')
setTimeout(function(){
new_message.destroy();
}, 1000);
}, 4000);
},
// Notification setting tests
addTestButtons: function(){
var self = this;
+7 -4
View File
@@ -46,10 +46,13 @@ class Plex(Notification):
def notify(self, message = '', data = {}, listener = None):
if self.isDisabled(): return
for host in [x.strip() + ':3000' for x in self.conf('host').split(",")]:
self.send({'command': 'ExecBuiltIn', 'parameter': 'Notification(CouchPotato, %s)' % message}, host)
hosts = [x.strip() + ':3000' for x in self.conf('host').split(",")]
successful = 0
for host in hosts:
if self.send({'command': 'ExecBuiltIn', 'parameter': 'Notification(CouchPotato, %s)' % message}, host):
successful += 1
return True
return successful == len(hosts)
def send(self, command, host):
@@ -60,7 +63,7 @@ class Plex(Notification):
try:
self.urlopen(url, headers = headers, show_error = False)
except:
log.error("Couldn't sent command to Plex")
log.error("Couldn't sent command to Plex: %s", traceback.format_exc())
return False
log.info('Plex notification to %s successful.', host)
+10 -9
View File
@@ -78,15 +78,16 @@ Page.Log = new Class({
addColors: function(text){
var self = this;
var text = new Element('div', {
'html': text
}).get('text')
text = text.replace(/\u001b\[31m/gi, '</span><span class="error">')
text = text.replace(/\u001b\[36m/gi, '</span><span class="debug">')
text = text.replace(/\u001b\[33m/gi, '</span><span class="debug">')
text = text.replace(/\u001b\[0m\n/gi, '</span><span class="time">')
text = text.replace(/\u001b\[0m/gi, '</span><span>')
text = text
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/\u001b\[31m/gi, '</span><span class="error">')
.replace(/\u001b\[36m/gi, '</span><span class="debug">')
.replace(/\u001b\[33m/gi, '</span><span class="debug">')
.replace(/\u001b\[0m\n/gi, '</span><span class="time">')
.replace(/\u001b\[0m/gi, '</span><span>')
return '<span class="time">' + text + '</span>';
}
+2 -2
View File
@@ -240,7 +240,6 @@ class MoviePlugin(Plugin):
db = get_session()
for id in getParam('id').split(','):
fireEvent('notify.frontend', type = 'movie.busy.%s' % id, data = True)
movie = db.query(Movie).filter_by(id = id).first()
if movie:
@@ -250,6 +249,7 @@ class MoviePlugin(Plugin):
for title in movie.library.titles:
if title.default: default_title = title.title
fireEvent('notify.frontend', type = 'movie.busy.%s' % id, data = True, message = 'Updating "%s"' % default_title)
fireEventAsync('library.update', identifier = movie.library.identifier, default_title = default_title, force = True, on_complete = self.createOnComplete(id))
@@ -342,7 +342,7 @@ class MoviePlugin(Plugin):
onComplete()
if added:
fireEvent('notify.frontend', type = 'movie.added', data = movie_dict)
fireEvent('notify.frontend', type = 'movie.added', data = movie_dict, message = 'Successfully added "%s" to your wanted list.' % params.get('title', ''))
#db.close()
return movie_dict
@@ -17,10 +17,13 @@ var Movie = new Class({
self.parent(self, options);
App.addEvent('movie.update.'+data.id, self.update.bind(self));
App.addEvent('movie.busy.'+data.id, function(notification){
if(notification.data)
self.busy(true)
});
['movie.busy', 'searcher.started'].each(function(listener){
App.addEvent(listener+'.'+data.id, function(notification){
if(notification.data)
self.busy(true)
});
})
},
busy: function(set_busy){
+1 -1
View File
@@ -84,7 +84,7 @@ class Searcher(Plugin):
if not default_title:
return
fireEvent('notify.frontend', type = 'searcher.started.%s' % movie['id'], data = True)
fireEvent('notify.frontend', type = 'searcher.started.%s' % movie['id'], data = True, message = 'Searching for "%s"' % default_title)
ret = False
for quality_type in movie['profile']['types']:
@@ -89,7 +89,7 @@ class IMDBAPI(MovieProvider):
'poster': [movie.get('Poster', '')] if movie.get('Poster') and len(movie.get('Poster', '')) > 4 else [],
},
'rating': {
'imdb': (tryFloat(movie.get('imdbRating', 0)), tryInt(movie.get('imdbVotes', ''))),
'imdb': (tryFloat(movie.get('imdbRating', 0)), tryInt(movie.get('imdbVotes', '').replace(',', ''))),
#'rotten': (tryFloat(movie.get('tomatoRating', 0)), tryInt(movie.get('tomatoReviews', 0))),
},
'imdb': str(movie.get('imdbID', '')),