def _parse_description_tag(subs): ''' Handles the description tag ''' def prepare_desc_string(s): ''' Clears linebreaks and XML-escapes the resulting string ''' if not s: return "" s = s.strip() s = " ".join(s.split()) return escape(s) ddict = dict() # The description tag translation is combined per language, # for faster parsing on the client side. # In case no translation is found, the untranslated version is used instead. # the DEP-11 YAML stores the description as HTML for usubs in subs: locale = _get_tag_locale(usubs) if usubs.tag == 'p': if not locale in ddict: ddict[locale] = "" ddict[locale] += "<p>%s</p>" % str_enc_dec(prepare_desc_string(usubs.text)) elif usubs.tag == 'ul' or usubs.tag == 'ol': tmp_dict = dict() # find the right locale, or fallback to untranslated for u_usubs in usubs: locale = _get_tag_locale(u_usubs) if not locale in tmp_dict: tmp_dict[locale] = "" if u_usubs.tag == 'li': tmp_dict[locale] += "<li>%s</li>" % str_enc_dec(prepare_desc_string(u_usubs.text)) for locale, value in tmp_dict.items(): if not locale in ddict: # This should not happen (but better be prepared) ddict[locale] = "" ddict[locale] += "<%s>%s</%s>" % (usubs.tag, value, usubs.tag) return ddict
def _parse_description_tag(subs): ''' Handles the description tag ''' def prepare_desc_string(s): ''' Clears linebreaks and XML-escapes the resulting string ''' s = s.strip() s = " ".join(s.split()) return escape(s) ddict = dict() # The description tag translation is combined per language, # for faster parsing on the client side. # In case no translation is found, the untranslated version is used instead. # the DEP-11 YAML stores the description as HTML for usubs in subs: locale = _get_tag_locale(usubs) if usubs.tag == 'p': if not locale in ddict: ddict[locale] = "" ddict[locale] += "<p>%s</p>" % str_enc_dec( prepare_desc_string(usubs.text)) elif usubs.tag == 'ul' or usubs.tag == 'ol': tmp_dict = dict() # find the right locale, or fallback to untranslated for u_usubs in usubs: locale = _get_tag_locale(u_usubs) if not locale in tmp_dict: tmp_dict[locale] = "" if u_usubs.tag == 'li': tmp_dict[locale] += "<li>%s</li>" % str_enc_dec( prepare_desc_string(u_usubs.text)) for locale, value in tmp_dict.items(): if not locale in ddict: # This should not happen (but better be prepared) ddict[locale] = "" ddict[locale] += "<%s>%s</%s>" % (usubs.tag, value, usubs.tag) return ddict
def _parse_screenshots_tag(subs): ''' Handles screenshots.Caption source-image etc. ''' shots = [] for usubs in subs: # for one screeshot tag if usubs.tag == 'screenshot': screenshot = dict() attr_dic = usubs.attrib if attr_dic.get('type'): if attr_dic['type'] == 'default': screenshot['default'] = True # in case of old styled xmls url = usubs.text if url: url = url.strip() screenshot['source-image'] = {'url': url} shots.append(screenshot) continue # else look for captions and image tag for tags in usubs: if tags.tag == 'caption': # for localisation attr_dic = tags.attrib if attr_dic: for v in attr_dic.values(): key = v else: key = 'C' if screenshot.get('caption'): screenshot['caption'][key] = str_enc_dec(tags.text) else: screenshot['caption'] = {key: str_enc_dec(tags.text)} if tags.tag == 'image': screenshot['source-image'] = {'url': tags.text} # only add the screenshot if we have a source image if screenshot.get('source-image'): shots.append(screenshot) return shots
def _parse_screenshots_tag(subs): ''' Handles screenshots.Caption source-image etc. ''' shots = [] for usubs in subs: # for one screeshot tag if usubs.tag == 'screenshot': screenshot = dict() attr_dic = usubs.attrib if attr_dic.get('type'): if attr_dic['type'] == 'default': screenshot['default'] = True # in case of old styled xmls url = usubs.text if url: url = url.strip() screenshot['source-image'] = {'url': url} shots.append(screenshot) continue # else look for captions and image tag for tags in usubs: if tags.tag == 'caption': # for localisation attr_dic = tags.attrib if attr_dic: for v in attr_dic.values(): key = v else: key = 'C' if screenshot.get('caption'): screenshot['caption'][key] = str_enc_dec(tags.text) else: screenshot['caption'] = {key: str_enc_dec(tags.text)} if tags.tag == 'image': screenshot['source-image'] = {'url': tags.text} # only add the screenshot if we have a source image if screenshot.get ('source-image'): shots.append(screenshot) return shots
def read_desktop_data(cpt, dcontent): ''' Parses a .desktop file and sets ComponentData properties ''' df = RawConfigParser() df.readfp(StringIO.StringIO(dcontent)) items = None try: items = df.items("Desktop Entry") if df.get("Desktop Entry", "Type") != "Application": # ignore this file, isn't an application cpt.add_error_hint("Not an application.") return False try: if df.get("Desktop Entry", "NoDisplay") == "True": # we ignore this .desktop file, shouldn't be displayed cpt.add_error_hint("Invisible") return False except: # we don't care if the NoDisplay variable doesn't exist # if it isn't there, the file should be processed pass except Exception as e: # this .desktop file is not interesting cpt.add_error_hint("Error while reading .desktop data: %s" % str(e)) return True # if we reached this step, we are dealing with a GUI desktop app cpt.kind = 'desktop-app' for item in items: if len(item) != 2: continue key = item[0] value = str_enc_dec(item[1]) if not value: continue if key.startswith("name"): if key == 'name': cpt.name['C'] = value else: cpt.name[key[5:-1]] = value elif key == 'categories': value = value.split(';') value.pop() cpt.categories = value elif key.startswith('comment'): if key == 'comment': cpt.summary['C'] = value else: cpt.summary[key[8:-1]] = value elif key.startswith('keywords'): value = re.split(';|,', value) if not value[-1]: value.pop() if key[8:] == '': if cpt.keywords: if set(value) not in \ [set(val) for val in cpt.keywords.values()]: cpt.keywords.update({'C': map(str_enc_dec, value)}) else: cpt.keywords = {'C': map(str_enc_dec, value)} else: if cpt.keywords: if set(value) not in \ [set(val) for val in cpt.keywords.values()]: cpt.keywords.update( {key[9:-1]: map(str_enc_dec, value)}) else: cpt.keywords = {key[9:-1]: map(str_enc_dec, value)} elif key == 'mimetype': value = value.split(';') if len(value) > 1: value.pop() for val in value: cpt.add_provided_item(ProvidedItemType.MIMETYPE, val) elif key == 'icon': cpt.icon = value return True
def read_desktop_data(cpt, dcontent): ''' Parses a .desktop file and sets ComponentData properties ''' df = RawConfigParser() df.readfp(StringIO.StringIO(dcontent)) items = None try: items = df.items("Desktop Entry") if df.get("Desktop Entry", "Type") != "Application": # ignore this file, isn't an application cpt.add_error_hint("Not an application.") return False try: if df.get("Desktop Entry", "NoDisplay") == "True": # we ignore this .desktop file, shouldn't be displayed cpt.add_error_hint("Invisible") return False except: # we don't care if the NoDisplay variable doesn't exist # if it isn't there, the file should be processed pass except Exception as e: # this .desktop file is not interesting cpt.add_error_hint("Error while reading .desktop data: %s" % str(e)) return True # if we reached this step, we are dealing with a GUI desktop app cpt.kind = 'desktop-app' for item in items: if len(item) != 2: continue key = item[0] value = str_enc_dec(item[1]) if not value: continue if key.startswith("name"): if key == 'name': cpt.name['C'] = value else: cpt.name[key[5:-1]] = value elif key == 'categories': value = value.split(';') value.pop() cpt.categories = value elif key.startswith('comment'): if key == 'comment': cpt.summary['C'] = value else: cpt.summary[key[8:-1]] = value elif key.startswith('keywords'): value = re.split(';|,', value) if not value[-1]: value.pop() if key[8:] == '': if cpt.keywords: if set(value) not in \ [set(val) for val in cpt.keywords.values()]: cpt.keywords.update( {'C': map(str_enc_dec, value)} ) else: cpt.keywords = { 'C': map(str_enc_dec, value) } else: if cpt.keywords: if set(value) not in \ [set(val) for val in cpt.keywords.values()]: cpt.keywords.update( {key[9:-1]: map(str_enc_dec, value)} ) else: cpt.keywords = { key[9:-1]: map(str_enc_dec, value) } elif key == 'mimetype': value = value.split(';') if len(value) > 1: value.pop() for val in value: cpt.add_provided_item( ProvidedItemType.MIMETYPE, val ) elif key == 'icon': cpt.icon = value return True