def _start_category_task(self, task_man: TaskManager): if task_man: task_man.register_task( 'snap_cats', self.i18n['task.download_categories'].format('Snap'), get_icon_path()) task_man.update_progress('snap_cats', 50, None)
def prepare(self, task_manager: TaskManager, root_password: Optional[str], internet_available: bool): create_config = CreateConfigFile(taskman=task_manager, configman=self.configman, i18n=self.i18n, task_icon_path=get_icon_path(), logger=self.logger) create_config.start() task_manager.register_task('snap_cats', self.i18n['task.download_categories'], get_icon_path()) category_downloader = CategoriesDownloader( id_='snap', manager=self, http_client=self.http_client, logger=self.logger, url_categories_file=URL_CATEGORIES_FILE, categories_path=CATEGORIES_FILE_PATH, internet_connection=internet_available, internet_checker=self.context.internet_checker, after=lambda: self._finish_category_task(task_manager)) category_downloader.before = lambda: self._start_category_task( task_manager, create_config, category_downloader) category_downloader.start()
def read_settings(self, task_man: TaskManager = None) -> dict: try: if task_man: task_man.register_task('web_down_sets', self.i18n['web.task.download_settings'], get_icon_path()) task_man.update_progress('web_down_sets', 10, None) res = self.http_client.get(URL_ENVIRONMENT_SETTINGS) if not res: self.logger.warning( 'Could not retrieve the environments settings from the cloud' ) self._finish_task_download_settings(task_man) return try: self._finish_task_download_settings(task_man) return yaml.safe_load(res.content) except yaml.YAMLError: self.logger.error( 'Could not parse environment settings: {}'.format( res.text)) self._finish_task_download_settings(task_man) return except requests.exceptions.ConnectionError: self._finish_task_download_settings(task_man) return
def _start_category_task(self, taskman: TaskManager, create_config: CreateConfigFile, downloader: CategoriesDownloader): if taskman: taskman.update_progress( 'snap_cats', 0, self.i18n['task.waiting_task'].format( bold(create_config.task_name))) create_config.join() categories_exp = create_config.config['categories_exp'] downloader.expiration = categories_exp if isinstance( categories_exp, int) else None taskman.update_progress('snap_cats', 1, None)
def prepare(self, task_manager: TaskManager, root_password: str, internet_available: bool): ti = time.time() self.logger.info("Initializing") taskman = task_manager if task_manager else TaskManager( ) # empty task manager to prevent null pointers create_config = CreateConfigFile( taskman=taskman, configman=self.configman, i18n=self.i18n, task_icon_path=get_path('img/logo.svg'), logger=self.logger) create_config.start() if self.managers: internet_on = self.context.is_internet_available() prepare_tasks = [] for man in self.managers: if man not in self._already_prepared and self._can_work(man): t = Thread(target=man.prepare, args=(taskman, root_password, internet_on), daemon=True) t.start() prepare_tasks.append(t) self._already_prepared.append(man) for t in prepare_tasks: t.join() tf = time.time() self.logger.info("Finished. Took {0:.2f} seconds".format(tf - ti))
def prepare(self, task_manager: TaskManager, root_password: str, internet_available: bool): if self.managers: internet_on = internet.is_available() taskman = task_manager if task_manager else TaskManager( ) # empty task manager to prevent null pointers for man in self.managers: if man not in self._already_prepared and self._can_work(man): man.prepare(taskman, root_password, internet_on) self._already_prepared.append(man)
def prepare(self, task_manager: TaskManager, root_password: str, internet_available: bool): task_id = 'flatpak' task_manager.register_task(task_id, self.i18n['flatpak.task.read_config'], get_icon_path()) task_manager.update_progress(task_id, 10, None) Thread(target=read_config, args=(True, ), daemon=True).start() task_manager.update_progress(task_id, 100, None) task_manager.finish_task(task_id)
def update_database(self, root_password: str, watcher: ProcessWatcher) -> bool: db_updater = DatabaseUpdater(i18n=self.i18n, http_client=self.context.http_client, logger=self.context.logger, watcher=watcher, taskman=TaskManager()) res = db_updater.download_databases() return res
def suggestions_downloader(self) -> AppImageSuggestionsDownloader: if not self._suggestions_downloader: file_url = self.context.get_suggestion_url(self.__module__) self._suggestions_downloader = AppImageSuggestionsDownloader(taskman=TaskManager(), i18n=self.context.i18n, http_client=self.context.http_client, logger=self.context.logger, file_url=file_url) if self._suggestions_downloader.is_custom_local_file_mapped(): self.logger.info(f"Local AppImage suggestions file mapped: {file_url}") return self._suggestions_downloader
def list_suggestions(self, limit: int, filter_installed: bool) -> Optional[List[PackageSuggestion]]: if limit == 0: return connection = self._get_db_connection(DATABASE_APPS_FILE) if connection: self.suggestions_downloader.taskman = TaskManager() suggestions = tuple(self.suggestions_downloader.read()) if not suggestions: self.logger.warning("Could not read AppImage suggestions") return else: self.logger.info("Mapping AppImage suggestions") try: if filter_installed: installed = {i.name.lower() for i in self.read_installed(disk_loader=None, connection=connection).installed} else: installed = None sugs_map = {} for s in suggestions: lsplit = s.split('=') name = lsplit[1].strip() if limit < 0 or len(sugs_map) < limit: if not installed or not name.lower() in installed: sugs_map[name] = SuggestionPriority(int(lsplit[0])) else: break cursor = connection.cursor() cursor.execute(query.FIND_APPS_BY_NAME_FULL.format(','.join([f"'{s}'" for s in sugs_map.keys()]))) res = [] for t in cursor.fetchall(): app = AppImage(*t, i18n=self.i18n) res.append(PackageSuggestion(app, sugs_map[app.name.lower()])) self.logger.info(f"Mapped {len(res)} AppImage suggestions") return res except: traceback.print_exc() finally: connection.close()
def index_apps(self, root_password: Optional[str], watcher: Optional[ProcessWatcher], taskman: Optional[TaskManager] = None, deb_config: Optional[dict] = None, check_expiration: bool = False) -> bool: _config = deb_config if deb_config else self.configman.get_config() _taskman = taskman if taskman else TaskManager() map_apps = MapApplications(taskman=_taskman, app_indexer=self.app_indexer, i18n=self._i18n, logger=self._log, deb_config=deb_config, app_mapper=self.app_mapper, check_expiration=check_expiration, watcher=watcher) map_apps.start() gen_app_index = UpdateApplicationIndex(taskman=_taskman, app_indexer=self.app_indexer, i18n=self._i18n, logger=self._log, mapping_apps=map_apps) gen_app_index.start() map_apps.join() self._update_apps_index(map_apps.apps) gen_app_index.join() return True
def synchronize_packages(self, root_password: Optional[str], watcher: ProcessWatcher) -> bool: return SynchronizePackages(i18n=self._i18n, logger=self._log, root_password=root_password, watcher=watcher, aptitude=self.aptitude, taskman=TaskManager()).run()
def taskman(self) -> TaskManager: if self._taskman is None: self._taskman = TaskManager() return self._taskman
def list_suggestions(self, limit: int, filter_installed: bool) -> List[PackageSuggestion]: res = [] connection = self._get_db_connection(DATABASE_APPS_FILE) if connection: suggestions = AppImageSuggestionsDownloader( appimage_config=self.configman.get_config(), logger=self.logger, i18n=self.i18n, http_client=self.http_client, taskman=TaskManager()).read() if not suggestions: self.logger.warning("Could not read suggestions") return res else: self.logger.info("Mapping suggestions") try: if filter_installed: installed = { i.name.lower() for i in self.read_installed( disk_loader=None, connection=connection).installed } else: installed = None sugs_map = {} for s in suggestions: lsplit = s.split('=') name = lsplit[1].strip() if limit <= 0 or len(sugs_map) < limit: if not installed or not name.lower() in installed: sugs_map[name] = SuggestionPriority( int(lsplit[0])) else: break cursor = connection.cursor() cursor.execute( query.FIND_APPS_BY_NAME_FULL.format(','.join( ["'{}'".format(s) for s in sugs_map.keys()]))) for t in cursor.fetchall(): app = AppImage(*t, i18n=self.i18n, custom_actions=self.custom_app_actions) res.append( PackageSuggestion(app, sugs_map[app.name.lower()])) self.logger.info("Mapped {} suggestions".format(len(res))) except: traceback.print_exc() finally: connection.close() return res
def _finish_category_task(self, task_man: TaskManager): if task_man: task_man.update_progress('snap_cats', 100, None) task_man.finish_task('snap_cats')
def _finish_task_download_settings(self, task_man: TaskManager): if task_man: task_man.update_progress('web_down_sets', 100, None) task_man.finish_task('web_down_sets')