def download_plugins(self, plugins: list) -> list: download_res = [] delete_existing_folder(self.get_plugin_download_dir()) from src.system.resources.app.utils import get_github_token token: str = get_github_token() plugin_download_links = self._get_plugin_download_links(token, plugins) for plugin_download_link in plugin_download_links: plugin: str = plugin_download_link['plugin'] download_link: str = plugin_download_link['download_link'] error = plugin_download_link['error'] if error: download_res.append({ 'plugin': plugin, 'download': False, 'error': error }) else: try: download_unzip_service(download_link, self.get_plugin_download_dir(), token, self.is_asset) download_res.append({ 'plugin': plugin, 'download': True, 'error': "" }) except Exception as e: download_res.append({ 'plugin': plugin, 'download': False, 'error': str(e) }) return download_res
def install_app(arg): _service = arg['service'].upper() _version = arg['version'] res = {'service': _service, 'version': _version, 'installation': False, 'backup_data': False, 'error': ''} try: app: InstallableApp = get_app_from_service(_service, _version) if app.app_type == Types.APT_APP.value: installation: bool = app.install() res = {**res, 'version': app.version, 'installation': installation} else: if not is_dir_exist(app.get_downloaded_dir()): res = { **res, 'version': app.version, 'error': f'Please download service {app.service} with version {app.version} at first' } if not res.get('error'): backup_data: bool = app.backup_data() delete_existing_folder(app.get_installation_dir()) shutil.copytree(app.get_downloaded_dir(), app.get_installed_dir()) installation: bool = app.install() app.install_plugins() delete_existing_folder(app.get_download_dir()) res = {**res, 'version': app.version, 'installation': installation, 'backup_data': backup_data} except (Exception, NotFoundException) as e: res = {**res, 'error': str(e)} return res
def download(app_setting: AppSetting, repo_name: str, _version: str, token: str): download_dir = _get_download_dir(app_setting, repo_name) download_link: str = _get_download_link(repo_name, _version, app_setting.device_type, token) delete_existing_folder(download_dir) try: name: str = _download_unzip_service(download_link, download_dir, token) except Exception: raise ModuleNotFoundError(f'download link {download_link} or token might be incorrect') _after_download_upload(download_dir, name, _version)
def install(app_setting: AppSetting, repo_name: str, _version: str) -> bool: installation_dir: str = _get_installation_dir(app_setting, repo_name) download_dir: str = _get_download_dir(app_setting, repo_name) downloaded_dir: str = _get_downloaded_dir(download_dir, _version) installed_dir: str = _get_installed_dir(installation_dir, _version) delete_existing_folder(installation_dir) shutil.copytree(downloaded_dir, installed_dir) systemd: Systemd = RubixServiceSystemd(installed_dir, app_setting.device_type, app_setting.auth) installation = systemd.install() delete_existing_folder(downloaded_dir) return installation
def install_plugins(self) -> bool: try: plugin_download_dir: str = self.get_plugin_download_dir() if not os.path.exists(plugin_download_dir): return False plugin_installation_dir = self.get_plugin_installation_dir() delete_existing_folder(plugin_installation_dir) shutil.copytree(plugin_download_dir, plugin_installation_dir) delete_existing_folder(plugin_download_dir) except Exception as e: logger.info(str(e)) return False return True
def post(cls): args = request.get_json() if not validate_args(args, delete_data_attributes): raise BadDataException('Invalid request') delete_data_res = [] for arg in args: service: str = arg['service'].upper() app: InstallableApp = get_app_from_service(service) try: res = { 'service': service, 'deletion': False, 'backup_data': False, 'stop': False, 'error': '' } stop: bool = app.stop() backup_data: bool = app.backup_data() deletion: bool = delete_existing_folder(app.get_data_dir()) res = { **res, 'deletion': deletion, 'backup_data': backup_data, 'stop': stop } except Exception as e: res = {'error': str(e)} delete_data_res.append(res) return delete_data_res
def upload(self, file: FileStorage) -> dict: if self.app_type == Types.APT_APP.value: return { 'service': self.service, 'version': self.version, 'existing_app_deletion': False } upload_name = upload_unzip_service(file, self.get_download_dir()) existing_app_deletion: bool = delete_existing_folder( self.get_downloaded_dir()) self.after_download_upload(upload_name) self.download_installed_plugin() return { 'service': self.service, 'version': self.version, 'existing_app_deletion': existing_app_deletion }
def post(cls): parser = reqparse.RequestParser() parser.add_argument('service', type=str, required=True) args = parser.parse_args() service: str = args['service'].upper() app: InstallableApp = get_app_from_service(service) version: str = app.get_installed_version() if not version: raise NotFoundException(f'service {service} is not running') app.set_version(version) deletion: bool = app.uninstall() existing_apps_deletion: bool = delete_existing_folder( app.get_installation_dir()) return { 'service': service, 'deletion': deletion, 'existing_apps_deletion': existing_apps_deletion }
def download(self) -> dict: if self.app_type == Types.APT_APP.value: return { 'service': self.service, 'version': self.version, 'existing_app_deletion': False } from src.system.resources.app.utils import get_github_token token: str = get_github_token() download_name = download_unzip_service(self.get_download_link(token), self.get_download_dir(), token, self.is_asset) existing_app_deletion: bool = delete_existing_folder( self.get_downloaded_dir()) self.after_download_upload(download_name) self.download_installed_plugin() return { 'service': self.service, 'version': self.version, 'existing_app_deletion': existing_app_deletion }
def upload(app_setting: AppSetting, repo_name: str, _version: str, file: FileStorage): download_dir = _get_download_dir(app_setting, repo_name) delete_existing_folder(download_dir) name: str = _upload_unzip_service(file, download_dir) _after_download_upload(download_dir, name, _version)