Event priority
Mootools defaults fixes
This commit is contained in:
Ruud
2011-09-12 21:26:38 +02:00
parent c0c0628708
commit 1effeb2134
21 changed files with 695 additions and 349 deletions
+2 -2
View File
@@ -19,7 +19,7 @@ class ProfilePlugin(Plugin):
addApiView('profile.save_order', self.saveOrder)
addApiView('profile.delete', self.delete)
addEvent('app.initialize', self.fill)
addEvent('app.initialize', self.fill, priority = 90)
def all(self):
@@ -127,7 +127,7 @@ class ProfilePlugin(Plugin):
}]
# Create default quality profile
order = 99
order = -2
for profile in profiles:
log.info('Creating default profile: %s' % profile.get('label'))
p = Profile(
+1 -1
View File
@@ -32,7 +32,7 @@ class QualityPlugin(Plugin):
addEvent('quality.single', self.single)
addEvent('quality.guess', self.guess)
addEvent('app.initialize', self.fill)
addEvent('app.initialize', self.fill, priority = 10)
def all(self):
+1 -1
View File
@@ -86,7 +86,7 @@ class Searcher(Plugin):
for info in nzb:
try:
if not isinstance(nzb[info], (str, unicode)):
if not isinstance(nzb[info], (str, unicode, int, long)):
continue
rls_info = ReleaseInfo(
+28 -11
View File
@@ -1,4 +1,6 @@
from couchpotato.api import addApiView
from couchpotato.core.event import addEvent, fireEvent
from couchpotato.core.helpers.request import jsonified
from couchpotato.core.logger import CPLog
from couchpotato.core.plugins.base import Plugin
from couchpotato.environment import Env
@@ -10,14 +12,13 @@ log = CPLog(__name__)
class Updater(Plugin):
git = 'git://github.com/CouchPotato/CouchPotato.git'
repo_name = 'RuudBurger/CouchPotatoServer'
running = False
version = None
updateFailed = False
updateAvailable = False
updateVersion = None
lastCheck = 0
update_failed = False
update_version = None
last_check = 0
def __init__(self):
@@ -27,6 +28,18 @@ class Updater(Plugin):
addEvent('app.load', self.check)
addApiView('updater.info', self.getInfo)
addApiView('updater.update', self.doUpdateView)
def getInfo(self):
return jsonified({
'repo_name': self.repo_name,
'last_check': self.last_check,
'update_version': self.update_version,
'version': self.getVersion(),
})
def getVersion(self):
if not self.version:
@@ -42,7 +55,7 @@ class Updater(Plugin):
def check(self):
if self.updateAvailable or self.isDisabled():
if self.update_version or self.isDisabled():
return
current_branch = self.repo.getCurrentBranch().name
@@ -54,13 +67,17 @@ class Updater(Plugin):
remote = branch.getHead()
if local.getDate() < remote.getDate():
if self.conf('automatic') and not self.updateFailed:
if self.conf('automatic') and not self.update_failed:
self.doUpdate()
else:
self.updateAvailable = True
self.updateVersion = remote.hash
self.update_version = remote.hash
self.lastCheck = time.time()
self.last_check = time.time()
def doUpdateView(self):
return jsonified({
'success': self.doUpdate()
})
def doUpdate(self):
try:
@@ -70,7 +87,7 @@ class Updater(Plugin):
except Exception, e:
log.error('Failed updating via GIT: %s' % e)
self.updateFailed = True
self.update_failed = True
return False
@@ -0,0 +1,89 @@
var UpdaterBase = new Class({
initialize: function(){
var self = this;
App.addEvent('load', self.info.bind(self, 1000))
},
info: function(timeout){
var self = this;
if(self.timer) clearTimeout(self.timer);
self.timer = setTimeout(function(){
Api.request('updater.info', {
'onComplete': function(json){
if(json.update_version){
self.createMessage(json);
}
else {
if(self.message)
self.message.destroy();
}
}
})
}, (timeout || 0))
},
createMessage: function(data){
var self = this;
self.message = new Element('div.message.update').adopt(
new Element('span', {
'text': 'A new version is available'
}),
new Element('a', {
'href': 'https://github.com/'+data.repo_name+'/compare/'+data.version.substr(0, 7)+'...'+data.update_version.substr(0, 7),
'text': 'see what has changed',
'target': '_blank'
}),
new Element('span[text=or]'),
new Element('a', {
'text': 'just update, gogogo!',
'events': {
'click': self.doUpdate.bind(self)
}
})
).inject($(document.body).getElement('.header'))
},
doUpdate: function(){
var self = this;
Api.request('updater.update', {
'onComplete': function(json){
if(json.success){
App.restart();
$(document.body).set('spin', {
'message': 'Updating'
});
$(document.body).spin();
var checks = 0;
var interval = 0;
interval = setInterval(function(){
Api.request('', {
'onSuccess': function(){
if(checks > 2){
clearInterval(interval);
$(document.body).unspin();
self.info();
}
}
});
checks++;
}, 500)
}
}
});
}
});
var Updater = new UpdaterBase();