def installArchive(ar): if ar.getClass() != t.BINARY: raise Syn.errors.InvalidArchiveException( "Need a binary package to install" ) metainf = ar.getConf(g.SYN_BINARY_META) pkg = metainf['package'] ver = metainf['version'] l.l(l.LOG,"Installing package %s, version %s" % (pkg, ver)) db = Syn.db.loadCanonicalDB() try: state = db.queryState(pkg, ver) l.l(l.LOG,"Oh shit. We have a hit on this package") if state['status'] != Syn.db.UNINSTALLED: raise Syn.errors.PackageInstalledException("Package already in the DB. Please purge") l.l(l.LOG,"Package is uninstalled. Phew.") except Syn.errors.PackageNotFoundException as e: l.l(l.LOG,"Package not found. Good. We may continue.") db.registerNewPackage(pkg, ver, Syn.db.UNINSTALLED) db.sync() l.l(l.LOG,"Moving on with the package install") # XXX: Someone fix below this, please. # use Syn.fspkg.fspkg() c.cd(Syn.reg.CHROOT + g.INSTALL_ROOT_PATH) if not c.xists(pkg): c.mkdir(pkg) c.cd(pkg) db.setState(pkg,ver,Syn.db.HALF_INSTALLED) db.sync() if c.xists(ver): raise Syn.errors.PackageInstalledException("Package already in the FS. Please purge") c.mkdir(ver) c.cd(ver) # XXX: Above this ar.extractall() for path in g.SYN_BIN_TO_XTRACT: c.mv(path, g.SYN_BIN_TO_XTRACT[path]) db.setState(pkg,ver,Syn.db.INSTALLED) db.sync()
def unlinkPkg(pkg, ver): root="/" db = Syn.db.loadCanonicalDB() if Syn.reg.CHROOT != root: Syn.log.l(Syn.log.PEDANTIC,"Dumping into chroot for real (%s)" % Syn.reg.CHROOT) os.chroot(Syn.reg.CHROOT) Syn.log.l(Syn.log.PEDANTIC,"Swaping chroot out to /") Syn.reg.CHROOT = "/" Syn.reg.CHROOT_TOUCHED = True Syn.log.l(Syn.log.PEDANTIC,"Re-loading DB") db = Syn.db.loadCanonicalDB() Syn.log.l(Syn.log.MESSAGE, "Uninking " + pkg + ", version " + ver) status = db.queryState(pkg,ver) Syn.log.l(Syn.log.VERBOSE, "Status: %s" % status['status']) if status['status'] != Syn.db.LINKED: Syn.log.l(Syn.log.CRITICAL, "Package is not linked. Damnit!") raise Syn.errors.PackageNotinstalledException("Not linked: %s version %s" % (pkg, ver)) else: status = db.queryGState(pkg) if status['linked'] != ver: Syn.log.l(Syn.log.LOG, "Different version linked!") raise Syn.errors.ConflictException("Different version Linked") Syn.log.l(Syn.log.LOG, "Package is linked. We can unlink it!") fpkg = Syn.fspkg.fspkg(pkg, ver) fslist = fpkg.getAllFiles() errors = 0 for f in fslist: filespec = f[len(g.ARCHIVE_FS_ROOT):] if c.xists(root + filespec) and not c.isln(root + filespec): Syn.log.l(Syn.log.LOG, "Errorful: %s" % filespec) errors += 1 if errors != 0: Syn.log.l(Syn.log.LOG, "Errors found :(") raise Syn.errors.ConflictException("Link conflicts!") db.setState(pkg,ver,Syn.db.HALF_LINKED) db.sync() for f in fslist: filespec = f[len(g.ARCHIVE_FS_ROOT):] #try: c.fs_unln_inst(root+filespec) #except OSError as e: # Syn.log.l(Syn.log.LOG, "OS Error: %s" % str(e)) db.setUnlinked(pkg,ver) db.sync()
def linkPkg(pkg, ver): root = "/" db = Syn.db.loadCanonicalDB() if Syn.reg.CHROOT != root: Syn.log.l(Syn.log.PEDANTIC,"Dumping into chroot for real (%s)" % Syn.reg.CHROOT) os.chroot(Syn.reg.CHROOT) Syn.log.l(Syn.log.PEDANTIC,"Swaping chroot out to /") Syn.reg.CHROOT = "/" Syn.reg.CHROOT_TOUCHED = True Syn.log.l(Syn.log.PEDANTIC,"Re-loading DB") db = Syn.db.loadCanonicalDB() Syn.log.l(Syn.log.MESSAGE, "Linking " + pkg + ", version " + ver) db = Syn.db.loadCanonicalDB() status = db.queryState(pkg,ver) if status['status'] != Syn.db.INSTALLED: Syn.log.l(Syn.log.CRITICAL, "Package is not installed. Damnit!") raise Syn.errors.PackageNotinstalledException("Not installed: %s version %s" % (pkg, ver)) else: status = db.queryGState(pkg) if status['linked'] != None: Syn.log.l(Syn.log.LOG, "Different version linked!") raise Syn.errors.ConflictException("Different version Linked") Syn.log.l(Syn.log.LOG, "Package is installed. We can link it!") fpkg = Syn.fspkg.fspkg(pkg, ver) fslist = fpkg.getAllFiles() errors = 0 for f in fslist: filespec = f[len(g.ARCHIVE_FS_ROOT):] if c.xists(root + filespec): Syn.log.l(Syn.log.LOG, "File in confict! %s" % filespec) errors += 1 if errors != 0: raise Syn.errors.ConflictException("Link conflicts!") db.setState(pkg,ver,Syn.db.HALF_LINKED) db.sync() for f in fslist: pkg_root = fpkg.getInstallPath() fs_root = root filespec = f[len(g.ARCHIVE_FS_ROOT):] c.fs_ln_inst(pkg_root + f, root + filespec) db.setLinked(pkg,ver) db.sync()
def package(metainf): for x in g.SYN_SRC_TO_BIN_FILESPEC: c.cp(x, "../" + g.SYN_SRC_TO_BIN_FILESPEC[x]) c.cd("..") for x in g.INSTALL_BLACKLIST: Syn.log.l(Syn.log.LOG,"checking blacklisted file: %s" % x) if c.xists(g.ARCHIVE_FS_ROOT_NOSLASH + x): Syn.log.l(Syn.log.LOG,"Removing: %s (blacklist)" % x) c.rm(g.ARCHIVE_FS_ROOT_NOSLASH + x) files = c.md5sumwd(g.ARCHIVE_FS_ROOT_NOSLASH) output = json.dumps(files, sort_keys = True, indent = 4) f = open(g.ARCHIVE_FS_ROOT + "/" + g.SYN_BINARY_FILESUMS, 'w') f.write(output) f.close() pkg = metainf['package'] ver = metainf['version'] b_pth = pkg + "-" + ver + "." + g.SYN_BIN_PKG_XTN l_pth = pkg + "-" + ver + "." + g.SYN_LOG_PKG_XTN ar = t.newArchive( [ g.ARCHIVE_FS_ROOT ], b_pth, t.BINARY ) ( r_errs, n_errs, g_errs ) = Syn.synlint.runCheck(b_pth) errs = "Errors (on the binary)\n" errs += "\n" errs += "Report for:" errs += " " + pkg + "-" + ver errs += "\n" errs += " Serious: " + str(r_errs) + "\n" errs += " Important: " + str(n_errs) + "\n" errs += " Pedantic: " + str(g_errs) + "\n" errs += "\n" logLog("./", "synlint", errs) ar = t.newArchive( [ g.LOG_FS_ROOT ], l_pth, t.UNKNOWN ) return ( b_pth, l_pth )
def forceUnlinkHalfLinkedPkg(pkg, ver): root="/" db = Syn.db.loadCanonicalDB() if Syn.reg.CHROOT != root: Syn.log.l(Syn.log.PEDANTIC,"Dumping into chroot for real (%s)" % Syn.reg.CHROOT) os.chroot(Syn.reg.CHROOT) Syn.log.l(Syn.log.PEDANTIC,"Swaping chroot out to /") Syn.reg.CHROOT = "/" Syn.reg.CHROOT_TOUCHED = True Syn.log.l(Syn.log.PEDANTIC,"Re-loading DB") db = Syn.db.loadCanonicalDB() Syn.log.l(Syn.log.MESSAGE, "Uninking " + pkg + ", version " + ver) status = db.queryState(pkg,ver) Syn.log.l(Syn.log.VERBOSE, "Status: %s" % status['status']) if status['status'] != Syn.db.HALF_LINKED: Syn.log.l(Syn.log.CRITICAL, "Package is not half-linked. Damnit!") raise Syn.errors.PackageNotinstalledException("Not half-linked: %s version %s" % (pkg, ver)) else: fpkg = Syn.fspkg.fspkg(pkg, ver) fslist = fpkg.getAllFiles() errors = 0 for f in fslist: filespec = f[len(g.ARCHIVE_FS_ROOT):] if c.xists(root + filespec) and not c.isln(root + filespec): Syn.log.l(Syn.log.LOG, "Errorful: %s" % filespec) errors += 1 if errors != 0: Syn.log.l(Syn.log.LOG, "Errors found :(") Syn.log.l(Syn.log.LOG, "We're going to plow through.") for f in fslist: filespec = f[len(g.ARCHIVE_FS_ROOT):] try: c.fs_unln_inst(root+filespec) except OSError as e: Syn.log.l(Syn.log.LOG, "OS Error: %s" % str(e)) Syn.log.l(Syn.log.LOG, "Ignoring.") db.setUnlinked(pkg,ver) db.sync()