Ejemplo n.º 1
0
 def generate_filelist(self):
     filelist_formatter = rdf.filelist_formatter(self.packagedirname)
     outfilename = os.path.join(self.rdfdir, self.filelistname)
     outfile = open(outfilename, "w")
     filelist_formatter.set_fd(outfile)
     filelist_formatter.reset()
     filelist_formatter.feed(self.filelists)
     outfile.close()
     # Md5
     utils.md5sumtofile(outfilename)
     if COMPRESS:
         utils.compress_file(outfilename)
     # Sign file
     if SIGN and not PGPID == "":
         gpg.gpg_signfile(PGPFILE, PGPID, PGPHOMEDIR, outfilename)
Ejemplo n.º 2
0
    def generate_packages(self):
        package_formatter = rdf.package_formatter(
            self.writer, self.resources, self.resourcedirname, self.packagedirname, self.packageprefix, self.sigprefix
        )

        # Write rdf-file for package here.
        for basename in self.packages.keys():
            if not self.quiet:
                self.log.write_stdout("Writing rdf for package: %s" % basename)
            pkgdata = self.packages[basename]
            outfilename = os.path.join(self.rdfdir, self.packagedirname, (basename + ".rdf"))
            outfile = open(outfilename, "w")
            package_formatter.set_fd(outfile)
            package_formatter.reset()
            package_formatter.feed(pkgdata)
            outfile.close()
            # Sign file
            if SIGN and not PGPID == "":
                gpg.gpg_signfile(PGPFILE, PGPID, PGPHOMEDIR, outfilename)
Ejemplo n.º 3
0
    def generate_resources(self):
        if not self.quiet:
            self.log.write_stdout("Writing resources.rdf")
        resources_formatter = rdf.resources_formatter(self.writer, self.packagedirname)
        # resources.rdf
        outfilename = os.path.join(self.rdfdir, self.resources_filename)
        outfile = open(outfilename, "w")
        resources_formatter.set_fd(outfile)
        resources_formatter.reset()
        resources_formatter.feed(self.capabilities)
        outfile.close()
        # Md5
        utils.md5sumtofile(outfilename)
        if COMPRESS:
            utils.compress_file(outfilename)
        # Sign file
        if SIGN and not PGPID == "":
            gpg.gpg_signfile(PGPFILE, PGPID, PGPHOMEDIR, outfilename)
        if OLDSTYLERESOURCES:
            #
            # Old style resources:
            #
            resource_formatter = rdf.resource_formatter(self.writer, self.packagedirname)
            resourcelist_formatter = rdf.resourcelist_formatter(self.writer, self.resourcedirname)
            capfilenames = {}
            for capabilityname in self.capabilities.keys():
                if not self.quiet:
                    self.log.write_stdout("Writing rdf for resource: %s\n" % capabilityname)
                capabilitydata = self.capabilities[capabilityname]
                escaped_capabilityname = rdf.escape_capabilityname(capabilityname)
                capfilename = os.path.join(self.resourcedirname, (escaped_capabilityname + ".rdf"))
                outfilename = os.path.join(self.rdfdir, capfilename)
                capfilenames[capabilityname] = capfilename
                outfile = open(outfilename, "w")
                resource_formatter.set_fd(outfile)
                resource_formatter.reset()
                resource_formatter.feed(capabilityname, capabilitydata)
                outfile.close()
                # Sign file
                if SIGN and not PGPID == "":
                    gpg.gpg_signfile(PGPFILE, PGPID, PGPHOMEDIR, outfilename)

            outfilename = os.path.join(self.rdfdir, self.resourcelist_filename)
            outfile = open(outfilename, "w")
            resourcelist_formatter.set_fd(outfile)
            resourcelist_formatter.reset()
            resourcelist_formatter.feed(capfilenames)
            outfile.close()
            # Md5
            utils.md5sumtofile(outfilename)
            if COMPRESS:
                utils.compress_file(outfilename)
            # Sign file
            if SIGN and not PGPID == "":
                gpg.gpg_signfile(PGPFILE, PGPID, PGPHOMEDIR, outfilename)
        else:
            self.log.write_stdout("Skipping old style resources.\n")
Ejemplo n.º 4
0
    def generate_rdfs(self, filenames):

        for filename in filenames:
            self.prepare_package(filename)
            # Sign file
            if SIGN and not PGPID == "":
                signfile = ""
                if not self.sigprefix == "":
                    op = os.path
                    packagerdfpath = op.join(self.rdfdir, "packages")
                    sigpath = op.join(packagerdfpath, self.sigprefix)
                    signfile = op.join(sigpath, filename + ".asc")
                    sigextradir = op.join(sigpath, op.dirname(filename))
                    if not op.isdir(sigextradir):
                        os.makedirs(sigextradir)
                gpg.gpg_signfile(PGPFILE, PGPID, PGPHOMEDIR, filename, signfile)

        # Checking if there are any requirements on capabilities that are not
        # found in the capabilities dictionary. If so, look for the
        # capability in the file lists, and add the capability to the
        # capability dictionary with the packageinfo for the package in
        # which the file was found.
        (incl_files, incl_resources) = self.get_remote_info()

        # Update resources from capabilities.
        for capname in self.capabilities.keys():
            self.resources[capname] = os.path.join("..", self.get_resourcefilename(capname))

        errors = ""
        for requirement in self.requirements.keys():
            reqfound = False
            if not self.resources.has_key(requirement):
                #
                # Check if requirement is a file in a local package
                #
                for basename in self.packages.keys():
                    filelist = self.filelists[basename]
                    if requirement in filelist:
                        reqfound = True
                        packageinfo = self.packages[basename]
                        if not self.capabilities.has_key(requirement):
                            self.capabilities[requirement] = []
                        self.capabilities[requirement].append(packageinfo)
                        self.resources[requirement] = os.path.join("..", self.get_resourcefilename(requirement))

            # Now search linked resources
            if not reqfound and requirement in incl_resources.keys():
                reqfound = True
                if not OLDSTYLERESOURCES:
                    #
                    # We are happy as long as the requirement is provided
                    # remotely. Continue.
                    #
                    self.resources[requirement] = False
                    continue
                resourceinfo = []
                item = incl_resources[requirement]
                if not type(item) == types.ListType:
                    #
                    # Old style: Info is found in separate rdf.
                    #
                    uri = item
                    protocol, server, path = urlparse.urlparse(uri)[:3]
                    if not (protocol and server):
                        path = os.path.join("../..", path)
                        baseuri = os.path.dirname(path)
                    else:
                        baseuri = os.path.dirname(uri)
                    filename = self.download_file(uri)

                    resourceinfo = self.reader.read_resource(filename, baseuri)
                else:
                    #
                    # New style: info was part of resource.rdf
                    #
                    resourceinfo = item

                for index in range(len(resourceinfo)):
                    #
                    # Go through each resource-provider
                    #
                    resource = resourceinfo[index]

                    uri = resource["uri"]
                    baseuri = os.path.dirname(uri)
                    filename = self.download_file(uri)
                    packageinfo = self.reader.read_package_short(filename, baseuri)
                    packageinfo["uri"] = uri
                    if not self.capabilities.has_key(requirement):
                        self.capabilities[requirement] = []
                    self.capabilities[requirement].append(packageinfo)
                    self.resources[requirement] = os.path.join("..", self.get_resourcefilename(requirement))
            if not reqfound:
                # Now search included filelists.
                for uri in incl_files.keys():
                    if requirement in incl_files[uri]:
                        reqfound = True
                        if not OLDSTYLERESOURCES:
                            #
                            # We are happy as long as the requirement is
                            # provided remotely. Continue.
                            #
                            self.resources[requirement] = False
                            continue
                        # We found the file. It is in package with package
                        # description found at <uri>. Generate a resource
                        # for this file locally.

                        protocol, server, path = urlparse.urlparse(uri)[:3]
                        if not (protocol and server):
                            path = os.path.join("../..", path)
                            baseuri = os.path.dirname(path)
                        else:
                            baseuri = os.path.dirname(uri)
                        filename = self.download_file(uri)

                        packageinfo = self.reader.read_package_short(filename, baseuri)
                        packageinfo["uri"] = uri
                        if not self.capabilities.has_key(requirement):
                            self.capabilities[requirement] = []
                        self.capabilities[requirement].append(packageinfo)
                        self.resources[requirement] = os.path.join("..", self.get_resourcefilename(requirement))

            if reqfound:
                continue
            if not self.capabilities.has_key(requirement):
                requiringPackages = []
                for package in self.requirements[requirement]:
                    requiringPackages.append(package["name"])
                errors += "%s is missing the resource %s\n" % (requiringPackages, requirement)

        if errors:
            sys.stderr.write("%s\n" % errors)

        # Write a one-file package listing with name, version, release and
        # resource-pointer to rdf for package.
        # Send whole dict of packages
        self.generate_latestlist()

        # Write rdf-file for resources/capabilities here.
        self.generate_resources()

        # Write package rdfs.
        self.generate_packages()

        # Write filelist.
        self.generate_filelist()