Ejemplo n.º 1
0
    def update_app(self, app, content_app_id=''):
        app_id = content_app_id or app.get_id()
        metadata = self._get_app_metadata(app_id)

        if not metadata:
            app_id = app_id.rsplit('.desktop', 1)[0]
            metadata = self._get_app_metadata(app_id)

            if not metadata:
                raise NoMetadataException(app_id)

        app.set_name('C', metadata['title'])
        app.set_comment('C', metadata['subtitle'])
        description = metadata['description']
        app.set_description('C', description)

        categories = metadata.get('category')
        for category in categories.split(';'):
            app.add_category(category)

        # Screenshots in the metadata are arranged as 'language' -> ['image', ...]
        # but we need to group the same images in the same screenshot (with a
        # different language each), so we invert the arrangement as:
        # 'image' -> ['language', ...]
        #
        # Use an OrderedDict so we maintain the order of the screenshots as found
        # in the metadata which can be important.
        screenshots = collections.OrderedDict()
        for locale, images in metadata.get('screenshots', {}).items():
            for image in images:
                screenshots.setdefault(image, []).append(locale)

        for image, locales in screenshots.items():
            screenshot = AppStreamGlib.Screenshot()
            for locale in locales:
                as_img = AppStreamGlib.Image()
                # We need to add the screenshots as source, otherwise, without a
                # caption and other elements, AppStreamGlib discards the screenshots
                # as duplicates...
                as_img.set_kind(AppStreamGlib.ImageKind.SOURCE)
                as_img.set_url(self._get_screenshot_url(app_id, locale, image))
                if locale != 'C':
                    as_img.set_locale(locale)
                screenshot.add_image(as_img)
            app.add_screenshot(screenshot)

        self._translate_app(app)
        # We only format the description now otherwise it would not
        # match the translations
        app.set_description('C',
                            self._add_paragraph_tags_if_needed(description))
Ejemplo n.º 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)
Ejemplo n.º 3
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()