Beispiel #1
0
	def _install(self,app_info):
		#self._debug("Installing %s"%app_info['name'])
		action="install"
		flInst=Flatpak.get_system_installations()
		for installer in flInst:
			flRemote=installer.list_remotes()
			remoteInst=installer
			for remote in flRemote:
				remoteName=remote.get_name()
				break
			transaction=Flatpak.Transaction.new_for_installation(installer)
			break
#		ref=remoteInst.install(remoteName,Flatpak.RefKind.APP,app_info['id'],None,'stable',None,None,None)
#		for relRef in remoteInst.list_remote_related_refs_sync(remoteName,ref.format_ref()):
#			if relRef.should_download():
#				self._debug("Installing related ref %s"%relRef.get_name())
#				remoteInst.install(remoteName,Flatpak.RefKind.APP,relRef.format_ref(),None,'stable',None,None,None)

		if transaction:
	   	#Get remote ref
			self._debug(remoteName)
			remoteRef=remoteInst.fetch_remote_ref_sync(remoteName,Flatpak.RefKind.APP,app_info['id'],None,'stable',None)
			self._debug(remoteRef)
			self._debug(app_info['id'])
			#transaction.add_install(remoteName,remoteRef.get_remote_name(),None)
			transaction.add_install(remoteName,remoteRef.format_ref(),None)
			self._debug(transaction)
			transaction.run()
	   #self._debug("Installed %s"%app_info)
#		self.resultQ[action].put(str(json.dumps([result])))
#		self.progress[action] = 100
#		self.progressQ[action].put(int(self.progress[action]))
		app_info['state']='installed'
		self._set_status(0)
		return app_info
Beispiel #2
0
	def _get_info(self,app_info):
		flInst=Flatpak.get_system_installations()
		for installer in flInst:
			flRemote=installer.list_remotes()
			remoteInst=installer
			break
		try:
			installer.get_installed_ref(Flatpak.RefKind.APP,app_info['id'],None,'stable',None)
			app_info['state']='installed'
		except Exception as e:
			app_info['state']='available'
		self._set_status(0)
		return app_info
Beispiel #3
0
	def _remove(self,app_info):
		action='remove'
		flInst=Flatpak.get_system_installations()
		for installer in flInst:
			flRemote=installer.list_remotes()
			remoteInst=installer
			for remote in flRemote:
				remoteName=remote.get_name()
				break
			transaction=Flatpak.Transaction.new_for_installation(installer)
			break
		if transaction:
	   	#Get remote ref
			self._debug(remoteName)
			remoteRef=remoteInst.fetch_remote_ref_sync(remoteName,Flatpak.RefKind.APP,app_info['id'],None,'stable',None)
			self._debug(remoteRef)
			self._debug(app_info['id'])
			#transaction.add_install(remoteName,remoteRef.get_remote_name(),None)
			transaction.add_uninstall(remoteRef.format_ref())
			self._debug(transaction)
			transaction.run()
		app_info['state']='available'
		self._set_status(0)
		return app_info
Beispiel #4
0
	def _get_flatpak_catalogue(self):
		action="load"
		rebostPkgList=[]
		sections=[]
		progress=0
		inc=0
		flInst=''
		store=appstream.Store()
		store2=appstream.Store()
		#metadata=appstream.Metadata()
		try:
			#Get all the remotes, copy appstream to wrkdir
			flInst=Flatpak.get_system_installations()
			for installer in flInst:
				flRemote=installer.list_remotes()
				for remote in flRemote:
					srcDir=remote.get_appstream_dir().get_path()
					installer.update_appstream_sync(remote.get_name())
			#sections=self.snap_client.get_sections_sync()
		except Exception as e:
			print(e)
			#self._on_error("load",e)

		try:
			store.from_file(Gio.File.parse_name(os.path.join(srcDir,"appstream.xml")))
		except Exception as e:
			print(e)
			pass
		added=[]
		for pkg in store.get_apps():
			idx=pkg.get_id()
			idxList=idx.split(".")
			if len(idxList)>2:
				idxList[0]="org"
				idxList[1]="flathub"
				newId=".".join(idxList).lower()
			else:
				newId="org.flathub.{}".format(idx[-1])
			#pkg.set_id(newId)
			state="available"
			for installer in flInst:
				installed=False
				try:
					installed=installer.get_installed_ref(0,pkg.get_name())
				except:
					try:
						installed=installer.get_installed_ref(1,pkg.get_name())
					except:
						pass
				if installed:
					state="installed"
					break
			#flatpak has his own cache dir for icons so if present use it
			iconPath=''
			icon64=os.path.join(srcDir,"icons/64x64")
			icon128=os.path.join(srcDir,"icons/128x128")
			idx=idx.replace(".desktop","")
			if os.path.isfile(os.path.join(icon128,"{}.png".format(idx))):
				iconPath=os.path.join(icon128,"{}.png".format(idx))
			elif os.path.isfile(os.path.join(icon64,"{}.png".format(idx))):
				iconPath=os.path.join(icon64,"{}.png".format(idx))
			if iconPath!='':
				icon=appstream.Icon()
				icon.set_kind(appstream.IconKind.LOCAL)
				icon.set_filename(iconPath)
				pkg.add_icon(icon)
			add=False
			if not pkg.get_bundles():
				bundle=appstream.Bundle()
				bundle.set_id("{};amd64;{}".format(pkg.get_id(),state))
				bundle.set_kind(appstream.BundleKind.FLATPAK)
				pkg.add_bundle(bundle)
				add=True
			else:
				for bundle in pkg.get_bundles():
					bundle.set_id("{};amd64;{}".format(pkg.get_id(),state))
					bundle.set_kind(appstream.BundleKind.FLATPAK)
					add=True
			if add and pkg.get_id() not in added:
				try:
						#	if not (app.validate()):
					pkg.set_name("C",pkg.get_name().lower().replace(" ","_")+'.flatpak')
					pkg.add_pkgname(pkg.get_name())
					store2.add_app(pkg)
				#	else:
				#		pass
				#		print(app.validate())
				except:
					pass
				added.append(pkg.get_id())
		self._debug("Loaded flatpak metadata")
		return(store2)