Example #1
0
	def _th_load_store(self,store,pkg,semaphore):
		semaphore.acquire()
		app=self.store.get_app_by_pkgname(pkg.get_name())
		if not app:
			#self._debug("Searching for %s"%pkg.get_name())
			app=self.store.get_app_by_id(pkg.get_name().lower()+".desktop")
			if app:
				bundle=appstream.Bundle()
				bundle.set_kind(bundle.kind_from_string('SNAP'))
				bundle.set_id(pkg.get_name()+'.snap')
				app.add_bundle(bundle)
				app.add_category("Snap")
				store.put(self._generate_appstream_app_from_snap(pkg))
			else:
				store.put(self._generate_appstream_app_from_snap(pkg))
		semaphore.release()
Example #2
0
	def _generate_appstream_app_from_snap(self,pkg):
		bundle=appstream.Bundle()
		app=appstream.App()
		icon=appstream.Icon()
		screenshot=appstream.Screenshot()
#		bundle.set_kind(appstream.BundleKind.SNAP)
		bundle.set_kind(bundle.kind_from_string('SNAP'))
		bundle.set_id(pkg.get_name()+'.snap')
		app.add_bundle(bundle)
		app.set_name("C",pkg.get_name()+'.snap')
		app.add_pkgname(pkg.get_name()+'.snap')
		app.add_category("Snap")
		release=appstream.Release()
		release.set_version(pkg.get_version())
		app.add_release(release)
		app.set_id("io.snapcraft.%s"%pkg.get_name()+'.snap')
		app.set_id_kind=appstream.IdKind.DESKTOP
		app.set_metadata_license("CC0-1.0")
		description="" #This is an Snap bundle. It hasn't been tested by our developers and comes from a 3rd party dev team. Please use it carefully."
		pkg_description=pkg.get_description()
		pkg_description=html.escape(pkg_description,quote=True)
		pkg_description=pkg_description.replace("<","&gt;")
		app.set_description("C","<p>%s</p><p>%s</p>"%(description,pkg_description))
		app.set_comment("C",pkg.get_summary().rstrip('.'))

		app.add_keyword("C",pkg.get_name())
		for word in pkg.get_summary().split(' '):
			if len(word)>3:
				app.add_keyword("C",word)

		if pkg.get_icon():
			if self.icon_cache_enabled:
				icon.set_kind(appstream.IconKind.LOCAL)
				icon.set_filename(self._download_file(pkg.get_icon(),pkg.get_name(),self.icons_folder))
			else:
				icon.set_kind(appstream.IconKind.REMOTE)
				icon.set_name(pkg.get_icon())
				icon.set_url(pkg.get_icon())
			app.add_icon(icon)

		if pkg.get_license():
			app.set_project_license(pkg.get_license())

		if pkg.get_screenshots():
			for snap_screen in pkg.get_screenshots():
				img=appstream.Image()
				img.set_kind(appstream.ImageKind.SOURCE)
				img.set_url(snap_screen.get_url())
				break
			screenshot.add_image(img)
			app.add_screenshot(screenshot)

		if not os.path.isfile(self.cache_xmls+'/'+app.get_id_filename()):
			xml_path='%s/%s.xml'%(self.cache_xmls,app.get_id_filename())
			gioFile=Gio.File.new_for_path(xml_path)
			app.to_file(gioFile)
			#Fix some things in app_file...
			with open(xml_path,'r',encoding='utf-8') as f:
				xml_data=f.readlines()
			#self._debug("fixing %s"%xml_path)
			try:
				xml_data[0]=xml_data[0]+"<components>\n"
				xml_data[-1]=xml_data[-1]+"\n"+"</components>"
			except:
				pass
			with open(xml_path,'w') as f:
				f.writelines(xml_data)
		return(app)
Example #3
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)
Example #4
0
    def _add_appimage(self, appinfo):
        #Search in local store for the app
        sw_new = True
        app = appstream.App()
        app_orig = self.store.get_app_by_pkgname(appinfo['name'].lower())
        if not app_orig:
            app_orig = self.store.get_app_by_id(appinfo['name'].lower() +
                                                ".desktop")
        if app_orig:
            self._debug("Extending app %s" % appinfo['package'])
            if appinfo['icon']:
                #self._debug("Icon: %s"%appinfo['icon'])
                app = self._copy_app_from_appstream(app_orig,
                                                    app,
                                                    copy_icon=False)
            else:
                app = self._copy_app_from_appstream(app_orig,
                                                    app,
                                                    copy_icon=True)
            sw_new = False
        else:
            self._debug("Generating new %s" % appinfo['package'])
            pass
        if appinfo['name'].lower().endswith('.appimage'):
            app.set_id("appimagehub.%s" % appinfo['name'].lower())
            app.set_name("C", appinfo['name'])
        else:
            app.set_id("appimagehub.%s" % appinfo['name'].lower() +
                       '.appimage')
            app.set_name("C", appinfo['name'] + ".appimage")
        if appinfo['package'].lower().endswith('.appimage'):
            app.add_pkgname(appinfo['package'].lower())
        else:
            app.add_pkgname(appinfo['package'].lower() + ".appimage")
        app.set_id_kind = appstream.IdKind.DESKTOP

        if appinfo['license']:
            app.set_project_license(appinfo['license'])
        bundle = appstream.Bundle()
        bundle.set_kind(bundle.kind_from_string('APPIMAGE'))
        if appinfo['package'].endswith('.appimage'):
            bundle.set_id(appinfo['package'])
        else:
            bundle.set_id(appinfo['package'] + '.appimage')
        app.add_bundle(bundle)
        if 'keywords' in appinfo.keys():
            for keyword in appinfo['keywords']:
                app.add_keyword("C", keyword)
            if 'appimage' not in appinfo['keywords']:
                app.add_keyword("C", "appimage")
        else:
            app.add_keyword("C", "appimage")
        app.add_url(appstream.UrlKind.UNKNOWN, appinfo['installerUrl'])
        app.add_url(appstream.UrlKind.HOMEPAGE, appinfo['homepage'])
        if sw_new:
            app.add_keyword("C", appinfo['package'])
            if not appinfo['name'].endswith('.appimage'):
                app.set_name("C", appinfo['name'] + ".appimage")
            desc_header = ""  #This is an AppImage bundle. It hasn't been tested by our developers and comes from a 3rd party dev team. Please use it carefully."
            if appinfo['description']:
                for lang, desc in appinfo['description'].items():
                    desc = desc.replace('&', '&amp;')
                    description = "<p>%s</p><p>%s</p>" % (desc_header, desc)
                    summary = ' '.join(list(desc.split(' ')[:10]))
                    app.set_description(lang, description)
                    app.set_comment(lang, summary)
            else:
                description = "<p>%s</p>" % (desc_header)
                summary = ' '.join(list(desc_header.split(' ')[:8]))
                app.set_description("C", description)
                app.set_comment("C", summary)

            if 'categories' in appinfo.keys():
                for category in appinfo['categories']:
                    if category:
                        app.add_category(category)
                if 'appimage' not in appinfo['categories']:
                    app.add_category("appimage")
            else:
                app.add_category("appimage")
        if appinfo['icon']:
            icon = appstream.Icon()
            if self.icon_cache_enabled:
                icon.set_kind(appstream.IconKind.LOCAL)
                icon_fn = self._download_file(appinfo['icon'], appinfo['name'],
                                              self.icons_dir)
                icon.set_filename(icon_fn)
            else:
                icon.set_kind(appstream.IconKind.REMOTE)
                icon.set_name(pkg.get_icon())
                icon.set_url(pkg.get_icon())
            app.add_icon(icon)
        if appinfo['thumbnails']:
            screenshot = appstream.Screenshot()
            img = appstream.Image()
            if not appinfo['thumbnails'][0].startswith('http'):
                appinfo['screenshot'] = appinfo['thumbnails'][0]
                appinfo[
                    'screenshot'] = "https://appimage.github.io/database/%s" % appinfo[
                        'screenshot']
            img.set_kind(appstream.ImageKind.SOURCE)
            img.set_url(appinfo['screenshot'])
            screenshot.add_image(img)
            app.add_screenshot(screenshot)
        #Adds the app to the store
        self.apps_for_store.put(app)
        xml_path = '%s/%s.xml' % (self.cache_xmls, app.get_id_filename())
        gioFile = Gio.File.new_for_path(xml_path)
        app.to_file(gioFile)
        #Fix some things in app_file...
        xml_file = open(xml_path, 'r', encoding='utf-8')
        xml_data = xml_file.readlines()
        xml_file.close()
        self._debug("fixing %s" % xml_path)
        try:
            xml_data[0] = xml_data[
                0] + "<components origin=\"%s\">\n" % app.get_origin()
            xml_data[-1] = xml_data[-1] + "\n" + "</components>"
        except:
            pass
        xml_file = open(xml_path, 'w')
        xml_file.writelines(xml_data)
        xml_file.close()