Exemple #1
0
    def __init__(self):
        self.store = As.Store()
        self.store.load(As.StoreLoadFlags.APP_INFO_SYSTEM)

        itheme = Gtk.IconTheme.get_default()
        try:
            self.default_pixbuf = self.scaled_icon(itheme.load_icon(
                "package-x-generic",
                64,
                Gtk.IconLookupFlags.GENERIC_FALLBACK))
            self.security_pixbuf = self.scaled_icon(itheme.load_icon(
                "network-vpn",
                64,
                Gtk.IconLookupFlags.GENERIC_FALLBACK))
            self.mandatory_pixbuf = self.scaled_icon(itheme.load_icon(
                "computer",
                64,
                Gtk.IconLookupFlags.GENERIC_FALLBACK))
            self.other_pixbuf = self.scaled_icon(itheme.load_icon(
                "folder-download",
                64,
                Gtk.IconLookupFlags.GENERIC_FALLBACK))
            self.addon_pixbuf = self.scaled_icon(itheme.load_icon(
                "application-x-addon",
                64,
                Gtk.IconLookupFlags.GENERIC_FALLBACK))
        except Exception as e:
            print(e)
Exemple #2
0
	def execute_action(self,action,applist=None,store=None,results=0):
		if store:
			self.store=store
		else:
			self.store=appstream.Store()
		self.progress=0
		self.result['status']={'status':-1,'msg':''}
		self.result['data']=''
		
		if self.disabled==True:
			self._set_status(9)
			self.result['data']=self.store
		else:
			self._check_dirs()
			dataList=[]
			if action=='load':
				self.result['data']=self._loadStore(self.store)
			else:
				for app_info in applist:
					self.partial_progress=0
					if action=='install':
						dataList.append(self._install(app_info))
					if action=='remove':
						dataList.append(self._remove(app_info))
					if action=='pkginfo':
						dataList.append(self._get_info(app_info))
						#dataList.append((app_info))
					self.progress+=round(self.partial_progress/len(applist),1)
					if self.progress>98:
						self.progress=98
				self.result['data']=list(dataList)
		self.progress=100
		return(self.result)
Exemple #3
0
def _load_appstream_pool(pools, remote):
    pool = AppStreamGlib.Store()
    path = remote.get_appstream_dir().get_path()

    with open(os.path.join(path, "appstream.xml")) as f:
        pool.from_xml(f.read(), path)

    pools[remote.get_name()] = pool
Exemple #4
0
	def _searchPackage(self,package):
		self._debug("Searching %s"%package)
		pklist=None
		package=package.replace("_","-")
		apps=appstream.Store()
		searchStore=[]
		for app in self.store.get_apps():
			if app.search_matches(package)>90:
				apps.add_app(app)
		searchResults=rebostHelper.appstream_to_rebost(apps)
		return(searchResults)
Exemple #5
0
    def cache_icons(self):
        for release in self.active_fedora_releases:
            fname = 'fedora-%s.xml.gz' % release
            target = join(self.icons_path, 'tmp', str(release), fname)
            if not os.path.exists(target):
                return

            metadata = AppStreamGlib.Store()

            with gzip.open(target, 'rb') as f:
                metadata.from_xml(f.read(), '')

            for app in metadata.get_apps():
                # Other types are 'stock' and 'unknown'
                icons = app.get_icons()
                pkgname = app.get_pkgnames()[0]

                # Pick the biggest one..
                icon = None
                for candidate in icons:
                    if not icon:
                        if candidate.get_kind().value_nick == 'cached':
                            icon = candidate
                        continue
                    if int(icon.get_width()) < int(candidate.get_width()):
                        icon = candidate

                if not icon:
                    continue

                # Move the file out of the temp dir and into place
                s = join(self.icons_path, 'tmp', str(release),
                         '{width}x{height}', '{value}')
                d = join(self.icons_path, '{value}')
                source = s.format(width=icon.get_width(), height=icon.get_height(),
                                  value=icon.get_name())
                destination = d.format(value=icon.get_name())

                try:
                    shutil.copy(source, destination)

                    # And hang the name in the dict for other code to find it
                    # ... but only if we succeeded at placing the icon file.
                    self.icon_cache[pkgname] = icon.get_name()
                except IOError as e:
                    log.warning("appstream metadata lied: %s %r" % (source, e))
                except OSError as e:
                    log.warning("fail %r->%r.  %r" % (source, destination, e))

        shutil.rmtree(join(self.icons_path, 'tmp'))
 def execute_action(self, action, applist=None, store=None):
     if store:
         self.store = store
     else:
         self.store = appstream.Store()
     self.appimage_store = appstream.Store()
     self.progress = 0
     self.result['status'] = {'status': -1, 'msg': ''}
     self.result['data'] = []
     self.threads = []
     dataList = []
     if self.disabled:
         self._set_status(9)
         self.result['data'] = self.store
     else:
         self._chk_installDir()
         if action == 'load':
             self._load_appimage_store(self.store)
             self._debug("Ending threads...")
             while not self.apps_for_store.empty():
                 app = self.apps_for_store.get()
                 self.store.add_app(app)
             self.result['data'] = self.store
         else:
             for app_info in applist:
                 self.partial_progress = 0
                 if action == 'install':
                     dataList.append(self._install_appimage(app_info))
                 if action == 'remove':
                     dataList.append(self._remove_appimage(app_info))
                 if action == 'pkginfo':
                     dataList.append(self._get_info(app_info))
                 self.progress += int(
                     self.partial_progress / len(applist)) - 1
             self.result['data'] = list(dataList)
     self.progress = 100
     return (self.result)
Exemple #7
0
    def __init__(self):
        #  /usr/share/gir-1.0/AppStreamGlib-1.0.gir
        try:
            if not USE_APPSTREAM:
                raise ValueError
            import gi
            gi.require_version('AppStreamGlib', '1.0')
            from gi.repository import AppStreamGlib
            app_store = AppStreamGlib.Store()
            app_store.load(flags=AppStreamGlib.StoreLoadFlags.APP_INFO_SYSTEM);
            app_store.set_search_match(AppStreamGlib.AppSearchMatch.PKGNAME | AppStreamGlib.AppSearchMatch.NAME |  AppStreamGlib.AppSearchMatch.KEYWORD);
        except ValueError:
            app_store = None

        def _app_store_ico(tofind):
            """ find app in store
            It's very slow ...
            """
            default = "package"
            for app in app_store.get_apps():
                if app.get_kind() != AppStreamGlib.AppKind.DESKTOP:
                    continue
                if app.get_pkgname_default() == tofind:
                    #print(f"-- AppStream trouvé -- {tofind}")
                    # FIX entries errors
                    iname = app.get_icon_default().get_name()
                    if not ".png" in iname:
                        iname = f"{app.get_pkgname_default()}_{iname}.png"
                    icon = f"{app.get_icon_path()}/64x64/{iname}"
                    if not Path(icon).exists():
                        print(f"  bad ico ? {icon} {app.get_icon_default().get_name()}")
                        icon = default
                    return icon
            return default

        #self.handle = Handle('/', '/var/lib/pacman')
        self.handle = config.init_with_config("/etc/pacman.conf")
        self.pkgs = []
        for i, pkg in enumerate(self.handle.get_localdb().pkgcache):
            pkg_repo = self._find(pkg.name)
            afile = AlpmFile(pkg, i, pkg_repo)
            if app_store:
                afile.ico = _app_store_ico(pkg.name)
            self.pkgs.append(afile)
        print(f"end scan {len(self.pkgs)} packages")
Exemple #8
0
	def execute_action(self,action,applist=None,store=None,results=0):
		if store:
			self.store=store
		else:
			self.store=appstream.Store()
		self.progress=0
		self.result['status']={'status':-1,'msg':''}
		self.result['data']=''
		
		self.snap_client=Snapd.Client()
		try:
			self.snap_client.connect_sync(None)
		except Exception as e:
			self.disabled=True
			#self._debug("Disabling snap %s"%e)

		if self.disabled==True:
			self._set_status(9)
			self.result['data']=self.store
		else:
			self._check_dirs()
			dataList=[]
			if action=='load':
				self.result['data']=self._load_snap_store(self.store)
			else:
				for app_info in applist:
					self.partial_progress=0
					if action=='install':
						dataList.append(self._install_snap(app_info))
					if action=='remove':
						dataList.append(self._remove_snap(app_info))
					if action=='pkginfo':
						dataList.append(self._get_info(app_info))
					self.progress+=round(self.partial_progress/len(applist),1)
					if self.progress>98:
						self.progress=98
				self.result['data']=list(dataList)
		self.progress=100
		return(self.result)
Exemple #9
0
    def update_appdata_from_file(self, file_path, content_app_id=''):
        app = load_as_app_from_appdata(file_path)
        self.update_app(app, content_app_id)

        # Add a special metadata item in order to easily check if this app-data
        # file has been merged by eos-shell-content
        app.add_metadata('Endless::EosShellContent::Merged', 'true')

        store = AppStreamGlib.Store()
        store.add_app(app)
        xml_str = store.to_xml(AppStreamGlib.NodeToXmlFlags.NONE).str
        root = ET.fromstring(xml_str)
        if root.tag == 'components':
            root = root.find('component')

        # We do not want to display screenshots from 3rd parties when we have
        # provided some from the Shell Content, so we need to remove them.
        # The removal should be done in the app object but this cannot be
        # accomplished until there is API to do it in libappstream-glib.
        self._remove_unneeded_screenshots(root)

        node = xml.dom.minidom.parseString(ET.tostring(root, encoding='utf-8'))
        return node.toprettyxml(indent='  ')
Exemple #10
0
#!/usr/bin/env python2.7
import gi.repository
gi.require_version('AppStreamGlib', '1.0')
from gi.repository import AppStreamGlib as AS

store = AS.Store()

store.load(AS.StoreLoadFlags.APP_INFO_SYSTEM)


def test_markup(desc):
    m = AS.markup_convert(desc, -1, AS.MarkupConvertFormat.SIMPLE)
    return m


app = store.get_app_by_pkgname("pitivi")

desc = app.get_description("C")
print test_markup(desc)
Exemple #11
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)
Exemple #12
0
 def __init__(self):
     self.store = As.Store()
     self.store.load(As.StoreLoadFlags.APP_INFO_SYSTEM)