def run(self): """ Run the DB update """ clearscreen() print """ _\|/_ (o o) {:>32} +----oOO---OOo----------------------------------+ | | | UPDATING B3 DATABASE | | | +-----------------------------------------------+ """.format('B3 : %s' % b3.__version__) raw_input("press any key to start the update...") def _update_database(storage, update_version): """ Update a B3 database. :param storage: the initialized storage module :param update_version: the update version """ if B3version(b3.__version__) >= update_version: sql = b3.getAbsolutePath('@b3/sql/%s/b3-update-%s.sql' % (storage.protocol, update_version)) if os.path.isfile(sql): try: print '>>> updating database to version %s' % update_version sleep(.5) storage.queryFromFile(sql) except Exception, err: print 'WARNING: could not update database properly: %s' % err sleep(3)
def run(self): """ Run the DB update """ clearscreen() print(""" _\|/_ (o o) {:>32} +----oOO---OOo----------------------------------+ | | | UPDATING B3 DATABASE | | | +-----------------------------------------------+ """.format('B3 : %s' % b3.__version__)) input("press any key to start the update...") def _update_database(storage, update_version): """ Update a B3 database. :param storage: the initialized storage module :param update_version: the update version """ if B3version(b3.__version__) >= update_version: sql = b3.getAbsolutePath('@b3/sql/%s/b3-update-%s.sql' % (storage.protocol, update_version)) if os.path.isfile(sql): try: print('>>> updating database to version %s' % update_version) sleep(.5) storage.queryFromFile(sql) except Exception as err: print( 'WARNING: could not update database properly: %s' % err) sleep(3) dsn = self.config.get('b3', 'database') dsndict = splitDSN(dsn) database = getStorage(dsn, dsndict, StubParser()) _update_database(database, '1.3.0') _update_database(database, '1.6.0') _update_database(database, '1.7.0') _update_database(database, '1.8.1') _update_database(database, '1.9.0') _update_database(database, '1.10.0') console_exit('B3 database update completed!')
def start(mainconfig, options): """ Main B3 startup. :param mainconfig: The B3 configuration file instance :type: b3.config.MainConfig :param options: command line options """ clearscreen() global confdir confdir = os.path.dirname(mainconfig.fileName) sys.stdout.write('Starting B3 : %s\n' % getB3versionString()) sys.stdout.write('Autorestart mode : %s\n' % ('ON' if options.autorestart else 'OFF')) sys.stdout.flush() try: update_channel = mainconfig.get('update', 'channel') except (NoSectionError, NoOptionError): pass else: sys.stdout.write('Checking update : ') sys.stdout.flush() if update_channel == 'skip': sys.stdout.write('SKIP\n') sys.stdout.flush() else: updatetext = checkUpdate(__version__, channel=update_channel, singleLine=True, showErrormsg=True) if updatetext: sys.stdout.write('%s\n' % updatetext) sys.stdout.flush() time.sleep(2) else: sys.stdout.write('no update available\n') sys.stdout.flush() time.sleep(1) # not real loading but the user will get what's configuration he is using sys.stdout.write('Loading config : %s\n' % getShortPath(mainconfig.fileName, True)) sys.stdout.flush() parsertype = mainconfig.get('b3', 'parser') sys.stdout.write('Loading parser : %s\n' % parsertype) sys.stdout.flush() parser = loadParser(parsertype) global console console = parser(mainconfig, options) def termSignalHandler(signum, frame): """ Define the signal handler so to handle B3 shutdown properly. """ console.bot("TERM signal received: shutting down") console.shutdown() raise SystemExit(222) try: # necessary if using the functions profiler, # because signal.signal cannot be used in threads signal.signal(signal.SIGTERM, termSignalHandler) except Exception: pass try: console.start() except KeyboardInterrupt: console.shutdown() print 'Goodbye' return except SystemExit, msg: print 'EXITING: %s' % msg raise