def _check_database(self): try: log.info("Locking database") self.default_store.lock_database() except DatabaseError: msg = _('Could not lock database. This means there are other clients ' 'connected. Make sure to close every Stoq client ' 'before updating the database') error(msg) # Database migration is actually run in subprocesses, We need to unlock # the tables again and let the upgrade continue log.info("Releasing database lock") self.default_store.unlock_database() sucess = db_settings.test_connection() if not sucess: # FIXME: Improve this message after 1.5 is released msg = _(u'Could not connect to the database using command line ' 'tool! Aborting.') + ' ' msg += _(u'Please, check if you can connect to the database ' 'using:') + ' ' msg += _(u'psql -l -h <server> -p <port> -U <username>') error(msg) return return True
def _check_database(self): try: log.info("Locking database") self.default_store.lock_database() except DatabaseError: msg = _( 'Could not lock database. This means there are other clients ' 'connected. Make sure to close every Stoq client ' 'before updating the database') error(msg) # Database migration is actually run in subprocesses, We need to unlock # the tables again and let the upgrade continue log.info("Releasing database lock") self.default_store.unlock_database() sucess = db_settings.test_connection() if not sucess: # FIXME: Improve this message after 1.5 is released msg = _(u'Could not connect to the database using command line ' 'tool! Aborting.') + ' ' msg += _(u'Please, check if you can connect to the database ' 'using:') + ' ' msg += _(u'psql -l -h <server> -p <port> -U <username>') error(msg) return return True
def update(self, plugins=True, backup=True): log.info("Upgrading database (plugins=%r, backup=%r)" % ( plugins, backup)) try: log.info("Locking database") self.default_store.lock_database() except DatabaseError: msg = _('Could not lock database. This means there are other clients ' 'connected. Make sure to close every Stoq client ' 'before updating the database') error(msg) # Database migration is actually run in subprocesses, We need to unlock # the tables again and let the upgrade continue log.info("Releasing database lock") self.default_store.unlock_database() sucess = db_settings.test_connection() if not sucess: # FIXME: Improve this message after 1.5 is released msg = _(u'Could not connect to the database using command line ' 'tool! Aborting.') + ' ' msg += _(u'Please, check if you can connect to the database ' 'using:') + ' ' msg += _(u'psql -l -h <server> -p <port> -U <username>') error(msg) return if backup: temporary = tempfile.mktemp(prefix="stoq-dump-") log.info("Making a backup to %s" % (temporary, )) create_log.info("BACKUP-START:") success = db_settings.dump_database(temporary) if not success: info(_(u'Could not create backup! Aborting.')) info(_(u'Please contact stoq team to inform this problem.\n')) return # We have to wrap a try/except statement inside a try/finally to # support python previous to 2.5 version. try: try: super(StoqlibSchemaMigration, self).update() if plugins: self.update_plugins() except Exception: exc = sys.exc_info() tb_str = ''.join(traceback.format_exception(*exc)) collect_traceback(exc, submit=True) create_log.info("ERROR:%s" % (tb_str, )) if backup: log.info("Restoring backup %s" % (temporary, )) create_log.info("RESTORE-START:") new_name = db_settings.restore_database(temporary) create_log.info("RESTORE-DONE:%s" % (new_name, )) return False finally: if backup is True: os.unlink(temporary) log.info("Migration done") return True
def update(self, plugins=True, backup=True): log.info("Upgrading database (plugins=%r, backup=%r)" % (plugins, backup)) try: log.info("Locking database") self.default_store.lock_database() except DatabaseError: msg = _( 'Could not lock database. This means there are other clients ' 'connected. Make sure to close every Stoq client ' 'before updating the database') error(msg) # Database migration is actually run in subprocesses, We need to unlock # the tables again and let the upgrade continue log.info("Releasing database lock") self.default_store.unlock_database() sucess = db_settings.test_connection() if not sucess: # FIXME: Improve this message after 1.5 is released msg = _(u'Could not connect to the database using command line ' 'tool! Aborting.') + ' ' msg += _(u'Please, check if you can connect to the database ' 'using:') + ' ' msg += _(u'psql -l -h <server> -p <port> -U <username>') error(msg) return if backup: temporary = tempfile.mktemp(prefix="stoq-dump-") log.info("Making a backup to %s" % (temporary, )) create_log.info("BACKUP-START:") success = db_settings.dump_database(temporary) if not success: info(_(u'Could not create backup! Aborting.')) info(_(u'Please contact stoq team to inform this problem.\n')) return # We have to wrap a try/except statement inside a try/finally to # support python previous to 2.5 version. try: try: super(StoqlibSchemaMigration, self).update() if plugins: self.update_plugins() except Exception: exc = sys.exc_info() tb_str = ''.join(traceback.format_exception(*exc)) collect_traceback(exc, submit=True) create_log.info("ERROR:%s" % (tb_str, )) if backup: log.info("Restoring backup %s" % (temporary, )) create_log.info("RESTORE-START:") new_name = db_settings.restore_database(temporary) create_log.info("RESTORE-DONE:%s" % (new_name, )) return False finally: if backup is True: os.unlink(temporary) log.info("Migration done") return True