def prepare_restore(filename): src_zip_file_path = os.path.join(get_backup_path(), filename) dest_zip_file_path = os.path.join(get_restore_path(), filename) success = False try: shutil.copy(src_zip_file_path, dest_zip_file_path) except OSError: logging.exception( f'Unable to copy backup archive to {dest_zip_file_path}') else: try: with ZipFile(dest_zip_file_path, 'r') as zipObj: zipObj.extractall(path=get_restore_path()) except BadZipFile: logging.exception( f'Unable to extract files from backup archive {dest_zip_file_path}' ) success = True finally: try: os.remove(dest_zip_file_path) except OSError: logging.exception( f'Unable to delete backup archive {dest_zip_file_path}') if success: logging.debug('time to restart') from server import webserver webserver.restart()
def post(self): from server import webserver action = request.args.get('action') if action == "shutdown": webserver.shutdown() elif action == "restart": webserver.restart() return '', 204
def apply_update(): is_updated = False update_dir = os.path.join(args.config_dir, 'update') bazarr_zip = os.path.join(update_dir, 'bazarr.zip') bazarr_dir = os.path.dirname(os.path.dirname(__file__)) build_dir = os.path.join(os.path.dirname(__file__), 'frontend', 'build') if os.path.isdir(update_dir): if os.path.isfile(bazarr_zip): logging.debug('BAZARR is trying to unzip this release to {0}: {1}'.format(bazarr_dir, bazarr_zip)) try: with ZipFile(bazarr_zip, 'r') as archive: zip_root_directory = '' if len({item.split('/')[0] for item in archive.namelist()}) == 1: zip_root_directory = archive.namelist()[0] if os.path.isdir(build_dir): try: rmtree(build_dir, ignore_errors=True) except Exception as e: logging.exception( 'BAZARR was unable to delete the previous build directory during upgrade process.') for file in archive.namelist(): if file.startswith(zip_root_directory) and file != zip_root_directory and not \ file.endswith('bazarr.py'): file_path = os.path.join(bazarr_dir, file[len(zip_root_directory):]) parent_dir = os.path.dirname(file_path) os.makedirs(parent_dir, exist_ok=True) if not os.path.isdir(file_path): with open(file_path, 'wb+') as f: f.write(archive.read(file)) except Exception as e: logging.exception('BAZARR unable to unzip release') else: is_updated = True try: logging.debug('BAZARR successfully unzipped new release and will now try to delete the leftover ' 'files.') update_cleaner(zipfile=bazarr_zip, bazarr_dir=bazarr_dir, config_dir=args.config_dir) except: logging.exception('BAZARR unable to cleanup leftover files after upgrade.') else: logging.debug('BAZARR successfully deleted leftover files.') finally: logging.debug('BAZARR now deleting release archive') os.remove(bazarr_zip) else: return if is_updated: logging.debug('BAZARR new release have been installed, now we restart') from server import webserver webserver.restart()
def apply_update(): is_updated = False update_dir = os.path.join(args.config_dir, 'update') bazarr_zip = os.path.join(update_dir, 'bazarr.zip') bazarr_dir = os.path.dirname(os.path.dirname(__file__)) if os.path.isdir(update_dir): if os.path.isfile(bazarr_zip): logging.debug( 'BAZARR is trying to unzip this release to {0}: {1}'.format( bazarr_dir, bazarr_zip)) try: with ZipFile(bazarr_zip, 'r') as archive: zip_root_directory = archive.namelist()[0] for file in archive.namelist(): if file.startswith(zip_root_directory) and file != zip_root_directory and not \ file.endswith('bazarr.py'): file_path = os.path.join( bazarr_dir, file[len(zip_root_directory):]) parent_dir = os.path.dirname(file_path) os.makedirs(parent_dir, exist_ok=True) if not os.path.isdir(file_path): with open(file_path, 'wb+') as f: f.write(archive.read(file)) except Exception as e: logging.exception('BAZARR unable to unzip release') else: is_updated = True finally: logging.debug('BAZARR now deleting release archive') os.remove(bazarr_zip) else: return if is_updated: logging.debug('BAZARR new release have been installed, now we restart') from server import webserver webserver.restart()
def updated(restart=True): if settings.general.getboolean('update_restart') and restart: from server import webserver webserver.restart() else: database.execute("UPDATE system SET updated='1'")