def _update_now(self, mode): ''' Starts and executes update process. :param mode: str 'set_true' or 'update_now' Helper for self.update_now() If mode == set_true, sets core.UPDATING to True This is done so if the user visits /update without setting true they will be redirected back to status. Yields 'true' back to browser If mode == 'update_now', starts update process. Yields 'true' or 'failed'. If true, restarts server. ''' if mode == 'set_true': core.UPDATING = True yield json.dumps({'response': True}) if mode == 'update_now': update_status = version.Version().manager.execute_update() core.UPDATING = False if update_status is False: logging.error('Update Failed.') yield json.dumps({'response': False}) elif update_status is True: yield json.dumps({'response': True}) logging.info('Respawning process...') cherrypy.engine.stop() python = sys.executable os.execl(python, python, *sys.argv) else: return
def update_check(self): ''' Manually check for updates Returns str json.dumps(dict) from Version manager update_check() ''' response = version.Version().manager.update_check() return json.dumps(response)
def __init__(self): self.tmdb = movieinfo.TMDB() self.config = config.Config() self.metadata = library.Metadata() self.predb = predb.PreDB() self.searcher = searcher.Searcher() self.score = searchresults.Score() self.snatcher = snatcher.Snatcher() self.version = version.Version()
def update_server(self, mode): ''' Starts and executes update process. mode (str): 'set_true' or 'update_now' This method has two major functions based on mode set_true: Sets core.UPDATING to True, the browser should then automatically redirect the user to the update page that calls update_server('update_now') update_now: Starts update process: * Stops task scheduler to cancel all Timers * Waits for in-process tasks to finish. Yields to browser a list of currently-running tasks every 1.5 seconds * Yields updating message to browser. Calls update method * Sets core.UPDATING to False * Yields response from update method to browser If False, starts scheduler plugin again to get back to a normal state If True, calls restart method. Browser is responsible for redirecting afer the server is back up. Returns dict ajax-style response ''' if mode == 'set_true': core.UPDATING = True return json.dumps({'response': True}) if mode == 'update_now': logging.info('Update process started.') core.scheduler_plugin.stop() active_tasks = [k for k, v in core.scheduler_plugin.task_list.items() if v.running] while len(active_tasks) > 0: yield json.dumps({'response': True, 'status': 'waiting', 'active_tasks': active_tasks}) active_tasks = [k for k, v in core.scheduler_plugin.task_list.items() if v.running] time.sleep(1.5) yield json.dumps({'response': True, 'status': 'updating'}) update_status = version.Version().manager.execute_update() core.UPDATING = False if update_status is False: logging.error('Update Failed.') yield json.dumps({'response': False, 'error': _('Unable to complete update.')}) core.scheduler_plugin.restart() elif update_status is True: yield json.dumps({'response': True, 'status': 'complete'}) self.server_status('restart') else: return json.dumps({'response': False})
def update_check(): ''' Checks for any available updates Returns dict from core.version.Version.manager.update_check(): {'status': 'error', 'error': <error> } {'status': 'behind', 'behind_count': #, 'local_hash': 'abcdefg', 'new_hash': 'bcdefgh'} {'status': 'current'} ''' ver = version.Version() data = ver.manager.update_check() # if data['status'] == u'current', nothing to do. if data['status'] == u'error': notif = { 'type': 'warning', 'closeButton': 'true', 'title': 'Error Checking for Updates', 'body': data['error'], 'params': '{closeButton: true, timeOut: 0, extendedTimeOut: 0}' } Notification.add(notif) elif data['status'] == u'behind': if data['behind_count'] == 1: title = u'1 Update Available' else: title = u'{} Updates Available'.format(data['behind_count']) compare = u'{}/compare/{}...{}'.format(core.GIT_URL, data['local_hash'], data['new_hash']) notif = { 'type': 'update', 'title': title, 'body': 'Click <a href="update_now"><u>here</u></a> to update now.' '<br/> Click <a href="' + compare + '"><u>here</u></a> to view changes.', 'params': { 'timeOut': 0, 'extendedTimeOut': 0, 'tapToDismiss': 0 } } Notification.add(notif) return data
def update_check(): ''' Checks for any available updates Returns dict from core.version.Version.manager.update_check(): {'status': 'error', 'error': <error> } {'status': 'behind', 'behind_count': #, 'local_hash': 'abcdefg', 'new_hash': 'bcdefgh'} {'status': 'current'} ''' ver = version.Version() data = ver.manager.update_check() # if data['status'] == 'current', nothing to do. if data['status'] == 'error': notif = { 'icon': 'fa-exclamation-triangle', 'title': 'Error Checking for Updates', 'text': data['error'] } Notification.add(notif) elif data['status'] == 'behind': if core.CONFIG['Server']['installupdates'] == 'true': hour = core.CONFIG['Server']['installupdatehr'] minute = core.CONFIG['Server']['installupdatemin'] text = 'Updates will install automatically at {}:{}'.format( hour, minute) else: text = '' if data['behind_count'] == 1: title = '1 Update Available' else: title = '{} Updates Available'.format(data['behind_count']) title_link = '{}/compare/{}...{}'.format(core.GIT_API, data['new_hash'], data['local_hash']) button = ('Update Now', '/update_now', 'fa-arrow-circle-up') notif = { 'icon': 'fa-star', 'title': title, 'title_link': title_link, 'text': text, 'button': button } Notification.add(notif) return data
def update_install(): ver = version.Version() if not core.UPDATE_STATUS or core.UPDATE_STATUS['status'] != u'behind': return logging.info(u'Running automatic updater.') logging.info(u'Currently {} commits behind. Updating to {}.'.format( core.UPDATE_STATUS['behind_count'], core.UPDATE_STATUS['new_hash'])) core.UPDATING = True logging.info(u'Executing update.') update = ver.manager.execute_update() core.UPDATING = False if not update: logging.error(u'Update failed.') logging.info(u'Update successful, restarting.') cherrypy.engine.restart() return
import cherrypy import core import glob import hashlib import os from core import searcher, version, notification from core.rss import imdb, popularmovies from core.cp_plugins import taskscheduler from core import trakt from core.library import Metadata logging = logging.getLogger(__name__) ver = version.Version() md = Metadata() search = searcher.Searcher() def create_plugin(): ''' Creates plugin instance, adds tasks, and subscribes to cherrypy.engine Does not return ''' core.scheduler_plugin = taskscheduler.SchedulerPlugin(cherrypy.engine) AutoSearch.create() AutoUpdateCheck.create() ImdbRssSync.create() MetadataUpdate.create() PopularMoviesSync.create()