def Init(self): parser = argparse.ArgumentParser( formatter_class=argparse.ArgumentDefaultsHelpFormatter, description= 'This is the standalone database updater. It downloads the current database update from mediathekview.de and integrates it in a local database' ) parser.add_argument('-v', '--verbose', default=0, action='count', help='Show progress messages') subparsers = parser.add_subparsers(dest='dbtype', help='target database') sqliteopts = subparsers.add_parser( 'sqlite', formatter_class=argparse.ArgumentDefaultsHelpFormatter) sqliteopts.add_argument( '-p', '--path', dest='path', help='alternative path for the sqlite database', default='./') mysqlopts = subparsers.add_parser( 'mysql', formatter_class=argparse.ArgumentDefaultsHelpFormatter) mysqlopts.add_argument('-H', '--host', dest='host', help='hostname or ip address', default='localhost') mysqlopts.add_argument('-P', '--port', dest='port', help='connection port', default='3306') mysqlopts.add_argument('-u', '--user', dest='user', help='connection username', default='mediathekview') mysqlopts.add_argument('-p', '--password', dest='password', help='connection password', default=None) mysqlopts.add_argument('-d', '--database', dest='database', default='mediathekview', help='database name') self.args = parser.parse_args() self.verbosity = self.args.verbose self.info('Startup') self.settings = Settings(self.args) self.notifier = Notifier() self.monitor = MediathekViewMonitor() self.updater = MediathekViewUpdater( self.getNewLogger('MediathekViewUpdater'), self.notifier, self.settings, self.monitor) self.updater.Init()
def __init__(self): super(MediathekViewService, self).__init__() self.set_topic('Service') self.settings = Settings() self.notifier = Notifier() self.monitor = MediathekViewMonitor(self, 'instanceid') self.updater = MediathekViewUpdater(self.get_new_logger( 'Updater'), self.notifier, self.settings, self.monitor)
def __init__(self): super(MediathekViewService, self).__init__() self.setTopic('Service') self.settings = Settings() self.notifier = Notifier() self.monitor = MediathekViewMonitor(self) self.updater = MediathekViewUpdater(self.getNewLogger('Updater'), self.notifier, self.settings, self.monitor)
def __init__(self): super(MediathekViewService, self).__init__() # self.set_topic('Service') self.logger = appContext.MVLOGGER.get_new_logger('MediathekViewService') self.settings = appContext.MVSETTINGS self.notifier = appContext.MVNOTIFIER self.monitor = MonitorKodi() appContext.initMonitor(self.monitor) self.updater = MediathekViewUpdater() self._lastDatabaseType = self.settings.getDatabaseType()
class MediathekViewService(KodiService): def __init__(self): super(MediathekViewService, self).__init__() self.setTopic('Service') self.settings = Settings() self.notifier = Notifier() self.monitor = MediathekViewMonitor(self) self.updater = MediathekViewUpdater(self.getNewLogger('Updater'), self.notifier, self.settings, self.monitor) def Init(self): self.info('Init') self.updater.Init() def Run(self): self.info('Starting up...') while not self.monitor.abortRequested(): updateop = self.updater.GetCurrentUpdateOperation() if updateop == 1: # full update self.info('Initiating full update...') self.updater.Update(True) elif updateop == 2: # differential update self.info('Initiating differential update...') self.updater.Update(False) # Sleep/wait for abort for 60 seconds if self.monitor.waitForAbort(60): # Abort was requested while waiting. We should exit break self.info('Shutting down...') def Exit(self): self.info('Exit') self.updater.Exit() def ReloadSettings(self): # TODO: support online reconfiguration pass
def run(self): """ Execution of the service """ self.logger.debug('Service Startup...') # Wait for Kodi to retrieve network self.monitor.wait_for_abort(self.settings.getDelayStartupSec()) # error counter to slow down self.errorCount = 0 # while not self.monitor.abort_requested(): # slow down in case of errors (+1 because 0 is unlimited!) delayInSec = (self.errorCount * 60) + 1 self.monitor.wait_for_abort(delayInSec) if delayInSec > 1: self.logger.warn('Delayed service agent by {} sec due to error count {}', delayInSec, self.errorCount) # self.updater = MediathekViewUpdater() self.updater.init() # try: # we need this for database change and update variable cache if self._lastDatabaseType != self.settings.getDatabaseType(): self.logger.debug('database change from {} to {}', self._lastDatabaseType, self.settings.getDatabaseType()) self._lastDatabaseType = self.settings.getDatabaseType() self.updater.database.get_status() self.updater.doUpdate() self.errorCount = 0 except Exception as err: self.logger.error('MediathekViewUpdater {}', err) self.updater.exit() self.settings.setDatabaseStatus('UNINIT'); self.errorCount = self.errorCount + 1 # self.updater.exit() # Sleep/wait for abort for 60 seconds if self.monitor.wait_for_abort(appContext.MVSETTINGS.getUpdateCheckIntervel()): # Abort was requested while waiting. We should exit break self.logger.info('Shutting down Service')
class MediathekViewService(KodiService): def __init__(self): super(MediathekViewService, self).__init__() self.setTopic('Service') self.settings = Settings() self.notifier = Notifier() self.monitor = MediathekViewMonitor(self, 'instanceid') self.updater = MediathekViewUpdater(self.getNewLogger('Updater'), self.notifier, self.settings, self.monitor) def Init(self): self.info('Init (instance id: {})', self.monitor.instance_id) self.monitor.RegisterInstance() self.updater.Init(convert=True) self.settings.ResetUserActivity() def Run(self): self.info('Starting up... (instance id: {})', self.monitor.instance_id) while not self.monitor.abortRequested(): if self.settings.Reload() is True: # database configuration changed self.info( '===== Database Configuration has changed - Reloading the updater =====' ) self.updater.Reload() updateop = self.updater.GetCurrentUpdateOperation() if updateop == 1: # full update self.info('Initiating full update...') self.settings.SaveUpdateInstance(self.monitor.instance_id) self.updater.Update(True) elif updateop == 2: # differential update self.info('Initiating differential update...') self.settings.SaveUpdateInstance(self.monitor.instance_id) self.updater.Update(False) # Sleep/wait for abort for 60 seconds if self.monitor.waitForAbort(15): # Abort was requested while waiting. We should exit break self.info('Shutting down... (instance id: {})', self.monitor.instance_id) def Exit(self): self.info('Exit (instance id: {})', self.monitor.instance_id) self.updater.Exit() self.monitor.UnregisterInstance() def ReloadSettings(self): # self.info("===== RELOAD SETTINGS =====") # TODO: support online reconfiguration # currently there is a bug in Kodi: this event is only # triggered if the reconfiguration happen inside the # addon (via setSetting). If teh user changes something # via the settings page, NOTHING WILL HAPPEN! pass
class MediathekViewService(KodiService): """ The main service class """ def __init__(self): super(MediathekViewService, self).__init__() self.set_topic('Service') self.settings = Settings() self.notifier = Notifier() self.monitor = MediathekViewMonitor(self, 'instanceid') self.updater = MediathekViewUpdater(self.get_new_logger('Updater'), self.notifier, self.settings, self.monitor) def init(self): """ Initialisation of the service """ self.info('Init (instance id: {})', self.monitor.instance_id) self.monitor.register_instance() self.updater.init(convert=True) self.settings.reset_user_activity() def run(self): """ Execution of the service """ self.info('Starting up... (instance id: {})', self.monitor.instance_id) while not self.monitor.abort_requested(): if self.settings.reload() is True: # database configuration changed self.info( '===== Database Configuration has changed - Reloading the updater =====' ) self.updater.reload() updateop = self.updater.get_current_update_operation() if updateop == 1: # full update self.info('Initiating full update...') self.settings.save_update_instance(self.monitor.instance_id) self.updater.update(True) elif updateop == 2: # differential update self.info('Initiating differential update...') self.settings.save_update_instance(self.monitor.instance_id) self.updater.update(False) # Sleep/wait for abort for 60 seconds if self.monitor.wait_for_abort(15): # Abort was requested while waiting. We should exit break self.info('Shutting down... (instance id: {})', self.monitor.instance_id) def exit(self): """ Shutdown of the service """ self.info('Exit (instance id: {})', self.monitor.instance_id) self.updater.exit() self.monitor.unregister_instance() def reload_settings(self): """ Reload settings and reconfigure service behaviour """ # self.info("===== RELOAD SETTINGS =====") # TODO: support online reconfiguration # currently there is a bug in Kodi: this event is only # triggered if the reconfiguration happen inside the # addon (via setSetting). If teh user changes something # via the settings page, NOTHING WILL HAPPEN! pass
def init(self): """ Startup of the application """ # pylint: disable=line-too-long parser = argparse.ArgumentParser( formatter_class=argparse.ArgumentDefaultsHelpFormatter, description= 'This is the standalone database updater. It downloads the current database update from mediathekview.de and integrates it in a local database' ) parser.add_argument('-v', '--verbose', default=0, action='count', help='show progress messages') subparsers = parser.add_subparsers(dest='dbtype', help='target database') sqliteopts = subparsers.add_parser( 'sqlite', formatter_class=argparse.ArgumentDefaultsHelpFormatter) sqliteopts.add_argument('-v', '--verbose', default=0, action='count', help='show progress messages') sqliteforce = sqliteopts.add_mutually_exclusive_group() sqliteforce.add_argument('-f', '--force', default=False, action='store_true', help='ignore the minimum interval') sqliteforce.add_argument( '-F', '--full', default=False, action='store_true', help='ignore the minimum interval and force a full update') sqliteopts.add_argument('-i', '--intervall', default=3600, type=int, action='store', help='minimum interval between updates') sqliteopts.add_argument( '-p', '--path', dest='path', help='alternative path for the sqlite database', default='./') sqliteopts.add_argument('-n', '--native', default=False, action='store_true', help='allow native update') mysqlopts = subparsers.add_parser( 'mysql', formatter_class=argparse.ArgumentDefaultsHelpFormatter) mysqlopts.add_argument('-v', '--verbose', default=0, action='count', help='show progress messages') mysqlforce = mysqlopts.add_mutually_exclusive_group() mysqlforce.add_argument('-f', '--force', default=False, action='store_true', help='ignore the minimum interval') mysqlforce.add_argument( '-F', '--full', default=False, action='store_true', help='ignore the minimum interval and force a full update') mysqlopts.add_argument('-i', '--intervall', default=3600, type=int, action='store', help='minimum interval between updates') mysqlopts.add_argument('-H', '--host', dest='host', help='hostname or ip address', default='localhost') mysqlopts.add_argument('-P', '--port', dest='port', help='connection port', default='3306') mysqlopts.add_argument('-u', '--user', dest='user', help='connection username', default='mediathekview') mysqlopts.add_argument('-p', '--password', dest='password', help='connection password', default=None) mysqlopts.add_argument('-d', '--database', dest='database', default='mediathekview', help='database name') self.args = parser.parse_args() self.verbosity = self.args.verbose self.info('Startup') self.settings = Settings(self.args) self.notifier = Notifier() self.monitor = MediathekViewMonitor() self.updater = MediathekViewUpdater( self.get_new_logger('MediathekViewUpdater'), self.notifier, self.settings, self.monitor) return self.updater.init(convert=True)
class UpdateApp(AppLogger): """ The standalone updater application class """ def __init__(self): scriptpath, scriptname = os.path.split(sys.argv[0]) storederr = None version = '0.0' try: tree = ET.parse(os.path.join(scriptpath, 'addon.xml')) version = tree.getroot().attrib['version'] # pylint: disable=broad-except except Exception: # cannot self.warn before super.__init__, so store for later storederr = sys.exc_info() AppLogger.__init__(self, scriptname, version) self.args = None self.verbosity = 0 self.notifier = None self.monitor = None self.updater = None self.settings = None if storederr is not None: self.warn("Unable to find version information: {} {}", storederr[0].__name__, storederr[1]) self.info('Python Version' + sys.version) def init(self): """ Startup of the application """ # pylint: disable=line-too-long parser = argparse.ArgumentParser( formatter_class=argparse.ArgumentDefaultsHelpFormatter, description= 'This is the standalone database updater. It downloads the current database update from mediathekview.de and integrates it in a local database' ) parser.add_argument('-v', '--verbose', default=0, action='count', help='show progress messages') subparsers = parser.add_subparsers(dest='dbtype', help='target database') sqliteopts = subparsers.add_parser( 'sqlite', formatter_class=argparse.ArgumentDefaultsHelpFormatter) sqliteopts.add_argument('-v', '--verbose', default=0, action='count', help='show progress messages') sqliteforce = sqliteopts.add_mutually_exclusive_group() sqliteforce.add_argument('-f', '--force', default=False, action='store_true', help='ignore the minimum interval') sqliteforce.add_argument( '-F', '--full', default=False, action='store_true', help='ignore the minimum interval and force a full update') sqliteopts.add_argument('-i', '--intervall', default=3600, type=int, action='store', help='minimum interval between updates') sqliteopts.add_argument( '-p', '--path', dest='path', help='alternative path for the sqlite database', default='./') sqliteopts.add_argument('-n', '--native', default=False, action='store_true', help='allow native update') mysqlopts = subparsers.add_parser( 'mysql', formatter_class=argparse.ArgumentDefaultsHelpFormatter) mysqlopts.add_argument('-v', '--verbose', default=0, action='count', help='show progress messages') mysqlforce = mysqlopts.add_mutually_exclusive_group() mysqlforce.add_argument('-f', '--force', default=False, action='store_true', help='ignore the minimum interval') mysqlforce.add_argument( '-F', '--full', default=False, action='store_true', help='ignore the minimum interval and force a full update') mysqlopts.add_argument('-i', '--intervall', default=3600, type=int, action='store', help='minimum interval between updates') mysqlopts.add_argument('-H', '--host', dest='host', help='hostname or ip address', default='localhost') mysqlopts.add_argument('-P', '--port', dest='port', help='connection port', default='3306') mysqlopts.add_argument('-u', '--user', dest='user', help='connection username', default='mediathekview') mysqlopts.add_argument('-p', '--password', dest='password', help='connection password', default=None) mysqlopts.add_argument('-d', '--database', dest='database', default='mediathekview', help='database name') self.args = parser.parse_args() self.verbosity = self.args.verbose self.info('Startup') self.settings = Settings(self.args) self.notifier = Notifier() self.monitor = MediathekViewMonitor() self.updater = MediathekViewUpdater( self.get_new_logger('MediathekViewUpdater'), self.notifier, self.settings, self.monitor) return self.updater.init(convert=True) def run(self): """ Execution of the application """ self.info('Starting up...') updateop = self.updater.get_current_update_operation( self.args.force, self.args.full) if updateop == 1: # full update self.info('Initiating full update...') self.updater.update(True) elif updateop == 2: # differential update self.info('Initiating differential update...') self.updater.update(False) self.info('Exiting...') def exit(self): """ Shutdown of the application """ self.updater.exit()
class UpdateApp(AppLogger): def __init__(self): try: self.mypath = os.path.dirname(sys.argv[0]) tree = ET.parse(self.mypath + '/addon.xml') version = tree.getroot().attrib['version'] AppLogger.__init__(self, os.path.basename(sys.argv[0]), version) except Exception: AppLogger.__init__(self, os.path.basename(sys.argv[0]), '0.0') def Init(self): parser = argparse.ArgumentParser( formatter_class=argparse.ArgumentDefaultsHelpFormatter, description= 'This is the standalone database updater. It downloads the current database update from mediathekview.de and integrates it in a local database' ) parser.add_argument('-v', '--verbose', default=0, action='count', help='Show progress messages') subparsers = parser.add_subparsers(dest='dbtype', help='target database') sqliteopts = subparsers.add_parser( 'sqlite', formatter_class=argparse.ArgumentDefaultsHelpFormatter) sqliteopts.add_argument( '-p', '--path', dest='path', help='alternative path for the sqlite database', default='./') mysqlopts = subparsers.add_parser( 'mysql', formatter_class=argparse.ArgumentDefaultsHelpFormatter) mysqlopts.add_argument('-H', '--host', dest='host', help='hostname or ip address', default='localhost') mysqlopts.add_argument('-P', '--port', dest='port', help='connection port', default='3306') mysqlopts.add_argument('-u', '--user', dest='user', help='connection username', default='mediathekview') mysqlopts.add_argument('-p', '--password', dest='password', help='connection password', default=None) mysqlopts.add_argument('-d', '--database', dest='database', default='mediathekview', help='database name') self.args = parser.parse_args() self.verbosity = self.args.verbose self.info('Startup') self.settings = Settings(self.args) self.notifier = Notifier() self.monitor = MediathekViewMonitor() self.updater = MediathekViewUpdater( self.getNewLogger('MediathekViewUpdater'), self.notifier, self.settings, self.monitor) self.updater.Init() def Run(self): self.info('Starting up...') updateop = self.updater.GetCurrentUpdateOperation() if updateop == 1: # full update self.info('Initiating full update...') self.updater.Update(True) elif updateop == 2: # differential update self.info('Initiating differential update...') self.updater.Update(False) self.info('Exiting...') def Exit(self): self.updater.Exit()
def init(self): """ Startup of the application """ # pylint: disable=line-too-long parser = argparse.ArgumentParser( formatter_class=argparse.ArgumentDefaultsHelpFormatter, description='This is the standalone database updater. It downloads the current database update from mediathekview.de and integrates it in a local database' ) parser.add_argument( '-v', '--verbose', default=0, action='count', help='show progress messages' ) subparsers = parser.add_subparsers( dest='dbtype', help='target database' ) sqliteopts = subparsers.add_parser( 'sqlite', formatter_class=argparse.ArgumentDefaultsHelpFormatter) sqliteopts.add_argument( '-v', '--verbose', default=0, action='count', help='show progress messages' ) sqliteforce = sqliteopts.add_mutually_exclusive_group() sqliteforce.add_argument( '-f', '--force', default=False, action='store_true', help='ignore the minimum interval' ) sqliteforce.add_argument( '-F', '--full', default=False, action='store_true', help='ignore the minimum interval and force a full update' ) sqliteopts.add_argument( '-i', '--intervall', default=3500, type=int, action='store', help='minimum interval between updates' ) sqliteopts.add_argument( '-b', '--updateBatchSize', default=10000, type=int, action='store', help='insert/update batch size' ) sqliteopts.add_argument( '-p', '--path', dest='path', help='alternative path for the sqlite database', default='./' ) sqliteopts.add_argument( '-n', '--native', default=False, action='store_true', help='allow native update' ) mysqlopts = subparsers.add_parser( 'mysql', formatter_class=argparse.ArgumentDefaultsHelpFormatter) mysqlopts.add_argument( '-v', '--verbose', default=0, action='count', help='show progress messages' ) mysqlforce = mysqlopts.add_mutually_exclusive_group() mysqlforce.add_argument( '-f', '--force', default=False, action='store_true', help='ignore the minimum interval' ) mysqlforce.add_argument( '-F', '--full', default=False, action='store_true', help='ignore the minimum interval and force a full update' ) mysqlopts.add_argument( '-i', '--intervall', default=3600, type=int, action='store', help='minimum interval between updates' ) mysqlopts.add_argument( '-b', '--updateBatchSize', default=10000, type=int, action='store', help='insert/update batch size' ) mysqlopts.add_argument( '-H', '--host', dest='host', help='hostname or ip address', default='localhost' ) mysqlopts.add_argument( '-P', '--port', dest='port', help='connection port', default='3306' ) mysqlopts.add_argument( '-u', '--user', dest='user', help='connection username', default='mediathekview' ) mysqlopts.add_argument( '-p', '--password', dest='password', help='connection password', default='mediathekview' ) mysqlopts.add_argument( '-d', '--database', dest='database', default='mediathekview', help='database name' ) self.args = parser.parse_args() self.verbosity = self.args.verbose # do it again to have proper loglevel (verbosity) self.logger = LoggerCommandline(self.scriptname, self.version, 'mvupdate', self.verbosity) appContext.initLogger(self.logger) # self.logger.debug('Startup') appContext.initSettings(SettingsCommandline(self.args)) # self.monitor = MonitorInterface() appContext.initMonitor(self.monitor) self.updater = MediathekViewUpdater() # self.logger.info('Python Version' + sys.version) # return self.updater.init()
class UpdateApp(): """ The standalone updater application class """ def __init__(self): self.scriptpath, self.scriptname = os.path.split(sys.argv[0]) storederr = None self.version = '0.0' try: tree = ET.parse(os.path.join(self.scriptpath, 'addon.xml')) self.version = tree.getroot().attrib['version'] # pylint: disable=broad-except except Exception: # cannot self.warn before super.__init__, so store for later storederr = sys.exc_info() # appContext.init() self.logger = LoggerCommandline(self.scriptname, self.version) appContext.initLogger(self.logger) # self.notifier = None appContext.initNotifier(NotifierInterface()) # self.args = None self.verbosity = 0 self.monitor = None self.updater = None self.settings = None if storederr is not None: self.logger.error("Unable to find version information: {} {}", storederr[0].__name__, storederr[1]) def init(self): """ Startup of the application """ # pylint: disable=line-too-long parser = argparse.ArgumentParser( formatter_class=argparse.ArgumentDefaultsHelpFormatter, description='This is the standalone database updater. It downloads the current database update from mediathekview.de and integrates it in a local database' ) parser.add_argument( '-v', '--verbose', default=0, action='count', help='show progress messages' ) subparsers = parser.add_subparsers( dest='dbtype', help='target database' ) sqliteopts = subparsers.add_parser( 'sqlite', formatter_class=argparse.ArgumentDefaultsHelpFormatter) sqliteopts.add_argument( '-v', '--verbose', default=0, action='count', help='show progress messages' ) sqliteforce = sqliteopts.add_mutually_exclusive_group() sqliteforce.add_argument( '-f', '--force', default=False, action='store_true', help='ignore the minimum interval' ) sqliteforce.add_argument( '-F', '--full', default=False, action='store_true', help='ignore the minimum interval and force a full update' ) sqliteopts.add_argument( '-i', '--intervall', default=3500, type=int, action='store', help='minimum interval between updates' ) sqliteopts.add_argument( '-b', '--updateBatchSize', default=10000, type=int, action='store', help='insert/update batch size' ) sqliteopts.add_argument( '-p', '--path', dest='path', help='alternative path for the sqlite database', default='./' ) sqliteopts.add_argument( '-n', '--native', default=False, action='store_true', help='allow native update' ) mysqlopts = subparsers.add_parser( 'mysql', formatter_class=argparse.ArgumentDefaultsHelpFormatter) mysqlopts.add_argument( '-v', '--verbose', default=0, action='count', help='show progress messages' ) mysqlforce = mysqlopts.add_mutually_exclusive_group() mysqlforce.add_argument( '-f', '--force', default=False, action='store_true', help='ignore the minimum interval' ) mysqlforce.add_argument( '-F', '--full', default=False, action='store_true', help='ignore the minimum interval and force a full update' ) mysqlopts.add_argument( '-i', '--intervall', default=3600, type=int, action='store', help='minimum interval between updates' ) mysqlopts.add_argument( '-b', '--updateBatchSize', default=10000, type=int, action='store', help='insert/update batch size' ) mysqlopts.add_argument( '-H', '--host', dest='host', help='hostname or ip address', default='localhost' ) mysqlopts.add_argument( '-P', '--port', dest='port', help='connection port', default='3306' ) mysqlopts.add_argument( '-u', '--user', dest='user', help='connection username', default='mediathekview' ) mysqlopts.add_argument( '-p', '--password', dest='password', help='connection password', default='mediathekview' ) mysqlopts.add_argument( '-d', '--database', dest='database', default='mediathekview', help='database name' ) self.args = parser.parse_args() self.verbosity = self.args.verbose # do it again to have proper loglevel (verbosity) self.logger = LoggerCommandline(self.scriptname, self.version, 'mvupdate', self.verbosity) appContext.initLogger(self.logger) # self.logger.debug('Startup') appContext.initSettings(SettingsCommandline(self.args)) # self.monitor = MonitorInterface() appContext.initMonitor(self.monitor) self.updater = MediathekViewUpdater() # self.logger.info('Python Version' + sys.version) # return self.updater.init() def run(self): """ Execution of the application """ self.logger.debug('Starting up...') self.updater.database.get_status() updateop = self.updater.doUpdate() self.logger.debug('Exiting...') def exit(self): """ Shutdown of the application """ self.updater.exit()