示例#1
0
    def iter_package_info(self):
        '''Iterate over ghost_package, blob_id, locator for this section.
        '''
        dummy, primary_data = self.get_primary_data()
        handle = os.popen('gunzip <%s' % primary_data)
        tree = parse_xml(handle)
        handle.close()
        common_prefix = 'http://linux.duke.edu/metadata/common'
        for package_element in tree.getroot():
            package_tag = '{%s}%s' % (common_prefix, u'package')
            if package_element.tag != package_tag:
                message = u'Unexpected element "%s" in %s' \
                    % (package_element.tag, primary_data)
                logger.warn(message)
                continue

            package = parse_rpm_header(package_element)
            location_element = \
                package_element.find('{%s}location' % common_prefix)
            if location_element is None:
                message = "Can't find location for package %s." \
                    % package.name
                raise InputError, message
            location = location_element.attrib['href']
            locator = FileLocator(self.path, location, package.blob_id,
                                  package.size, self.loader_factory)

            yield package, dict(package), package.blob_id, locator
示例#2
0
文件: channels.py 项目: djibi2/pdk
    def iter_package_info(self):
        '''Iterate over ghost_package, blob_id, locator for this section.
        '''
        dummy, primary_data = self.get_primary_data()
        handle = os.popen('gunzip <%s' % primary_data)
        tree = parse_xml(handle)
        handle.close()
        common_prefix = 'http://linux.duke.edu/metadata/common'
        for package_element in tree.getroot():
            package_tag = '{%s}%s' % (common_prefix, u'package')
            if package_element.tag != package_tag:
                message = u'Unexpected element "%s" in %s' \
                    % (package_element.tag, primary_data)
                logger.warn(message)
                continue

            package = parse_rpm_header(package_element)
            location_element = \
                package_element.find('{%s}location' % common_prefix)
            if location_element is None:
                message = "Can't find location for package %s." \
                    % package.name
                raise InputError, message
            location = location_element.attrib['href']
            locator = FileLocator(self.path, location, package.blob_id,
                                  package.size, self.loader_factory)

            yield package, dict(package), package.blob_id, locator
示例#3
0
    def get_primary_data(self):
        '''Look up the url and channel file for the primary.xml document.
        '''
        tree = parse_xml(open(self.repomd_data))
        root = tree.getroot()
        repo_prefix = 'http://linux.duke.edu/metadata/repo'
        data_pattern = '{%s}data' % repo_prefix
        data_elements = [
            d for d in root.findall(data_pattern)
            if d.attrib['type'] == 'primary'
        ]
        if len(data_elements) != 1:
            message = 'Found %d "primary" entries in %s' \
                % (len(data_elements), self.repomd_data)
            raise InputError, message

        data_element = data_elements[0]
        location_pattern = '{%s}location' % repo_prefix
        location_element = data_element.find(location_pattern)
        if location_element is None:
            raise InputError, 'Found no primary "location" in %s' \
                % self.repomd_data
        location = location_element.attrib['href']
        primary_url = '/'.join([self.path, location])
        return primary_url, self.get_channel_file(primary_url)
示例#4
0
def parse_yaxml_file(filename):
    '''Return data found in the given yaxml file.'''
    tree = parse_xml(filename)
    root = tree.getroot()
    data = {}
    build_tree(data, root)
    return data.values()[0]
示例#5
0
文件: channels.py 项目: djibi2/pdk
    def get_primary_data(self):
        '''Look up the url and channel file for the primary.xml document.
        '''
        tree = parse_xml(open(self.repomd_data))
        root = tree.getroot()
        repo_prefix = 'http://linux.duke.edu/metadata/repo'
        data_pattern = '{%s}data' % repo_prefix
        data_elements = [ d for d in root.findall(data_pattern)
                          if d.attrib['type'] == 'primary' ]
        if len(data_elements) != 1:
            message = 'Found %d "primary" entries in %s' \
                % (len(data_elements), self.repomd_data)
            raise InputError, message

        data_element = data_elements[0]
        location_pattern = '{%s}location' % repo_prefix
        location_element = data_element.find(location_pattern)
        if location_element is None:
            raise InputError, 'Found no primary "location" in %s' \
                % self.repomd_data
        location = location_element.attrib['href']
        primary_url = '/'.join([self.path, location])
        return primary_url, self.get_channel_file(primary_url)
示例#6
0
文件: test_util.py 项目: lucciano/pdk
 def test_xml_read_then_write(self):
     tree = parse_xml(stringio(expected_xml_output))
     output = stringio()
     write_pretty_xml(tree, output)
     self.assert_equals_long(expected_xml_output, output.getvalue())
示例#7
0
 def test_xml_read_then_write(self):
     tree = parse_xml(stringio(expected_xml_output))
     output = stringio()
     write_pretty_xml(tree, output)
     self.assert_equals_long(expected_xml_output, output.getvalue())