Merge branch 'refs/heads/develop'
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
from couchpotato import app
|
||||
from couchpotato.api import addApiView
|
||||
from couchpotato.core.event import fireEvent, addEvent
|
||||
from couchpotato.core.helpers.request import jsonified
|
||||
@@ -7,7 +6,6 @@ from couchpotato.core.logger import CPLog
|
||||
from couchpotato.core.plugins.base import Plugin
|
||||
from couchpotato.environment import Env
|
||||
from flask import request
|
||||
from flask.helpers import url_for
|
||||
import os
|
||||
import time
|
||||
import traceback
|
||||
@@ -18,17 +16,18 @@ log = CPLog(__name__)
|
||||
|
||||
class Core(Plugin):
|
||||
|
||||
ignore_restart = ['Core.crappyRestart', 'Core.shutdown']
|
||||
ignore_restart = ['Core.crappyRestart', 'Core.crappyShutdown']
|
||||
|
||||
def __init__(self):
|
||||
addApiView('app.shutdown', self.shutdown)
|
||||
addApiView('app.restart', self.restart)
|
||||
addApiView('app.available', self.available)
|
||||
|
||||
addEvent('app.crappy_shutdown', self.shutdown)
|
||||
addEvent('app.crappy_shutdown', self.crappyShutdown)
|
||||
addEvent('app.crappy_restart', self.crappyRestart)
|
||||
addEvent('app.load', self.launchBrowser, priority = 1)
|
||||
addEvent('app.base_url', self.createBaseUrl)
|
||||
addEvent('app.api_url', self.createApiUrl)
|
||||
|
||||
addEvent('setting.save.core.password', self.md5Password)
|
||||
|
||||
@@ -42,11 +41,11 @@ class Core(Plugin):
|
||||
'succes': True
|
||||
})
|
||||
|
||||
def crappyShutdown(self):
|
||||
self.urlopen('%sapp.shutdown' % self.createApiUrl())
|
||||
|
||||
def crappyRestart(self):
|
||||
ctx = app.test_request_context()
|
||||
ctx.push()
|
||||
self.urlopen('%s%sapp.restart' % (fireEvent('app.base_url', single = True), url_for('api.index')))
|
||||
ctx.pop()
|
||||
self.urlopen('%sapp.restart' % self.createApiUrl())
|
||||
|
||||
def shutdown(self):
|
||||
self.initShutdown()
|
||||
@@ -57,6 +56,7 @@ class Core(Plugin):
|
||||
return 'restarting'
|
||||
|
||||
def initShutdown(self, restart = False):
|
||||
log.info('Shutting down' if not restart else 'Restarting')
|
||||
|
||||
fireEvent('app.shutdown')
|
||||
|
||||
@@ -77,18 +77,14 @@ class Core(Plugin):
|
||||
if restart:
|
||||
self.createFile(self.restartFilePath(), 'This is the most suckiest way to register if CP is restarted. Ever...')
|
||||
|
||||
log.debug('Save to shutdown/restart')
|
||||
|
||||
try:
|
||||
request.environ.get('werkzeug.server.shutdown')()
|
||||
except:
|
||||
try:
|
||||
ctx = app.test_request_context()
|
||||
ctx.push()
|
||||
request.environ.get('werkzeug.server.shutdown')()
|
||||
ctx.pop()
|
||||
except TypeError:
|
||||
pass
|
||||
except:
|
||||
log.error('Failed shutting down the server: %s' % traceback.format_exc())
|
||||
log.error('Failed shutting down the server: %s' % traceback.format_exc())
|
||||
|
||||
fireEvent('app.after_shutdown', restart = restart)
|
||||
|
||||
def removeRestartFile(self):
|
||||
try:
|
||||
@@ -120,3 +116,7 @@ class Core(Plugin):
|
||||
port = Env.setting('port')
|
||||
|
||||
return '%s:%d' % (cleanHost(host).rstrip('/'), int(port))
|
||||
|
||||
def createApiUrl(self):
|
||||
|
||||
return '%s/%s/' % (self.createBaseUrl(), Env.setting('api_key'))
|
||||
|
||||
@@ -2,24 +2,34 @@ from couchpotato.core.event import fireEvent, addEvent
|
||||
from couchpotato.core.logger import CPLog
|
||||
from couchpotato.core.plugins.base import Plugin
|
||||
from couchpotato.environment import Env
|
||||
from urllib import quote
|
||||
|
||||
log = CPLog(__name__)
|
||||
|
||||
if Env.get('desktop'):
|
||||
|
||||
class Desktop(Plugin):
|
||||
class Desktop(Plugin):
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self):
|
||||
|
||||
if not Env.get('binary_port'):
|
||||
return
|
||||
desktop = Env.get('desktop')
|
||||
desktop.setSettings({
|
||||
'base_url': fireEvent('app.base_url', single = True),
|
||||
'api_url': fireEvent('app.api_url', single = True),
|
||||
'api': Env.setting('api'),
|
||||
})
|
||||
|
||||
addEvent('app.load', self.settingsToDesktop, priority = 2)
|
||||
# Events from desktop
|
||||
desktop.addEvents({
|
||||
'onClose': self.onClose,
|
||||
})
|
||||
|
||||
def settingsToDesktop(self):
|
||||
# Events to desktop
|
||||
addEvent('app.after_shutdown', desktop.afterShutdown)
|
||||
|
||||
base_url = fireEvent('app.base_url', single = True)
|
||||
base_url_api = '%s/%s' % (base_url, Env.setting('api_key'))
|
||||
def onClose(self, event):
|
||||
return fireEvent('app.crappy_shutdown', single = True)
|
||||
|
||||
url_data = '{"host": "%s", "api": "%s"}' % (base_url, base_url_api)
|
||||
self.urlopen('http://localhost:%s/%s' % (Env.get('binary_port'), quote(url_data)))
|
||||
else:
|
||||
|
||||
class Desktop(Plugin):
|
||||
pass
|
||||
|
||||
@@ -93,6 +93,12 @@ class Plugin(object):
|
||||
|
||||
socket.setdefaulttimeout(timeout)
|
||||
|
||||
# Fill in some headers
|
||||
if not headers.get('Referer'):
|
||||
headers['Referer'] = urlparse(url).hostname
|
||||
if not headers.get('User-Agent'):
|
||||
headers['User-Agent'] = ''
|
||||
|
||||
host = urlparse(url).hostname
|
||||
self.wait(host)
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from couchpotato.api import addApiView
|
||||
from couchpotato.core.helpers.request import jsonified, getParam
|
||||
from couchpotato.core.helpers.request import jsonified, getParam, getParams
|
||||
from couchpotato.core.logger import CPLog
|
||||
from couchpotato.core.plugins.base import Plugin
|
||||
from couchpotato.environment import Env
|
||||
@@ -14,6 +14,7 @@ class Logging(Plugin):
|
||||
def __init__(self):
|
||||
addApiView('logging.get', self.get)
|
||||
addApiView('logging.clear', self.clear)
|
||||
addApiView('logging.log', self.log)
|
||||
|
||||
def get(self):
|
||||
|
||||
@@ -67,3 +68,21 @@ class Logging(Plugin):
|
||||
return jsonified({
|
||||
'success': True
|
||||
})
|
||||
|
||||
def log(self):
|
||||
|
||||
params = getParams()
|
||||
|
||||
try:
|
||||
log_message = 'API log: %s' % params
|
||||
try:
|
||||
getattr(log, params.get('type', 'error'))(log_message)
|
||||
except:
|
||||
log.error(log_message)
|
||||
except:
|
||||
log.error('Couldn\'t log via API: %s' % params)
|
||||
|
||||
|
||||
return jsonified({
|
||||
'success': True
|
||||
})
|
||||
|
||||
@@ -23,7 +23,7 @@ class X264(NZBProvider):
|
||||
if self.isDisabled() or not self.isAvailable(self.urls['search']) or not quality.get('hd', False):
|
||||
return results
|
||||
|
||||
q = '%s %s' % (movie['library']['titles'][0]['title'], quality.get('identifier'))
|
||||
q = '%s %s %s' % (movie['library']['titles'][0]['title'], movie['library']['year'], quality.get('identifier'))
|
||||
url = self.urls['search'] % quote_plus(q)
|
||||
|
||||
cache_key = 'x264.%s' % q
|
||||
|
||||
@@ -14,7 +14,7 @@ class Env(object):
|
||||
_args = None
|
||||
_quiet = False
|
||||
_deamonize = False
|
||||
_version = 0.5
|
||||
_desktop = None
|
||||
|
||||
''' Data paths and directories '''
|
||||
_app_dir = ""
|
||||
|
||||
@@ -26,8 +26,6 @@ def getOptions(base_path, args):
|
||||
dest = 'console_log', help = "Log to console")
|
||||
parser.add_argument('--quiet', action = 'store_true',
|
||||
dest = 'quiet', help = 'No console logging')
|
||||
parser.add_argument('--binary_port', default = None,
|
||||
dest = 'binary_port', help = 'Running from binary build')
|
||||
parser.add_argument('--nogit', action = 'store_true',
|
||||
dest = 'nogit', help = 'No git available')
|
||||
|
||||
@@ -38,16 +36,13 @@ def getOptions(base_path, args):
|
||||
return options
|
||||
|
||||
|
||||
def runCouchPotato(options, base_path, args, handle = None):
|
||||
def runCouchPotato(options, base_path, args, desktop = None):
|
||||
|
||||
# Load settings
|
||||
from couchpotato.environment import Env
|
||||
settings = Env.get('settings')
|
||||
settings.setFile(options.config_file)
|
||||
|
||||
if handle:
|
||||
handle(Env)
|
||||
|
||||
# Create data dir if needed
|
||||
data_dir = os.path.expanduser(Env.setting('data_dir'))
|
||||
if data_dir == '':
|
||||
@@ -72,7 +67,7 @@ def runCouchPotato(options, base_path, args, handle = None):
|
||||
Env.set('cache', FileSystemCache(os.path.join(Env.get('cache_dir'), 'python')))
|
||||
Env.set('console_log', options.console_log)
|
||||
Env.set('quiet', options.quiet)
|
||||
Env.set('binary_port', options.binary_port)
|
||||
Env.set('desktop', desktop)
|
||||
Env.set('args', args)
|
||||
Env.set('options', options)
|
||||
|
||||
@@ -86,7 +81,7 @@ def runCouchPotato(options, base_path, args, handle = None):
|
||||
|
||||
# Only run once when debugging
|
||||
fire_load = False
|
||||
if os.environ.get('WERKZEUG_RUN_MAIN') or not debug or options.binary_port:
|
||||
if os.environ.get('WERKZEUG_RUN_MAIN') or not debug or Env.get('desktop'):
|
||||
|
||||
# Logger
|
||||
logger = logging.getLogger()
|
||||
@@ -151,7 +146,7 @@ def runCouchPotato(options, base_path, args, handle = None):
|
||||
from couchpotato import app
|
||||
api_key = Env.setting('api_key')
|
||||
url_base = '/' + Env.setting('url_base').lstrip('/') if Env.setting('url_base') else ''
|
||||
reloader = debug is True and not options.binary_port
|
||||
reloader = debug is True and not Env.get('desktop')
|
||||
|
||||
# Basic config
|
||||
app.secret_key = api_key
|
||||
|
||||
@@ -52,6 +52,22 @@
|
||||
'is_remote': false
|
||||
});
|
||||
|
||||
// Catch errors
|
||||
window.onerror = function(message, file, line){
|
||||
|
||||
Api.request('logging.log', {
|
||||
'data': {
|
||||
'type': 'error',
|
||||
'message': Browser.name + ' ' + Browser.version + ': \n' + message,
|
||||
'page': window.location.href,
|
||||
'file': file,
|
||||
'line': line
|
||||
}
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Quality.setup({
|
||||
'profiles': {{ fireEvent('profile.all', single = True)|tojson|safe }},
|
||||
'qualities': {{ fireEvent('quality.all', single = True)|tojson|safe }}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
import ntpath
|
||||
import os.path
|
||||
|
||||
|
||||
@@ -45,7 +44,7 @@ def split_path(path):
|
||||
"""
|
||||
result = []
|
||||
while True:
|
||||
head, tail = ntpath.split(path)
|
||||
head, tail = os.path.split(path)
|
||||
|
||||
# on Unix systems, the root folder is '/'
|
||||
if head == '/' and tail == '':
|
||||
|
||||
Reference in New Issue
Block a user