def download(self, file_url: str, watcher: ProcessWatcher, output_path: str, cwd: str) -> bool: self.logger.info('Downloading {}'.format(file_url)) handler = ProcessHandler(watcher) file_name = file_url.split('/')[-1] final_cwd = cwd if cwd else '.' success = False ti = time.time() try: if self.is_multithreaded(): ti = time.time() process = self._get_aria2c_process(file_url, output_path, final_cwd) else: ti = time.time() process = self._get_wget_process(file_url, output_path, final_cwd) success = handler.handle(process) except: traceback.print_exc() self._rm_bad_file(file_name, output_path, final_cwd) tf = time.time() self.logger.info(file_name + ' download took {0:.2f} minutes'.format((tf - ti) / 60)) if not success: self.logger.error("Could not download '{}'".format(file_name)) self._rm_bad_file(file_name, output_path, final_cwd) return success
def run(self) -> bool: ti = time.time() self._log.info("Begin: packages synchronization") self._taskman.update_progress(self._id, 1, None) handler = ProcessHandler(self._watcher) updated, _ = handler.handle_simple(self._aptitude.update( self._root_password), output_handler=self._notify_output) self._taskman.update_progress(self._id, 99, None) if updated: index_timestamp = datetime.utcnow().timestamp() finish_msg = None try: with open(PACKAGE_SYNC_TIMESTAMP_FILE, 'w+') as f: f.write(str(index_timestamp)) except OSError: finish_msg = self._i18n['error'] self._log.error( f"Could not write the packages synchronization timestamp to file " f"'{PACKAGE_SYNC_TIMESTAMP_FILE}'") else: finish_msg = self._i18n['error'] self._taskman.update_progress(self._id, 100, finish_msg) self._taskman.finish_task(self._id) tf = time.time() self._log.info( f"Finish: packages synchronization ({tf - ti:.4f} seconds)") return updated
def downgrade(self, pkg: FlatpakApplication, root_password: str, watcher: ProcessWatcher) -> bool: handler = ProcessHandler(watcher) pkg.commit = flatpak.get_commit(pkg.id, pkg.branch, pkg.installation) watcher.change_progress(10) watcher.change_substatus(self.i18n['flatpak.downgrade.commits']) commits = flatpak.get_app_commits(pkg.ref, pkg.origin, pkg.installation, handler) if commits is None: return False commit_idx = commits.index(pkg.commit) # downgrade is not possible if the app current commit in the first one: if commit_idx == len(commits) - 1: watcher.show_message( self.i18n['flatpak.downgrade.impossible.title'], self.i18n['flatpak.downgrade.impossible.body'], MessageType.WARNING) return False commit = commits[commit_idx + 1] watcher.change_substatus(self.i18n['flatpak.downgrade.reverting']) watcher.change_progress(50) success = handler.handle( SystemProcess( subproc=flatpak.downgrade(pkg.ref, commit, pkg.installation, root_password), success_phrases=['Changes complete.', 'Updates complete.'], wrong_error_phrase='Warning')) watcher.change_progress(100) return success
def uninstall(self, pkg: AppImage, root_password: Optional[str], watcher: ProcessWatcher, disk_loader: DiskCacheLoader = None) -> TransactionResult: if os.path.exists(pkg.get_disk_cache_path()): handler = ProcessHandler(watcher) if not handler.handle(SystemProcess(new_subprocess(['rm', '-rf', pkg.get_disk_cache_path()]))): watcher.show_message(title=self.i18n['error'], body=self.i18n['appimage.uninstall.error.remove_folder'].format(bold(pkg.get_disk_cache_path()))) return TransactionResult.fail() de_path = self._gen_desktop_entry_path(pkg) if os.path.exists(de_path): os.remove(de_path) self.revert_ignored_update(pkg) if pkg.symlink and os.path.islink(pkg.symlink): self.logger.info(f"Removing symlink '{pkg.symlink}'") try: os.remove(pkg.symlink) self.logger.info(f"symlink '{pkg.symlink}' successfully removed") except: msg = f"could not remove symlink '{pkg.symlink}'" self.logger.error(msg) if watcher: watcher.print(f"[error] {msg}") self._add_self_latest_version(pkg) # only for self installation return TransactionResult(success=True, installed=None, removed=[pkg])
def run(self): self.taskman.register_task(self.task_id, self.i18n['arch.task.mirrors'], get_icon_path()) self.logger.info("Refreshing mirrors") handler = ProcessHandler() try: self.taskman.update_progress(self.task_id, 10, '') success, output = handler.handle_simple(pacman.refresh_mirrors(self.root_password), output_handler=self._notify_output) if success: if self.sort_limit is not None and self.sort_limit >= 0: self.taskman.update_progress(self.task_id, 50, self.i18n['arch.custom_action.refresh_mirrors.status.updating']) try: handler.handle_simple(pacman.sort_fastest_mirrors(self.root_password, self.sort_limit), output_handler=self._notify_output) except: self.logger.error("Could not sort mirrors by speed") traceback.print_exc() mirrors.register_sync(self.logger) else: self.logger.error("It was not possible to refresh mirrors") except: self.logger.error("It was not possible to refresh mirrors") traceback.print_exc() self.taskman.update_progress(self.task_id, 100, None) self.taskman.finish_task(self.task_id) self.logger.info("Finished")
def install(self, pkg: SnapApplication, root_password: str, watcher: ProcessWatcher) -> bool: res, output = ProcessHandler(watcher).handle_simple( snap.install_and_stream(pkg.name, pkg.confinement, root_password)) if 'error:' in output: res = False if 'not available on stable' in output: channels = RE_AVAILABLE_CHANNELS.findall(output) if channels: opts = [ InputOption(label=c[0], value=c[1]) for c in channels ] channel_select = SingleSelectComponent( type_=SelectViewType.RADIO, label='', options=opts, default_option=opts[0]) body = '<p>{}.</p>'.format( self.i18n['snap.install.available_channels.message']. format(bold(self.i18n['stable']), bold(pkg.name))) body += '<p>{}:</p>'.format( self.i18n['snap.install.available_channels.help']) if watcher.request_confirmation( title=self. i18n['snap.install.available_channels.title'], body=body, components=[channel_select], confirmation_label=self.i18n['continue'], deny_label=self.i18n['cancel']): self.logger.info( "Installing '{}' with the custom command '{}'". format(pkg.name, channel_select.value)) res = ProcessHandler(watcher).handle( SystemProcess( new_root_subprocess( channel_select.value.value.split(' '), root_password=root_password))) if res: pkg.has_apps_field = snap.has_apps_field( pkg.name, self.ubuntu_distro) return res else: self.logger.error( "Could not find available channels in the installation output: {}" .format(output)) else: pkg.has_apps_field = snap.has_apps_field(pkg.name, self.ubuntu_distro) return res
def upgrade(self, requirements: UpgradeRequirements, root_password: str, watcher: ProcessWatcher) -> bool: handler = ProcessHandler(watcher) targets = (r.pkg.name for r in (*requirements.to_upgrade, *(requirements.to_install or ()))) with self.output_handler.start(watcher=watcher, targets=targets, action=AptitudeAction.UPGRADE) as handle: to_upgrade = (r.pkg.name for r in requirements.to_upgrade) success, _ = handler.handle_simple(self.aptitude.upgrade(packages=to_upgrade, root_password=root_password), output_handler=handle) return success
def _generate_backup(self, app_config: dict, root_password: Optional[str]) -> bool: if app_config['backup']['mode'] not in ('only_one', 'incremental'): self.show_message(title=self.i18n['error'].capitalize(), body='{}: {}'.format(self.i18n['action.backup.invalid_mode'],bold(app_config['backup']['mode'])), type_=MessageType.ERROR) self.change_substatus('') return False handler = ProcessHandler(self) if app_config['backup']['mode'] == 'only_one': remove_method = app_config['backup']['remove_method'] if remove_method not in BACKUP_REMOVE_METHODS: remove_method = BACKUP_DEFAULT_REMOVE_METHOD delete_failed = False if remove_method == 'self': previous_snapshots = tuple(timeshift.read_created_snapshots(root_password)) if previous_snapshots: substatus = f"[{self.i18n['core.config.tab.backup'].lower()}] {self.i18n['action.backup.substatus.delete']}" self.change_substatus(substatus) for snapshot in reversed(previous_snapshots): deleted, _ = handler.handle_simple(timeshift.delete(snapshot, root_password)) if not deleted: delete_failed = True else: deleted, _ = handler.handle_simple(timeshift.delete_all_snapshots(root_password)) delete_failed = not deleted if delete_failed and not self.request_confirmation(title=self.i18n['core.config.tab.backup'], body=f"{self.i18n['action.backup.error.delete']}. " f"{self.i18n['action.backup.error.proceed']}", confirmation_label=self.i18n['yes'].capitalize(), deny_label=self.i18n['no'].capitalize()): self.change_substatus('') return False self.change_substatus('[{}] {}'.format(self.i18n['core.config.tab.backup'].lower(), self.i18n['action.backup.substatus.create'])) created, _ = handler.handle_simple(timeshift.create_snapshot(root_password, app_config['backup']['type'])) if not created and not self.request_confirmation(title=self.i18n['core.config.tab.backup'], body='{}. {}'.format(self.i18n['action.backup.error.create'], self.i18n['action.backup.error.proceed']), confirmation_label=self.i18n['yes'].capitalize(), deny_label=self.i18n['no'].capitalize()): self.change_substatus('') return False self.change_substatus('') return True
def download(self, file_url: str, watcher: ProcessWatcher, output_path: str, cwd: str) -> bool: self.logger.info('Downloading {}'.format(file_url)) handler = ProcessHandler(watcher) file_name = file_url.split('/')[-1] final_cwd = cwd if cwd else '.' success = False ti = time.time() try: if output_path and os.path.exists(output_path): self.logger.info( 'Removing old file found before downloading: {}'.format( output_path)) os.remove(output_path) self.logger.info("Old file {} removed".format(output_path)) if self.is_multithreaded(): ti = time.time() process = self._get_aria2c_process(file_url, output_path, final_cwd) downloader = 'aria2c' else: ti = time.time() process = self._get_wget_process(file_url, output_path, final_cwd) downloader = 'wget' file_size = self.http_client.get_content_length(file_url) msg = bold('[{}] ').format( downloader) + self.i18n['downloading'] + ' ' + bold( file_url.split('/')[-1]) + (' ( {} )'.format(file_size) if file_size else '') watcher.change_substatus(msg) if isinstance(process, SimpleProcess): success = handler.handle_simple(process) else: success = handler.handle(process) except: traceback.print_exc() self._rm_bad_file(file_name, output_path, final_cwd) tf = time.time() self.logger.info(file_name + ' download took {0:.2f} minutes'.format((tf - ti) / 60)) if not success: self.logger.error("Could not download '{}'".format(file_name)) self._rm_bad_file(file_name, output_path, final_cwd) return success
def _generate_backup(self, app_config: dict, i18n: I18n, root_password: str) -> bool: if timeshift.is_available(): if app_config['backup']['mode'] not in ('only_one', 'incremental'): self.show_message(title=self.i18n['error'].capitalize(), body='{}: {}'.format( self.i18n['action.backup.invalid_mode'], bold(app_config['backup']['mode'])), type_=MessageType.ERROR) return False if not user.is_root() and not root_password: root_pwd, valid = self.request_root_password() else: root_pwd, valid = root_password, True if not valid: return False handler = ProcessHandler(self) if app_config['backup']['mode'] == 'only_one': self.change_substatus('[{}] {}'.format( i18n['core.config.tab.backup'].lower(), i18n['action.backup.substatus.delete'])) deleted, _ = handler.handle_simple( timeshift.delete_all_snapshots(root_pwd)) if not deleted and not self.request_confirmation( title=i18n['core.config.tab.backup'], body='{}. {}'.format( i18n['action.backup.error.delete'], i18n['action.backup.error.proceed']), confirmation_label=i18n['yes'].capitalize(), deny_label=i18n['no'].capitalize()): return False self.change_substatus('[{}] {}'.format( i18n['core.config.tab.backup'].lower(), i18n['action.backup.substatus.create'])) created, _ = handler.handle_simple( timeshift.create_snapshot(root_pwd, app_config['backup']['type'])) if not created and not self.request_confirmation( title=i18n['core.config.tab.backup'], body='{}. {}'.format(i18n['action.backup.error.create'], i18n['action.backup.error.proceed']), confirmation_label=i18n['yes'].capitalize(), deny_label=i18n['no'].capitalize()): return False return True
def _import_pgp_keys(self, pkgname: str, root_password: str, handler: ProcessHandler): srcinfo = self.aur_client.get_src_info(pkgname) if srcinfo.get('validpgpkeys'): handler.watcher.print(self.i18n['arch.aur.install.verifying_pgp']) keys_to_download = [ key for key in srcinfo['validpgpkeys'] if not pacman.verify_pgp_key(key) ] if keys_to_download: keys_str = ''.join([ '<br/><span style="font-weight:bold"> - {}</span>'.format( k) for k in keys_to_download ]) msg_body = '{}:<br/>{}<br/><br/>{}'.format( self.i18n['arch.aur.install.pgp.body'].format( bold(pkgname)), keys_str, self.i18n['ask.continue']) if handler.watcher.request_confirmation( title=self.i18n['arch.aur.install.pgp.title'], body=msg_body): for key in keys_to_download: handler.watcher.change_substatus( self.i18n['arch.aur.install.pgp.substatus'].format( bold(key))) if not handler.handle( pacman.receive_key(key, root_password)): handler.watcher.show_message( title=self.i18n['error'], body=self. i18n['arch.aur.install.pgp.receive_fail']. format(bold(key)), type_=MessageType.ERROR) return False if not handler.handle( pacman.sign_key(key, root_password)): handler.watcher.show_message( title=self.i18n['error'], body=self. i18n['arch.aur.install.pgp.sign_fail'].format( bold(key)), type_=MessageType.ERROR) return False handler.watcher.change_substatus( self.i18n['arch.aur.install.pgp.success']) else: handler.watcher.print(self.i18n['action.cancelled']) return False
def uninstall(self, pkg: AppImage, root_password: str, watcher: ProcessWatcher) -> bool: if os.path.exists(pkg.get_disk_cache_path()): handler = ProcessHandler(watcher) if not handler.handle(SystemProcess(new_subprocess(['rm', '-rf', pkg.get_disk_cache_path()]))): watcher.show_message(title=self.i18n['error'], body=self.i18n['appimage.uninstall.error.remove_folder'].format(bold(pkg.get_disk_cache_path()))) return False de_path = self._gen_desktop_entry_path(pkg) if os.path.exists(de_path): os.remove(de_path) return True
def install(self, pkg: FlatpakApplication, root_password: str, watcher: ProcessWatcher) -> bool: config = read_config() install_level = config['installation_level'] if install_level is not None: self.logger.info("Default Flaptak installation level defined: {}".format(install_level)) if install_level not in ('user', 'system'): watcher.show_message(title=self.i18n['error'].capitalize(), body=self.i18n['flatpak.install.bad_install_level.body'].format(field=bold('installation_level'), file=bold(CONFIG_FILE)), type_=MessageType.ERROR) return False pkg.installation = install_level else: user_level = watcher.request_confirmation(title=self.i18n['flatpak.install.install_level.title'], body=self.i18n['flatpak.install.install_level.body'].format(bold(pkg.name)), confirmation_label=self.i18n['no'].capitalize(), deny_label=self.i18n['yes'].capitalize()) pkg.installation = 'user' if user_level else 'system' remotes = flatpak.list_remotes() handler = ProcessHandler(watcher) if pkg.installation == 'user' and not remotes['user']: handler.handle_simple(flatpak.set_default_remotes('user')) elif pkg.installation == 'system' and not remotes['system']: if user.is_root(): handler.handle_simple(flatpak.set_default_remotes('system')) else: user_password, valid = watcher.request_root_password() if not valid: watcher.print('Operation aborted') return False else: if not handler.handle_simple(flatpak.set_default_remotes('system', user_password)): watcher.show_message(title=self.i18n['error'].capitalize(), body=self.i18n['flatpak.remotes.system_flathub.error'], type_=MessageType.ERROR) watcher.print("Operation cancelled") return False res = handler.handle(SystemProcess(subproc=flatpak.install(str(pkg.id), pkg.origin, pkg.installation), wrong_error_phrase='Warning')) if res: try: fields = flatpak.get_fields(str(pkg.id), pkg.branch, ['Ref', 'Branch']) if fields: pkg.ref = fields[0] pkg.branch = fields[1] except: traceback.print_exc() return res
def map_update_download_size(app_ids: Iterable[str], installation: str, version: str) -> Dict[str, int]: success, output = ProcessHandler().handle_simple( SimpleProcess(['flatpak', 'update', '--{}'.format(installation)])) if version >= '1.5': res = {} p = re.compile(r'^\d+.\t') p2 = re.compile(r'\s([0-9.?a-zA-Z]+)\s?') for l in output.split('\n'): if l: line = l.strip() if line: found = p.match(line) if found: line_split = line.split('\t') line_id = line_split[2].strip() related_id = [ appid for appid in app_ids if appid == line_id ] if related_id: size = p2.findall(line_split[6])[0].split('?') res[related_id[0].strip()] = size_to_byte( float(size[0]), size[1]) return res
def change_channel(self, pkg: SnapApplication, root_password: str, watcher: ProcessWatcher) -> bool: if not internet.is_available(): raise NoInternetException() try: channel = self._request_channel_installation( pkg=pkg, snap_config=None, snapd_client=SnapdClient(self.logger), watcher=watcher, exclude_current=True) if not channel: watcher.show_message( title=self.i18n['snap.action.channel.label'], body=self.i18n['snap.action.channel.error.no_channel']) return False return ProcessHandler(watcher).handle_simple( snap.refresh_and_stream(app_name=pkg.name, root_password=root_password, channel=channel))[0] except: return False
def upgrade(self, requirements: UpgradeRequirements, root_password: str, watcher: ProcessWatcher) -> bool: flatpak_version = flatpak.get_version() for req in requirements.to_upgrade: watcher.change_status("{} {} ({})...".format(self.i18n['manage_window.status.upgrading'], req.pkg.name, req.pkg.version)) related, deps = False, False ref = req.pkg.ref if req.pkg.partial and flatpak_version < '1.5': related, deps = True, True ref = req.pkg.base_ref try: res = ProcessHandler(watcher).handle(SystemProcess(subproc=flatpak.update(app_ref=ref, installation=req.pkg.installation, related=related, deps=deps))) watcher.change_substatus('') if not res: self.logger.warning("Could not upgrade '{}'".format(req.pkg.id)) return False except: watcher.change_substatus('') self.logger.error("An error occurred while upgrading '{}'".format(req.pkg.id)) traceback.print_exc() return False watcher.change_substatus('') return True
def check(project_dir: str, optimize: bool, missing_deps: bool, handler: ProcessHandler, custom_pkgbuild: Optional[str] = None, custom_user: Optional[str] = None) -> dict: res = {} cmd = ['makepkg', '-ALcfm', '--check', '--noarchive', '--nobuild', '--noprepare'] if not missing_deps: cmd.append('--nodeps') if custom_pkgbuild: cmd.append('-p') cmd.append(custom_pkgbuild) if optimize: if os.path.exists(CUSTOM_MAKEPKG_FILE): handler.watcher.print(f'Using custom makepkg.conf -> {CUSTOM_MAKEPKG_FILE}') cmd.append(f'--config={CUSTOM_MAKEPKG_FILE}') else: handler.watcher.print(f'Custom optimized makepkg.conf ({CUSTOM_MAKEPKG_FILE}) not found') success, output = handler.handle_simple(SimpleProcess(cmd, cwd=project_dir, shell=True, custom_user=custom_user)) if missing_deps and 'Missing dependencies' in output: res['missing_deps'] = RE_DEPS_PATTERN.findall(output) gpg_keys = RE_UNKNOWN_GPG_KEY.findall(output) if gpg_keys: res['gpg_key'] = gpg_keys[0] if 'One or more files did not pass the validity check' in output: res['validity_check'] = True return res
def install(self, pkg: ArchPackage, root_password: str, watcher: ProcessWatcher, skip_optdeps: bool = False) -> bool: clean_config = False if not self.local_config: self.local_config = read_config() clean_config = True if self.local_config['optimize'] and not os.path.exists( CUSTOM_MAKEPKG_FILE): watcher.change_substatus(self.i18n['arch.makepkg.optimizing']) ArchCompilationOptimizer(self.context.logger).optimize() res = self._install_from_aur(pkg.name, pkg.maintainer, root_password, ProcessHandler(watcher), dependency=False, skip_optdeps=skip_optdeps) if res: if os.path.exists(pkg.get_disk_data_path()): with open(pkg.get_disk_data_path()) as f: data = f.read() if data: data = json.loads(data) pkg.fill_cached_data(data) if clean_config: self.local_config = None return res
def downgrade(self, pkg: FlatpakApplication, root_password: str, watcher: ProcessWatcher) -> bool: if not self._make_exports_dir(watcher): return False watcher.change_progress(10) watcher.change_substatus(self.i18n['flatpak.downgrade.commits']) history = self.get_history(pkg, full_commit_str=True) # downgrade is not possible if the app current commit in the first one: if history.pkg_status_idx == len(history.history) - 1: watcher.show_message( self.i18n['flatpak.downgrade.impossible.title'], self.i18n['flatpak.downgrade.impossible.body'].format( bold(pkg.name)), MessageType.ERROR) return False commit = history.history[history.pkg_status_idx + 1]['commit'] watcher.change_substatus(self.i18n['flatpak.downgrade.reverting']) watcher.change_progress(50) success, _ = ProcessHandler(watcher).handle_simple( flatpak.downgrade(pkg.ref, commit, pkg.installation, root_password)) watcher.change_progress(100) return success
def uninstall(self, pkg: FlatpakApplication, root_password: str, watcher: ProcessWatcher) -> bool: uninstalled = ProcessHandler(watcher).handle(SystemProcess(subproc=flatpak.uninstall(pkg.ref))) if self.suggestions_cache: self.suggestions_cache.delete(pkg.id) return uninstalled
def request_reboot(self, msg: str) -> bool: if self.request_confirmation(title=self.i18n['action.request_reboot.title'], body=msg, confirmation_label=self.i18n['yes'].capitalize(), deny_label=self.i18n['bt.not_now']): ProcessHandler(self).handle_simple(SimpleProcess(['reboot'])) return True return False
def get_dependencies_to_remove(pkgs: Iterable[str], root_password: str) -> Dict[str, str]: proc = SimpleProcess(cmd=['pacman', '-R', *pkgs, '--confirm'], root_password=root_password) success, output = ProcessHandler().handle_simple(proc) if not output: return {} return {t[1]: t[0] for t in RE_REMOVE_TRANSITIVE_DEPS.findall(output)}
def _trim_disk(self, root_password: Optional[str]): self.change_status('{}...'.format(self.i18n['action.disk_trim'].capitalize())) self.change_substatus('') success, output = ProcessHandler(self).handle_simple(SimpleProcess(['fstrim', '/', '-v'], root_password=root_password)) if not success: self.show_message(title=self.i18n['success'].capitalize(), body=self.i18n['action.disk_trim.error'], type_=MessageType.ERROR)
def get_app_commits(app_ref: str, origin: str, installation: str, handler: ProcessHandler) -> List[str]: try: p = SimpleProcess(['flatpak', 'remote-info', '--log', origin, app_ref, '--{}'.format(installation)]) success, output = handler.handle_simple(p) if output.startswith('error:'): return else: return re.findall(r'Commit+:\s(.+)', output) except: raise NoInternetException()
def uninstall(self, pkg: SnapApplication, root_password: str, watcher: ProcessWatcher) -> bool: uninstalled = ProcessHandler(watcher).handle( SystemProcess( subproc=snap.uninstall_and_stream(pkg.name, root_password))) if self.suggestions_cache: self.suggestions_cache.delete(pkg.name) return uninstalled
def _rm_bad_file(self, file_name: str, output_path: str, cwd, handler: ProcessHandler, root_password: Optional[str]): to_delete = output_path if output_path else f'{cwd}/{file_name}' if to_delete and os.path.exists(to_delete): self.logger.info(f'Removing downloaded file {to_delete}') success, _ = handler.handle_simple( SimpleProcess(['rm', '-rf', to_delete], root_password=root_password)) return success
def upgrade(self, requirements: UpgradeRequirements, root_password: Optional[str], watcher: ProcessWatcher) -> bool: flatpak_version = flatpak.get_version() if not self._make_exports_dir(watcher): return False for req in requirements.to_upgrade: watcher.change_status("{} {} ({})...".format(self.i18n['manage_window.status.upgrading'], req.pkg.name, req.pkg.version)) related, deps = False, False ref = req.pkg.ref if req.pkg.partial and flatpak_version < VERSION_1_5: related, deps = True, True ref = req.pkg.base_ref try: if req.pkg.update_component: self.logger.info(f"Installing {req.pkg}") res, _ = ProcessHandler(watcher).handle_simple(flatpak.install(app_id=ref, installation=req.pkg.installation, origin=req.pkg.origin, version=flatpak_version)) else: self.logger.info(f"Updating {req.pkg}") res, _ = ProcessHandler(watcher).handle_simple(flatpak.update(app_ref=ref, installation=req.pkg.installation, related=related, deps=deps, version=flatpak_version)) watcher.change_substatus('') if not res: self.logger.warning("Could not upgrade '{}'".format(req.pkg.id)) return False except: watcher.change_substatus('') self.logger.error("An error occurred while upgrading '{}'".format(req.pkg.id)) traceback.print_exc() return False watcher.change_substatus('') return True
def downgrade(self, pkg: SnapApplication, root_password: str, watcher: ProcessWatcher) -> bool: if not snap.is_installed(): watcher.print("'snap' seems not to be installed") return False if not snapd.is_running(): watcher.print("'snapd' seems not to be running") return False return ProcessHandler(watcher).handle_simple( snap.downgrade_and_stream(pkg.name, root_password))[0]
def _rm_bad_file(self, file_name: str, output_path: str, cwd, handler: ProcessHandler, root_password: str): to_delete = output_path if output_path else '{}/{}'.format( cwd, file_name) if to_delete and os.path.exists(to_delete): self.logger.info('Removing downloaded file {}'.format(to_delete)) success, _ = handler.handle_simple( SimpleProcess(['rm', '-rf', to_delete], root_password=root_password)) return success
def _get_search_remote(self) -> str: remotes = flatpak.list_remotes() if remotes['system']: remote_level = 'system' elif remotes['user']: remote_level = 'user' else: remote_level = 'user' ProcessHandler().handle_simple(flatpak.set_default_remotes(remote_level)) return remote_level