def _find_remote_ref_from_list(fp_sys, remote_name, basic_ref, nofail=False): remote_ref = None all_refs = fp_sys.list_remote_refs_sync(remote_name, None) ref_str = basic_ref.format_ref() for ref in all_refs: if ref_str == ref.format_ref(): remote_ref = ref break if remote_ref == None: try: remote_ref = fp_sys.fetch_remote_ref_sync(remote_name, basic_ref.get_kind(), basic_ref.get_name(), basic_ref.get_arch(), basic_ref.get_branch(), None) except GLib.Error as e: if nofail: remote_ref = Flatpak.RemoteRef( remote_name=remote_name, kind=basic_ref.get_kind(), arch=basic_ref.get_arch(), branch=basic_ref.get_branch(), name=basic_ref.get_name(), commit=basic_ref.get_commit(), collection_id=basic_ref.get_collection_id()) return remote_ref
def _pick_refs_for_installation(task): fp_sys = get_fp_sys() pkginfo = task.pkginfo refid = pkginfo.refid ref = Flatpak.Ref.parse(refid) remote_name = pkginfo.remote try: remote_ref = Flatpak.RemoteRef(remote_name=remote_name, kind=ref.get_kind(), arch=ref.get_arch(), branch=ref.get_branch(), name=ref.get_name(), commit=ref.get_commit(), collection_id=ref.get_collection_id()) _add_ref_to_task(fp_sys, task, remote_ref) update_list = fp_sys.list_installed_refs_for_update(None) runtime_ref = _get_runtime_ref(fp_sys, remote_name, remote_ref) if not _is_ref_installed(fp_sys, runtime_ref): _add_ref_to_task(fp_sys, task, runtime_ref) else: if runtime_ref in update_list: _add_ref_to_task(fp_sys, task, runtime_ref, needs_update=True) all_related_refs = _get_remote_related_refs(fp_sys, remote_ref.get_remote_name(), remote_ref) all_related_refs += _get_remote_related_refs(fp_sys, runtime_ref.get_remote_name(), runtime_ref) all_related_refs += _get_theme_refs(fp_sys, runtime_ref.get_remote_name(), runtime_ref) for related_ref in all_related_refs: if not _is_ref_installed(fp_sys, related_ref): _add_ref_to_task(fp_sys, task, related_ref) else: if related_ref in update_list: _add_ref_to_task(fp_sys, task, related_ref, needs_update=True) except Exception as e: # Something went wrong, bail out task.info_ready_status = task.STATUS_BROKEN task.error_message = str(e) dialogs.show_flatpak_error(task.error_message) if task.info_ready_callback: GObject.idle_add(task.info_ready_callback, task) return print("For installation:") for ref in task.to_install: print(ref.format_ref()) task.info_ready_status = task.STATUS_OK task.execute = execute_transaction if task.info_ready_callback: GObject.idle_add(task.info_ready_callback, task)
def _pkginfo_from_file_thread(cache, file, callback): fp_sys = get_fp_sys() path = file.get_path() if path == None: print("Installer: flatpak - no valid .flatpakref path provided") return None ref = None pkginfo = None remote_name = None with open(path) as f: contents = f.read() b = contents.encode("utf-8") gb = GLib.Bytes(b) try: kf = GLib.KeyFile() if kf.load_from_file(path, GLib.KeyFileFlags.NONE): name = kf.get_string("Flatpak Ref", "Name") url = kf.get_string("Flatpak Ref", "Url") try: branch = kf.get_string("Flatpak Ref", "Branch") except GLib.Error as e: if e.code == GLib.KeyFileError.KEY_NOT_FOUND: print( "Installer: flatpak - flatpakref file doesn't have a Branch key, maybe nightly or testing." ) branch = None remote_name = _get_remote_name_by_url(fp_sys, url) if name and remote_name: ref = Flatpak.RemoteRef(remote_name=remote_name, kind=Flatpak.RefKind.APP, arch=Flatpak.get_default_arch(), branch=branch, name=name) print( "Installer: flatpak - using existing remote '%s' for flatpakref file install" % remote_name) else: #If Flatpakref is not installed already try: print( "Installer: flatpak - trying to install new remote for flatpakref file" ) ref = fp_sys.install_ref_file(gb, None) fp_sys.drop_caches(None) remote_name = ref.get_remote_name() print("Installer: flatpak - added remote '%s'" % remote_name) except GLib.Error as e: if e.code != Gio.DBusError.ACCESS_DENIED: # user cancelling auth prompt for adding a remote print( "Installer: could not add new remote to system: %s" % e.message) dialogs.show_flatpak_error(e.message) except GLib.Error as e: print("Installer: flatpak - could not parse flatpakref file: %s" % e.message) dialogs.show_flatpak_error(e.message) if ref: try: remote = fp_sys.get_remote_by_name(remote_name, None) # Add the ref's remote if it doesn't already exist _process_remote(cache, fp_sys, remote, Flatpak.get_default_arch()) # Add the ref to the cache, so we can work with it like any other in mintinstall pkginfo = _add_package_to_cache(cache, ref, remote.get_url(), False) # Fetch the appstream info for the ref global _as_pools with _as_pool_lock: if remote_name not in _as_pools.keys(): _load_appstream_pool(_as_pools, remote) # Some flatpakref files will have a pointer to a runtime .flatpakrepo file # We need to process and possibly add that remote as well. kf = GLib.KeyFile() if kf.load_from_file(path, GLib.KeyFileFlags.NONE): try: url = kf.get_string("Flatpak Ref", "RuntimeRepo") except GLib.Error: url = None if url: # Fetch the .flatpakrepo file r = requests.get(url, stream=True) file = tempfile.NamedTemporaryFile(delete=False) with file as fd: for chunk in r.iter_content(chunk_size=128): fd.write(chunk) # Get the true runtime url from the repo file runtime_repo_url = _get_repofile_repo_url(file.name) if runtime_repo_url: existing = False path = Path(file.name) runtime_remote_name = Path(url).stem # Check if the remote is already installed for remote in fp_sys.list_remotes(None): # See comments below in _remote_from_repo_file_thread about get_noenumerate() use. if remote.get_url( ) == runtime_repo_url and not remote.get_noenumerate( ): print( "Installer: flatpak - runtime remote '%s' already in system, skipping" % runtime_remote_name) existing = True break if not existing: print( "Installer: Adding additional runtime remote named '%s' at '%s'" % (runtime_remote_name, runtime_repo_url)) cmd_v = [ 'flatpak', 'remote-add', '--from', runtime_remote_name, file.name ] add_repo_proc = subprocess.Popen(cmd_v) retcode = add_repo_proc.wait() fp_sys.drop_caches(None) os.unlink(file.name) except GLib.Error as e: print("Installer: could not process .flatpakref file: %s" % e.message) dialogs.show_flatpak_error(e.message) GLib.idle_add(callback, pkginfo, priority=GLib.PRIORITY_DEFAULT)
def _get_remote_related_refs(fp_sys, remote, ref): return_refs = [] try: related_refs = fp_sys.list_remote_related_refs_sync(remote, ref.format_ref(), None) for related_ref in related_refs: real_ref = None if not related_ref.should_download(): continue print("Looking for related ref %s in remote %s" % (related_ref.get_name(), remote)) try: real_ref = fp_sys.fetch_remote_ref_sync(remote, related_ref.get_kind(), related_ref.get_name(), related_ref.get_arch(), related_ref.get_branch(), None) except GLib.Error: pass if real_ref == None: for other_remote in fp_sys.list_remotes(): other_remote_name = other_remote.get_name() if other_remote_name == remote: continue print("Looking for related ref %s in alternate remote %s" % (related_ref.get_name(), other_remote_name)) try: real_ref = fp_sys.fetch_remote_ref_sync(other_remote_name, related_ref.get_kind(), related_ref.get_name(), related_ref.get_arch(), related_ref.get_branch(), None) except GLib.Error: continue if real_ref: break if real_ref == None: real_ref = Flatpak.RemoteRef(remote_name=remote, kind=related_ref.get_kind(), arch=related_ref.get_arch(), branch=related_ref.get_branch(), name=related_ref.get_name(), commit=related_ref.get_commit(), collection_id=related_ref.get_collection_id()) return_refs.append(real_ref) except GLib.Error as e: raise Exception("Could not determine remote related refs for app: %s" % e.message) return return_refs