Browse Source

Revert "Merge branch 'refs/heads/develop'"

This reverts commit de4e47b4a4, reversing
changes made to 82a43f7bee.
pull/69/head
Ruud 14 years ago
parent
commit
d2996a6340
  1. 32
      couchpotato/core/_base/_core/main.py
  2. 30
      couchpotato/core/_base/desktop/main.py
  3. 2
      couchpotato/environment.py
  4. 13
      couchpotato/runner.py
  5. 3
      libs/guessit/fileutils.py

32
couchpotato/core/_base/_core/main.py

@ -1,3 +1,4 @@
from couchpotato import app
from couchpotato.api import addApiView from couchpotato.api import addApiView
from couchpotato.core.event import fireEvent, addEvent from couchpotato.core.event import fireEvent, addEvent
from couchpotato.core.helpers.request import jsonified from couchpotato.core.helpers.request import jsonified
@ -6,6 +7,7 @@ from couchpotato.core.logger import CPLog
from couchpotato.core.plugins.base import Plugin from couchpotato.core.plugins.base import Plugin
from couchpotato.environment import Env from couchpotato.environment import Env
from flask import request from flask import request
from flask.helpers import url_for
import os import os
import time import time
import traceback import traceback
@ -16,18 +18,17 @@ log = CPLog(__name__)
class Core(Plugin): class Core(Plugin):
ignore_restart = ['Core.crappyRestart', 'Core.crappyShutdown'] ignore_restart = ['Core.crappyRestart', 'Core.shutdown']
def __init__(self): def __init__(self):
addApiView('app.shutdown', self.shutdown) addApiView('app.shutdown', self.shutdown)
addApiView('app.restart', self.restart) addApiView('app.restart', self.restart)
addApiView('app.available', self.available) addApiView('app.available', self.available)
addEvent('app.crappy_shutdown', self.crappyShutdown) addEvent('app.crappy_shutdown', self.shutdown)
addEvent('app.crappy_restart', self.crappyRestart) addEvent('app.crappy_restart', self.crappyRestart)
addEvent('app.load', self.launchBrowser, priority = 1) addEvent('app.load', self.launchBrowser, priority = 1)
addEvent('app.base_url', self.createBaseUrl) addEvent('app.base_url', self.createBaseUrl)
addEvent('app.api_url', self.createApiUrl)
addEvent('setting.save.core.password', self.md5Password) addEvent('setting.save.core.password', self.md5Password)
@ -41,11 +42,11 @@ class Core(Plugin):
'succes': True 'succes': True
}) })
def crappyShutdown(self):
self.urlopen('%sapp.shutdown' % self.createApiUrl())
def crappyRestart(self): def crappyRestart(self):
self.urlopen('%sapp.restart' % self.createApiUrl()) ctx = app.test_request_context()
ctx.push()
self.urlopen('%s%sapp.restart' % (fireEvent('app.base_url', single = True), url_for('api.index')))
ctx.pop()
def shutdown(self): def shutdown(self):
self.initShutdown() self.initShutdown()
@ -56,7 +57,6 @@ class Core(Plugin):
return 'restarting' return 'restarting'
def initShutdown(self, restart = False): def initShutdown(self, restart = False):
log.info('Shutting down' if not restart else 'Restarting')
fireEvent('app.shutdown') fireEvent('app.shutdown')
@ -77,15 +77,19 @@ class Core(Plugin):
if restart: if restart:
self.createFile(self.restartFilePath(), 'This is the most suckiest way to register if CP is restarted. Ever...') self.createFile(self.restartFilePath(), 'This is the most suckiest way to register if CP is restarted. Ever...')
log.debug('Save to shutdown/restart')
try: try:
request.environ.get('werkzeug.server.shutdown')() request.environ.get('werkzeug.server.shutdown')()
except: 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): def removeRestartFile(self):
try: try:
os.remove(self.restartFilePath()) os.remove(self.restartFilePath())
@ -116,7 +120,3 @@ class Core(Plugin):
port = Env.setting('port') port = Env.setting('port')
return '%s:%d' % (cleanHost(host).rstrip('/'), int(port)) return '%s:%d' % (cleanHost(host).rstrip('/'), int(port))
def createApiUrl(self):
return '%s/%s/' % (self.createBaseUrl(), Env.setting('api_key'))

30
couchpotato/core/_base/desktop/main.py

@ -2,34 +2,24 @@ from couchpotato.core.event import fireEvent, addEvent
from couchpotato.core.logger import CPLog from couchpotato.core.logger import CPLog
from couchpotato.core.plugins.base import Plugin from couchpotato.core.plugins.base import Plugin
from couchpotato.environment import Env from couchpotato.environment import Env
from urllib import quote
log = CPLog(__name__) log = CPLog(__name__)
if Env.get('desktop'):
class Desktop(Plugin): class Desktop(Plugin):
def __init__(self): def __init__(self):
desktop = Env.get('desktop') if not Env.get('binary_port'):
desktop.setSettings({ return
'base_url': fireEvent('app.base_url', single = True),
'api_url': fireEvent('app.api_url', single = True),
'api': Env.setting('api'),
})
# Events from desktop addEvent('app.load', self.settingsToDesktop, priority = 2)
desktop.addEvents({
'onClose': self.onClose,
})
# Events to desktop def settingsToDesktop(self):
addEvent('app.after_shutdown', desktop.afterShutdown)
def onClose(self, event): base_url = fireEvent('app.base_url', single = True)
return fireEvent('app.crappy_shutdown', single = True) base_url_api = '%s/%s' % (base_url, Env.setting('api_key'))
else: url_data = '{"host": "%s", "api": "%s"}' % (base_url, base_url_api)
self.urlopen('http://localhost:%s/%s' % (Env.get('binary_port'), quote(url_data)))
class Desktop(Plugin):
pass

2
couchpotato/environment.py

@ -14,7 +14,7 @@ class Env(object):
_args = None _args = None
_quiet = False _quiet = False
_deamonize = False _deamonize = False
_desktop = None _version = 0.5
''' Data paths and directories ''' ''' Data paths and directories '''
_app_dir = "" _app_dir = ""

13
couchpotato/runner.py

@ -26,6 +26,8 @@ def getOptions(base_path, args):
dest = 'console_log', help = "Log to console") dest = 'console_log', help = "Log to console")
parser.add_argument('--quiet', action = 'store_true', parser.add_argument('--quiet', action = 'store_true',
dest = 'quiet', help = 'No console logging') 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', parser.add_argument('--nogit', action = 'store_true',
dest = 'nogit', help = 'No git available') dest = 'nogit', help = 'No git available')
@ -36,13 +38,16 @@ def getOptions(base_path, args):
return options return options
def runCouchPotato(options, base_path, args, desktop = None): def runCouchPotato(options, base_path, args, handle = None):
# Load settings # Load settings
from couchpotato.environment import Env from couchpotato.environment import Env
settings = Env.get('settings') settings = Env.get('settings')
settings.setFile(options.config_file) settings.setFile(options.config_file)
if handle:
handle(Env)
# Create data dir if needed # Create data dir if needed
data_dir = os.path.expanduser(Env.setting('data_dir')) data_dir = os.path.expanduser(Env.setting('data_dir'))
if data_dir == '': if data_dir == '':
@ -67,7 +72,7 @@ def runCouchPotato(options, base_path, args, desktop = None):
Env.set('cache', FileSystemCache(os.path.join(Env.get('cache_dir'), 'python'))) Env.set('cache', FileSystemCache(os.path.join(Env.get('cache_dir'), 'python')))
Env.set('console_log', options.console_log) Env.set('console_log', options.console_log)
Env.set('quiet', options.quiet) Env.set('quiet', options.quiet)
Env.set('desktop', desktop) Env.set('binary_port', options.binary_port)
Env.set('args', args) Env.set('args', args)
Env.set('options', options) Env.set('options', options)
@ -81,7 +86,7 @@ def runCouchPotato(options, base_path, args, desktop = None):
# Only run once when debugging # Only run once when debugging
fire_load = False fire_load = False
if os.environ.get('WERKZEUG_RUN_MAIN') or not debug or Env.get('desktop'): if os.environ.get('WERKZEUG_RUN_MAIN') or not debug or options.binary_port:
# Logger # Logger
logger = logging.getLogger() logger = logging.getLogger()
@ -146,7 +151,7 @@ def runCouchPotato(options, base_path, args, desktop = None):
from couchpotato import app from couchpotato import app
api_key = Env.setting('api_key') api_key = Env.setting('api_key')
url_base = '/' + Env.setting('url_base').lstrip('/') if Env.setting('url_base') else '' url_base = '/' + Env.setting('url_base').lstrip('/') if Env.setting('url_base') else ''
reloader = debug is True and not Env.get('desktop') reloader = debug is True and not options.binary_port
# Basic config # Basic config
app.secret_key = api_key app.secret_key = api_key

3
libs/guessit/fileutils.py

@ -18,6 +18,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
import ntpath
import os.path import os.path
@ -44,7 +45,7 @@ def split_path(path):
""" """
result = [] result = []
while True: while True:
head, tail = os.path.split(path) head, tail = ntpath.split(path)
# on Unix systems, the root folder is '/' # on Unix systems, the root folder is '/'
if head == '/' and tail == '': if head == '/' and tail == '':

Loading…
Cancel
Save