def prepare(self, task_manager: TaskManager, root_password: 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() symlink_check = SymlinksVerifier(taskman=task_manager, i18n=self.i18n, logger=self.logger) symlink_check.start() if internet_available: DatabaseUpdater(taskman=task_manager, i18n=self.context.i18n, create_config=create_config, http_client=self.context.http_client, logger=self.context.logger).start() AppImageSuggestionsDownloader(taskman=task_manager, i18n=self.context.i18n, http_client=self.context.http_client, logger=self.context.logger, create_config=create_config).start()
def __init__(self, taskman: TaskManager, i18n: I18n, logger: logging.Logger): super(SymlinksVerifier, self).__init__(daemon=True) self.taskman = taskman self.i18n = i18n self.logger = logger self.task_id = 'appim_symlink_check' self.taskman.register_task(self.task_id, self.i18n['appimage.task.symlink_check'], get_icon_path())
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() symlink_check = SymlinksVerifier(taskman=task_manager, i18n=self.i18n, logger=self.logger) symlink_check.start() if internet_available: DatabaseUpdater(taskman=task_manager, i18n=self.context.i18n, create_config=create_config, http_client=self.context.http_client, logger=self.context.logger).start() if not self.suggestions_downloader.is_custom_local_file_mapped(): self.suggestions_downloader.taskman = task_manager self.suggestions_downloader.create_config = create_config self.suggestions_downloader.register_task() self.suggestions_downloader.start()
def __init__(self, logger: logging.Logger, http_client: HttpClient, i18n: I18n, taskman: TaskManager, create_config: Optional[CreateConfigFile] = None, appimage_config: Optional[dict] = None): super(AppImageSuggestionsDownloader, self).__init__(daemon=True) self.create_config = create_config self.logger = logger self.i18n = i18n self.http_client = http_client self.taskman = taskman self.config = appimage_config self.task_id = 'appim.suggestions' self.taskman.register_task(id_=self.task_id, label=i18n['appimage.task.suggestions'], icon_path=get_icon_path())
def __init__(self, i18n: I18n, http_client: HttpClient, logger: logging.Logger, taskman: TaskManager, watcher: Optional[ProcessWatcher] = None, appimage_config: Optional[dict] = None, create_config: Optional[CreateConfigFile] = None): super(DatabaseUpdater, self).__init__(daemon=True) self.http_client = http_client self.logger = logger self.i18n = i18n self.taskman = taskman self.watcher = watcher self.task_id = 'appim_db' self.config = appimage_config self.create_config = create_config self.taskman.register_task(self.task_id, self.i18n['appimage.task.db_update'], get_icon_path())
def download_databases(self): if self.task_man: self.task_man.register_task(self.task_id, self.i18n['appimage.task.db_update'], get_icon_path()) self.task_man.update_progress(self.task_id, 10, None) try: if not internet.is_available(): self._finish_task() return except requests.exceptions.ConnectionError: self.logger.warning('The internet connection seems to be off.') self._finish_task() return self.logger.info('Retrieving AppImage databases') try: res = self.http_client.get(self.URL_DB, session=False) except Exception as e: self.logger.error( "An error ocurred while downloading the AppImage database: {}". format(e.__class__.__name__)) res = None if res: Path(LOCAL_PATH).mkdir(parents=True, exist_ok=True) with open(self.COMPRESS_FILE_PATH, 'wb+') as f: f.write(res.content) self.logger.info("Database file saved at {}".format( self.COMPRESS_FILE_PATH)) old_db_files = glob.glob(LOCAL_PATH + '/*.db') if old_db_files: self.logger.info('Deleting old database files') for f in old_db_files: self.db_locks[f].acquire() try: os.remove(f) finally: self.db_locks[f].release() self.logger.info('Old database files deleted') self.logger.info('Uncompressing {}'.format( self.COMPRESS_FILE_PATH)) try: tf = tarfile.open(self.COMPRESS_FILE_PATH) tf.extractall(LOCAL_PATH) self.logger.info('Successfully uncompressed file {}'.format( self.COMPRESS_FILE_PATH)) except: self.logger.error('Could not extract file {}'.format( self.COMPRESS_FILE_PATH)) traceback.print_exc() finally: self.logger.info('Deleting {}'.format(self.COMPRESS_FILE_PATH)) os.remove(self.COMPRESS_FILE_PATH) self.logger.info('Successfully removed {}'.format( self.COMPRESS_FILE_PATH)) self._finish_task() else: self.logger.warning( 'Could not download the database file {}'.format(self.URL_DB)) self._finish_task()
def run(self): self.taskman.register_task(self.task_id, self.i18n['appimage.task.symlink_check'], get_icon_path()) if os.path.exists(INSTALLATION_PATH): installed_files = glob.glob('{}/*/*.json'.format(INSTALLATION_PATH)) if installed_files: self.logger.info("Checking installed AppImage files with no symlinks created") progress_per_file = (1/len(installed_files)) * 100 total_progress = 0 for json_file in installed_files: with open(json_file) as f: try: data = json.loads(f.read()) except: self.logger.warning("Could not parse data from '{}'".format(json_file)) data = None if data and not data.get('symlink'): if not data.get('install_dir'): data['install_dir'] = '/'.join(json_file.split('/')[0:-1]) app = AppImage(**data, i18n=self.i18n) file_path = util.find_appimage_file(app.install_dir) if file_path: self.create_symlink(app, file_path, self.logger) data['symlink'] = app.symlink # caching try: with open(json_file, 'w+') as f: f.write(json.dumps(data)) except: self.logger.warning("Could not update cached data on '{}'".format(json_file)) traceback.print_exc() else: self.logger.warning("No AppImage file found on installation dir '{}'".format(file_path)) total_progress += progress_per_file self.taskman.update_progress(self.task_id, total_progress, '') self.taskman.update_progress(self.task_id, 100, '') self.taskman.finish_task(self.task_id) return self.logger.info("No AppImage applications found. Aborting") self.taskman.update_progress(self.task_id, 100, '') self.taskman.finish_task(self.task_id)
def register_task(self): self.taskman.register_task(id_=self.task_id, label=self.i18n['task.download_suggestions'], icon_path=get_icon_path())