Пример #1
0
 def _parse_tree(self, node):
     """ Parse a <release> object """
     if 'timestamp' in node.attrib:
         self.timestamp = int(node.attrib['timestamp'])
     if 'date' in node.attrib:
         dt = dateutil.parser.parse(node.attrib['date'])
         self.timestamp = int(dt.strftime("%s"))
     if 'urgency' in node.attrib:
         self.urgency = node.attrib['urgency']
     if 'version' in node.attrib:
         self.version = node.attrib['version']
         # fix up hex value
         if self.version.startswith('0x'):
             self.version = str(int(self.version[2:], 16))
     for c3 in node:
         if c3.tag == 'description':
             self.description = _parse_desc(c3)
         if c3.tag == 'size':
             if 'type' not in c3.attrib:
                 continue
             if c3.attrib['type'] == 'installed':
                 self.size_installed = int(c3.text)
             if c3.attrib['type'] == 'download':
                 self.size_download = int(c3.text)
         elif c3.tag == 'checksum':
             csum = Checksum()
             csum._parse_tree(c3)
             self.add_checksum(csum)
Пример #2
0
 def _parse_tree(self, node):
     """ Parse a <review> object """
     if 'date' in node.attrib:
         dt = dateutil.parser.parse(node.attrib['date'])
         self.date = int(dt.strftime("%s"))
     if 'id' in node.attrib:
         self.id = node.attrib['id']
     if 'karma' in node.attrib:
         self.karma = int(node.attrib['karma'])
     if 'score' in node.attrib:
         self.score = int(node.attrib['score'])
     if 'rating' in node.attrib:
         self.rating = int(node.attrib['rating'])
     for c3 in node:
         if c3.tag == 'lang':
             self.locale = c3.text
         if c3.tag == 'version':
             self.version = c3.text
         if c3.tag == 'reviewer_id':
             self.reviewer_id = c3.text
         if c3.tag == 'reviewer_name':
             self.reviewer_name = c3.text
         if c3.tag == 'summary':
             self.summary = c3.text
         if c3.tag == 'description':
             self.description = _parse_desc(c3)
         if c3.tag == 'metadata':
             for c4 in c3:
                 if c4.tag == 'value':
                     if 'key' in c4.attrib:
                         self.metadata[c4.attrib['key']] = c4.text
Пример #3
0
 def _parse_tree(self, node):
     """ Parse a <release> object """
     if 'timestamp' in node.attrib:
         self.timestamp = int(node.attrib['timestamp'])
     if 'date' in node.attrib:
         dt = dateutil.parser.parse(node.attrib['date'])
         self.timestamp = int(dt.strftime("%s"))
     if 'urgency' in node.attrib:
         self.urgency = node.attrib['urgency']
     if 'version' in node.attrib:
         self.version = node.attrib['version']
         # fix up hex value
         if self.version.startswith('0x'):
             self.version = str(int(self.version[2:], 16))
     for c3 in node:
         if c3.tag == 'description':
             self.description = _parse_desc(c3)
         if c3.tag == 'size':
             if 'type' not in c3.attrib:
                 continue
             if c3.attrib['type'] == 'installed':
                 self.size_installed = int(c3.text)
             if c3.attrib['type'] == 'download':
                 self.size_download = int(c3.text)
         elif c3.tag == 'checksum':
             csum = Checksum()
             csum._parse_tree(c3)
             self.add_checksum(csum)
Пример #4
0
 def _parse_tree(self, node):
     """ Parse a <screenshot> object """
     if 'type' in node.attrib:
         self.kind = node.attrib['type']
     for c3 in node:
         if c3.tag == 'caption':
             self.caption = _parse_desc(c3)
         elif c3.tag == 'image':
             im = Image()
             im._parse_tree(c3)
             self.add_image(im)
Пример #5
0
 def _parse_tree(self, node):
     """ Parse a <screenshot> object """
     if 'type' in node.attrib:
         self.kind = node.attrib['type']
     for c3 in node:
         if c3.tag == 'caption':
             self.caption = _parse_desc(c3)
         elif c3.tag == 'image':
             im = Image()
             im._parse_tree(c3)
             self.add_image(im)
Пример #6
0
    def parse(self, xml_data):
        """ Parse XML data """

        # parse tree
        if isinstance(xml_data, string_types):
            # Presumably, this is textual xml data.
            try:
                root = ET.fromstring(xml_data)
            except StdlibParseError as e:
                raise ParseError(str(e))
        else:
            # Otherwise, assume it has already been parsed into a tree
            root = xml_data

        # get type
        if 'type' in root.attrib:
            self.kind = root.attrib['type']

        # parse component
        for c1 in root:

            # <id>
            if c1.tag == 'id':
                self.id = c1.text

            # <updatecontact>
            elif c1.tag == 'updatecontact' or c1.tag == 'update_contact':
                self.update_contact = c1.text

            # <metadata_license>
            elif c1.tag == 'metadata_license':
                self.metadata_license = c1.text

            # <releases>
            elif c1.tag == 'releases':
                for c2 in c1:
                    if c2.tag == 'release':
                        rel = Release()
                        rel._parse_tree(c2)
                        self.add_release(rel)

            # <reviews>
            elif c1.tag == 'reviews':
                for c2 in c1:
                    if c2.tag == 'review':
                        rev = Review()
                        rev._parse_tree(c2)
                        self.add_review(rev)

            # <screenshots>
            elif c1.tag == 'screenshots':
                for c2 in c1:
                    if c2.tag == 'screenshot':
                        ss = Screenshot()
                        ss._parse_tree(c2)
                        self.add_screenshot(ss)

            # <provides>
            elif c1.tag == 'provides':
                for c2 in c1:
                    prov = Provide()
                    prov._parse_tree(c2)
                    self.add_provide(prov)

            # <requires>
            elif c1.tag == 'requires':
                for c2 in c1:
                    req = Require()
                    req._parse_tree(c2)
                    self.add_require(req)

            # <kudos>
            elif c1.tag == 'kudos':
                for c2 in c1:
                    if not c2.tag == 'kudo':
                        continue
                    self.kudos.append(c2.text)

            # <keywords>
            elif c1.tag == 'keywords':
                for c2 in c1:
                    if not c2.tag == 'keyword':
                        continue
                    self.keywords.append(c2.text)

            # <categories>
            elif c1.tag == 'categories':
                for c2 in c1:
                    if not c2.tag == 'category':
                        continue
                    self.categories.append(c2.text)

            # <custom>
            elif c1.tag == 'custom':
                for c2 in c1:
                    if not c2.tag == 'value':
                        continue
                    if 'key' not in c2.attrib:
                        continue
                    self.custom[c2.attrib['key']] = c2.text

            # <project_license>
            elif c1.tag == 'project_license' or c1.tag == 'licence':
                self.project_license = c1.text

            # <developer_name>
            elif c1.tag == 'developer_name':
                self.developer_name = _join_lines(c1.text)

            # <name>
            elif c1.tag == 'name' and not self.name:
                self.name = _join_lines(c1.text)

            # <pkgname>
            elif c1.tag == 'pkgname' and not self.pkgname:
                self.pkgname = _join_lines(c1.text)

            # <summary>
            elif c1.tag == 'summary' and not self.summary:
                self.summary = _join_lines(c1.text)

            # <description>
            elif c1.tag == 'description' and not self.description:
                self.description = _parse_desc(c1)

            # <url>
            elif c1.tag == 'url':
                key = 'homepage'
                if 'type' in c1.attrib:
                    key = c1.attrib['type']
                self.urls[key] = c1.text

            # <icon>
            elif c1.tag == 'icon':
                key = c1.attrib.pop('type', 'unknown')
                c1.attrib['value'] = c1.text
                self.icons[key] = self.icons.get(key, []) + [c1.attrib]

            # <bundle>
            elif c1.tag == 'bundle':
                type = c1.attrib.pop('type', 'unknown')
                runtime = c1.attrib.pop('runtime', 'unknown')
                sdk = c1.attrib.pop('sdk', 'unknown')
                value = c1.text
                self.bundle = {
                    'type': type,
                    'runtime': runtime,
                    'sdk': sdk,
                    'value': value
                }
Пример #7
0
    def parse(self, xml_data):
        """ Parse XML data """

        # parse tree
        if isinstance(xml_data, string_types):
            # Presumably, this is textual xml data.
            try:
                root = ET.fromstring(xml_data)
            except StdlibParseError as e:
                raise ParseError(str(e))
        else:
            # Otherwise, assume it has already been parsed into a tree
            root = xml_data

        # get type
        if 'type' in root.attrib:
            self.kind = root.attrib['type']

        # parse component
        for c1 in root:

            # <id>
            if c1.tag == 'id':
                self.id = c1.text

            # <updatecontact>
            elif c1.tag == 'updatecontact' or c1.tag == 'update_contact':
                self.update_contact = c1.text

            # <metadata_license>
            elif c1.tag == 'metadata_license':
                self.metadata_license = c1.text

            # <releases>
            elif c1.tag == 'releases':
                for c2 in c1:
                    if c2.tag == 'release':
                        rel = Release()
                        rel._parse_tree(c2)
                        self.add_release(rel)

            # <screenshots>
            elif c1.tag == 'screenshots':
                for c2 in c1:
                    if c2.tag == 'screenshot':
                        ss = Screenshot()
                        ss._parse_tree(c2)
                        self.add_screenshot(ss)

            # <provides>
            elif c1.tag == 'provides':
                for c2 in c1:
                    prov = Provide()
                    prov._parse_tree(c2)
                    self.add_provide(prov)

            # <kudos>
            elif c1.tag == 'kudos':
                for c2 in c1:
                    if not c2.tag == 'kudo':
                        continue
                    self.kudos.append(c2.text)

            # <keywords>
            elif c1.tag == 'keywords':
                for c2 in c1:
                    if not c2.tag == 'keyword':
                        continue
                    self.keywords.append(c2.text)

            # <project_license>
            elif c1.tag == 'project_license' or c1.tag == 'licence':
                self.project_license = c1.text

            # <developer_name>
            elif c1.tag == 'developer_name':
                self.developer_name = _join_lines(c1.text)

            # <name>
            elif c1.tag == 'name' and not self.name:
                self.name = _join_lines(c1.text)

            # <pkgname>
            elif c1.tag == 'pkgname' and not self.pkgname:
                self.pkgname = _join_lines(c1.text)

            # <summary>
            elif c1.tag == 'summary' and not self.summary:
                self.summary = _join_lines(c1.text)

            # <description>
            elif c1.tag == 'description' and not self.description:
                self.description = _parse_desc(c1)

            # <url>
            elif c1.tag == 'url':
                key = 'homepage'
                if 'type' in c1.attrib:
                    key = c1.attrib['type']
                self.urls[key] = c1.text

            elif c1.tag == 'icon':
                key = c1.attrib.pop('type', 'unknown')
                c1.attrib['value'] = c1.text
                self.icons[key] = self.icons.get(key, []) + [c1.attrib]