Пример #1
0
 def _find_package(self, name, version):
     pkg = self._packages()[name]
     for p in pkg:
         if p[0] == version:
             P = Package.Package(name, version, p[1][self.CHECKSUM_KEY])
             for upd in p[1][self.UPDATES_KEY]:
                 P.AddUpdate(upd[0], upd[1])
             return P
Пример #2
0
def main():
    root = ""
    try:
        opts, args = getopt.getopt(sys.argv[1:], "R:")
    except getopt.GetOptError as err:
        print >> sys.stderr, str(err)
        usage()

    for (o, a) in opts:
        if o == "-R":
            root = a
        else:
            usage()

    pkgdb = Package.PackageDB(root)

    files = pkgdb.FindFilesForPackage()
    # That gets us all the files!  Easy enough
    # Now we iterate them, and compare them against the actual filesystem
    for object in files:
        full_path = root + object["path"]
        try:
            st = os.lstat(full_path)
        except OSError as e:
            print >> sys.stderr, "Entry %s does not exist in filesystem" % object[
                "path"]
        else:
            # Now we check the type, mode, flags, owner, and group
            if object["kind"] == "dir" and stat.S_ISDIR(st.st_mode) == 0:
                print >> sys.stderr, "Entry %s is listed as a directory but is not" % object[
                    "path"]
            elif object["kind"] == "file" and stat.S_ISREG(st.st_mode) == 0:
                print >> sys.stderr, "Entry %s is listed as a regular file but is not" % object[
                    "path"]
            elif object["kind"] == "slink" and stat.S_ISLNK(st.st_mode) == 0:
                print >> sys.stderr, "Entry %s is listed as a symbolic link but is not" % object[
                    "path"]
            if object["uid"] != st.st_uid:
                print >> sys.stderr, "Entry %s is listed as owned by uid %d but has uid %d" % (
                    object["path"], object["uid"], st.st_uid)
            if object["gid"] != st.st_gid:
                print >> sys.stderr, "Entry %s is listed with gid %d but has gid %d" % (
                    object["path"], object["gid"], st.st_gid)
            if object["flags"] != st.st_flags:
                print >> sys.stderr, "Entry %s is listed with flags %#x but has flags %#x" % (
                    object["path"], object["flags"], st.st_flags)
            if object["mode"] != stat.S_IMODE(st.st_mode):
                print >> sys.stderr, "Entry %s is listed with mode %#o but has mode %#o" % (
                    object["path"], object["mode"], stat.S_IMODE(st.st_mode))
Пример #3
0
def Install(root = None, manifest = None):
    """
    Perform an install.  Uses the system manifest, and installs
    into root.  root must be set.
    """
    if root is None:
        print >> sys.stderr, "Install must have target root specified"
        usage()
    conf = Configuration.Configuration()
    if manifest is not None:
        cur = Manifest.Manifest()
        try:
            cur.LoadPath(manifest)
        except Exception as e:
            print >> sys.stderr, "Could not load manifest from %s: %s" % (manifest, str(e))
            return False
    else:
        try:
            cur = Configuration.SystemManifest()
        except:
            print >> sys.stderr, "Cannot get system manifest"
            return False
    if cur is None or cur.Packages() is None:
        raise Exception("Cannot load configuration")

    print "Want to install into %s" % root
    #
    # To install, we have to grab each package in the manifest,
    # and install them into the specified root directory.
    # When we are done, we write out the system manifest into
    # the manifest directory.
    for pkg in cur.Packages():
        print "Package %s" % pkg.Name()
        filename = Manifest.FormatName(pkg.Name(), pkg.Version())
        f = conf.FindPackage(filename, pkg.Checksum())
        if f is None:
            print >> sys.stderr, "\tCould not find package file for %s" % filename
            return False
        else:
            if Installer.install_file(f, root) == False:
                print >> sys.stderr, "Could not install package %s" % filename
                return False
            else:
                print "%s installed" % pkg.Name()
    conf.StoreManifest(cur, root)

    return True
Пример #4
0
    def PackageForSequence(self, sequence, name=None):
        """
        For a given sequence, return the package for it.
        If name is None, then return all the packages for
        that sequence.

        """

        sql = """
        SELECT PkgName, PkgVersion, Checksum
        FROM Manifests
        JOIN Packages
        JOIN Sequences
        WHERE Sequences.Sequence = ?
        AND Manifests.Sequence = Sequences.indx
        AND Manifests.Pkg = Packages.indx
        %s
        ORDER BY Packages.indx ASC
        """ % ("AND Packages.PkgName = ?" if name else "")

        if name:
            parms = (sequence, name)
        else:
            parms = (sequence, )

        if debug:
            print >> sys.stderr, "sql = `%s', parms = `%s'" % (sql, parms)
        self.cursor().execute(sql, parms)
        packages = self.cursor().fetchall()
        rv = []
        for pkg in packages:
            if debug:
                print >> sys.stderr, "Found package %s-%s" % (
                    pkg['PkgName'], pkg['PkgVersion'])
            p = Package.Package(pkg["PkgName"], pkg["PkgVersion"], None)
            rv.append(p)
        if rv and name:
            if len(rv) > 1:
                raise Exception(
                    "Too many results for package %s:  expected 1, got %d" %
                    (name, len(rv)))
            return rv[0]
        return rv
Пример #5
0
 def PackageForSequence(self, sequence, name=None):
     """
     For a given sequence, return the package for it.
     If name is none, return all of the packages for that
     sequence.
     We do this by opening _dbpath/sequences/$sequence,
     and os.listdirs if name is None
     """
     if debug:
         print >> sys.stderr, "FSReleaseDB::PackageForSequence(%s, %s)" % (
             sequence, name)
     sdir = "%s/sequences/%s" % (self._dbpath, sequence)
     if name:
         pkgs = (name, )
     else:
         pkgs = os.listdir(sdir)
     rv = []
     for pkg in pkgs:
         # sdir/pkg is a symlink to the package version.
         # The contents, if any, are a checksum
         if debug:
             print >> sys.stderr, "FSReleaseDB::PackageForSequence(%s, %s):  pkg = %s" % (
                 sequence, name, pkg)
         pkgfile = sdir + "/" + pkg
         pkg_version = os.path.basename(os.readlink(pkgfile))
         if debug:
             print >> sys.stderr, "\tpkgfile = %s, pkg_version = %s" % (
                 pkgfile, pkg_version)
         with open(pkgfile, "r") as f:
             cksum = f.read()
             if not cksum:
                 cksum = None
         P = Package.Package(pkg, pkg_version, cksum)
         if debug:
             print >> sys.stderr, "\tP = %s-%s" % (P.Name(), P.Version())
         rv.append(P)
     if rv and name:
         if len(rv) > 1:
             raise Exception(
                 "Too many results for packge %s:  expected 1, got %d" %
                 (P.Name(), len(rv)))
         return rv[0]
     return rv
Пример #6
0
            hash = Configuration.ChecksumFile(pkgfile)
            size = os.lstat(P).st_size
            try:
                services = pkg_json[PF.kPkgServicesKey]
            except:
                print("%s is not in pkg_json" % PF.kPkgServicesKey,
                      file=sys.stderr)
                services = None
            try:
                rr = pkg_json[PF.kPkgRebootKey]
            except:
                rr = None

            pkg = Package.Package({
                Package.NAME_KEY: name,
                Package.VERSION_KEY: version,
                Package.CHECKSUM_KEY: hash,
                Package.SIZE_KEY: size,
            })

            if rr is not None:
                print("rr = %s" % rr, file=sys.stderr)
                pkg.SetRequiresReboot(rr)
                if rr is False:
                    # Let's see if we have any services which are restarted by default.
                    print("services = %s" % services, file=sys.stderr)
                    if services and "Restart" in services:
                        # Services has two entries, we want the restart one
                        svcs = services["Restart"]
                        if len(svcs) > 0:
                            print("Restart Services = %s" % list(svcs.keys()),
                                  file=sys.stderr)
Пример #7
0
    if package_dir is not None:
        conf.SetPackageDir(package_dir)
        
    for P in pkgs:
        # Need to parse the name, which is pkg=version[:upgrade,upgrade,upgrade]
        upgrades = []
        if ":" in P:
            (P, tmp) = P.split(":")
            if "," in tmp:
                upgrades = tmp.split(",")
            else:
                upgrades.append(tmp)
        if "=" not in P:
            usage()
        (name, version) = P.split("=")
        pkg = Package.Package(name, version, None)
        pkgname = pkg.FileName()
        print "Package file name is %s" % pkgname
        pkgfile = conf.FindPackageFile(pkg)
        hash = None
        if pkgfile is not None:
            hash = ChecksumFile(pkgfile)
            pkgfile.seek(0, os.SEEK_END)
            size = pkgfile.tell()
            pkg.SetSize(size)
            pkgfile.seek(0)
        else:
            print >> sys.stderr, "Can't find file for %s" % name

        pkg.SetChecksum(hash)
        for U in upgrades: