Exemple #1
0
def populate_categories(logger):
    portdir = portage.settings["PORTDIR"]
    for cat in portage.settings.categories:
        try:
            meta = MetaData(os.path.join(portdir, cat, "metadata.xml"))
            desc = meta.descriptions()[0]
        except (IOError, IndexError):
            desc = ""
        obj, created = Category.objects.get_or_create(name=cat)
        obj.description = desc.strip()
        obj.save()
        if created:
            logger.info("+ [c] %s", cat)
Exemple #2
0
def populate_categories(logger):
    portdir = portage.settings["PORTDIR"]
    for cat in portage.settings.categories:
        try:
            meta = MetaData(os.path.join(portdir, cat, "metadata.xml"))
            desc = meta.descriptions()[0]
        except (IOError, IndexError):
            desc = ""
        obj, created = Category.objects.get_or_create(name=cat)
        obj.description = desc.strip()
        obj.save()
        if created:
            logger.info("+ [c] %s", cat)
Exemple #3
0
def get_metadata(pkg):
    metadata = {}

    pkg_metadata = None

    meta_override = os.path.join('metadata', pkg.category, pkg.name,
                                 'metadata.xml')

    try:
        if os.path.exists(meta_override):
            pkg_metadata = MetaData(meta_override)
            output.einfo('Using custom metadata: %s' % meta_override)
        if not pkg_metadata:
            pkg_metadata = pkg.metadata
    except Exception as e:
        output.ewarn('Error when fetching metadata: %s' % str(e))

    if not pkg_metadata:
        return {}

    # Support multiple remote-id and multiple watch
    for upstream in pkg_metadata._xml_tree.findall("upstream"):
        for node in upstream.findall("watch"):
            options = dict(node.attrib)
            options['data'] = node.text

            if "type" in options:
                handler = options['type']
            else:
                handler = "url"
                options['type'] = "url"

            for key in ["versionmangle", "downloadurlmangle"]:
                value = options.get(key, None)
                if value:
                    options[key] = value.split(";")

            if handler not in metadata:
                metadata[handler] = []
            metadata[handler].append(options)

    for upstream in pkg_metadata._xml_tree.findall("upstream"):
        for node in upstream.findall("remote-id"):
            handler = node.attrib.get("type")
            if not handler:
                continue
            if handler in metadata:
                for i in range(len(metadata[handler])):
                    if not metadata[handler][i]['data']:
                        metadata[handler][i]['data'] = node.text
            else:
                metadata[handler] = [{'type': handler, 'data': node.text}]

    return metadata
Exemple #4
0
    def metadata_from_db(self, query, pkg=None):
        if not pkg:
            pkg = self.get_package(query)

        try:
            version = Version.objects.filter(package=pkg).\
                values('metadata_path').order_by('version', 'revision')[0]
        except IndexError:
            return pkg, None

        if not version['metadata_path']:
            return pkg, None
        return pkg, MetaData(version['metadata_path'])
Exemple #5
0
def get_metadata(pkg):
    metadata = {}

    pkg_metadata = None

    meta_override = os.path.join('metadata', pkg.category, pkg.name,
                                 'metadata.xml')

    try:
        if os.path.exists(meta_override):
            pkg_metadata = MetaData(meta_override)
            output.einfo('Using custom metadata: %s' % meta_override)
        if not pkg_metadata:
            pkg_metadata = pkg.metadata
    except Exception, e:
        output.ewarn('Error when fetching metadata: %s' % str(e))
Exemple #6
0
    def metadata(self):
        """Instantiate a L{gentoolkit.metadata.MetaData} object here."""

        from gentoolkit.metadata import MetaData

        if self._metadata is None:
            metadata_path = os.path.join(self.package_path(), 'metadata.xml')
            try:
                self._metadata = MetaData(metadata_path)
            except IOError as error:
                import errno
                if error.errno != errno.ENOENT:
                    raise
                return None

        return self._metadata