def update(old_version, new_version): """ Called whenever a version change in kolibri is detected """ logger.info("Running update routines for new version...") try: # Check if there are other kolibri instances running # If there are, then we need to stop users from starting kolibri again. get_status() logger.error( "There is a Kolibri server running. " "Running updates now could cause a database error. " "Please use `kolibri stop` and try again. " ) sys.exit(1) except NotRunning: pass _migrate_databases() run_upgrades(old_version, new_version) with open(version_file(), "w") as f: f.write(kolibri.__version__) from django.core.cache import caches cache = caches["built_files"] cache.clear()
def move_content_directory(self, dst): # Check exsitence of current directory before running the commands. content_directory = OPTIONS["Paths"]["CONTENT_DIR"] destination = os.path.abspath(os.path.expanduser(dst)) if not os.path.exists(content_directory): self.stderr.write( self.style.ERROR( "\nCurrent content directory {} does not exist.").format( content_directory)) raise SystemExit(1) # If the current directory is the same as the destination if content_directory == destination: self.stderr.write( self.style.ERROR( "\nDestination {} is the current content directory."). format(destination)) raise SystemExit(1) # Check if Kolibri is running try: server.get_status() self.stderr.write( self.style.ERROR( "Cannot migrate content while Kolibri is running, please run:\n" "\n" " kolibri stop\n")) raise SystemExit(1) except server.NotRunning: pass self.migrate(content_directory, destination)
def handle(self, *args, **options): try: server.get_status() self.stderr.write(self.style.ERROR( "Cannot restore while Kolibri is running, please run:\n" "\n" " kolibri stop\n" )) raise SystemExit() except server.NotRunning: # Great, it's not running! pass latest = options['latest'] use_backup = options.get("dump_file", None) if latest == bool(use_backup): raise CommandError("Either specify a backup file or use --latest") logger.info("Beginning database restore") if latest: search_root = default_backup_folder() use_backup = None # Ultimately, we are okay about a backup from a minor release fallback_version = ".".join(map(str, kolibri.VERSION[:2])) if os.path.exists(search_root): use_backup = search_latest(search_root, fallback_version) if not use_backup: raise RuntimeError( "Could not find a database backup for version: {}".format( fallback_version ) ) logger.info("Using backup file: {}".format(use_backup)) if not os.path.isfile(use_backup): raise CommandError("Couldn't find: {}".format(use_backup)) dbrestore(use_backup) self.stdout.write(self.style.SUCCESS( "Restored database from: {path}".format(path=use_backup) ))
def handle(self, *args, **options): try: server.get_status() self.stderr.write( self.style.ERROR( "Cannot restore while Kolibri is running, please run:\n" "\n" " kolibri stop\n")) raise SystemExit() except server.NotRunning: # Great, it's not running! pass latest = options['latest'] use_backup = options.get("dump_file", None) if latest == bool(use_backup): raise CommandError("Either specify a backup file or use --latest") logger.info("Beginning database restore") if latest: search_root = default_backup_folder() use_backup = None # Ultimately, we are okay about a backup from a minor release fallback_version = ".".join(map(str, kolibri.VERSION[:2])) if os.path.exists(search_root): use_backup = search_latest(search_root, fallback_version) if not use_backup: raise RuntimeError( "Could not find a database backup for version: {}".format( fallback_version)) logger.info("Using backup file: {}".format(use_backup)) if not os.path.isfile(use_backup): raise CommandError("Couldn't find: {}".format(use_backup)) dbrestore(use_backup) self.stdout.write( self.style.SUCCESS( "Restored database from: {path}".format(path=use_backup)))
def stop(): """ Stops the server unless it isn't running """ try: server.get_status() except server.NotRunning as e: if e.status_code == server.STATUS_STOPPED: logging.info("Already stopped: {}".format( server.status_messages[server.STATUS_STOPPED])) sys.exit(0) status = server.stop() if status == server.STATUS_STOPPED: if OPTIONS["Server"]["CHERRYPY_START"]: logger.info("Kolibri server has successfully been stopped.") else: logger.info( "Kolibri background services have successfully been stopped.") sys.exit(0) sys.exit(status)
def handle(self, *args, **options): try: server.get_status() self.stderr.write(self.style.ERROR( "Cannot restore while Kolibri is running, please run:\n" "\n" " kolibri stop\n" )) raise SystemExit() except server.NotRunning: # Great, it's not running! pass dest_folder = options.get("dest_folder", None) backup = dbbackup(kolibri.__version__, dest_folder=dest_folder) self.stdout.write(self.style.SUCCESS( "Backed up database to: {path}".format(path=backup) ))
def handle(self, *args, **options): try: server.get_status() self.stderr.write( self.style.ERROR( "Cannot restore while Kolibri is running, please run:\n" "\n" " kolibri stop\n")) raise SystemExit() except server.NotRunning: # Great, it's not running! pass dest_folder = options.get("dest_folder", None) backup = dbbackup(kolibri.__version__, dest_folder=dest_folder) self.stdout.write( self.style.SUCCESS( "Backed up database to: {path}".format(path=backup)))
def handle(self, *args, **options): try: server.get_status() self.stderr.write( self.style.ERROR( "Cannot restore while Kolibri is running, please run:\n" "\n" " kolibri stop\n")) raise SystemExit() except server.NotRunning: # Great, it's not running! pass latest = options["latest"] select = options["select"] use_backup = options.get("dump_file", None) logger.info("Beginning database restore") search_root = default_backup_folder() if latest: use_backup = self.fetch_latest(search_root) elif select: use_backup = self.select_backup(search_root) logger.info("Using backup file: {}".format(use_backup)) if not os.path.isfile(use_backup): raise CommandError("Couldn't find: {}".format(use_backup)) dbrestore(use_backup) self.stdout.write( self.style.SUCCESS( "Restored database from: {path}".format(path=use_backup)))