def blankFile(self): """ `blankFile` simply blanks out the bfile loaded. """ l.l(l.PEDANTIC,"creating blank file: %s" % self.file) self.setContent("") self.write()
def buildSourcePackage(package): ret = 0 ar = t.archive(package) klass = ar.getClass() pop = os.path.abspath(os.getcwd()) if klass != t.SOURCE: l.l(l.CRITICAL, "Archive is not a source package") return -1 l.l(l.PEDANTIC, "Archive is sourceful. May continue") build_root = c.getTempLocation() c.mkdir(build_root) c.cd(build_root) try: (build, logs) = Syn.build.build(ar) c.cp(build, pop + "/" + build) c.cp(logs, pop + "/" + logs) ret = 0 except Syn.errors.BuildFailureException as e: l.l(l.CRITICAL, "Failure to build!") l.l(l.CRITICAL, "Check the package build root in /tmp/syn, plox") l.l(l.CRITICAL, str(e)) ret = -2 return ret # f**k removing the dir c.rmdir(build_root) return ret
def blankFile(self): """ @see: bfile.bfile.blankFile """ l.l(l.PEDANTIC,"creating blank file: %s" % self.file) self.setContent({}) self.write()
def setContent(self, content): """ `setContent` sets the content of the cache, klobbering what was there before. @arg content: content to cache, and prepare for write. """ self.content = content l.l(l.PEDANTIC,"Setting internal cache: %s" % self.file)
def update(self): """ @see: bfile.bfile.update """ l.l(l.PEDANTIC,"Updating JSON file: %s" % self.file) f = gzip.open(self.file, 'rb') self.setContent(json.loads(f.read())) f.close()
def write(self): """ @see: bfile.bfile.write """ l.l(l.PEDANTIC,"Writing JSON file: %s" % self.file) f = gzip.open(self.file, 'wb') f.write(json.dumps(self.getContent())) f.close()
def write(self): """ `write` writes the cached file to the filesystem, overwriting whatever was on that file moments ago. """ l.l(l.PEDANTIC,"Writing file: %s" % self.file) f = gzip.open(self.file, 'wb') f.write(self.getContent()) f.close()
def update(self): """ `update` syncs the file in the filesystem into this object, if the file has been written while the file has been cached in memory. """ l.l(l.PEDANTIC,"Updating file: %s" % self.file) f = gzip.open(self.file, 'rb') self.setContent(f.read()) f.close()
def __loaddb(self, path): """ Load a database into the cache. Called by the constructor. """ try: self.ff = flatfile.json_bfile(path) except IOError as e: l.l(l.CRITICAL,"Database does not exist.") raise Syn.exceptions.SynDirectoryFailure("%s does not exist." % path)
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 __init__(self, fil): """ Simple constructor. @arg fil: File to load, or create if it does not exist. """ self.file = fil l.l(l.PEDANTIC,"Using file: %s" % fil) try: self.update() l.l(l.PEDANTIC,"existing file loaded: %s" % fil) except IOError as e: # OK, we need to create it. self.blankFile()
def genLibraryLinks(ar): if ar.getClass() != t.BINARY: l.l(l.PEDANTIC, "Not running library checks -- tis a source package.") return None wd = os.getcwd() workdir = Syn.common.getTempLocation() Syn.common.mkdir(workdir) Syn.common.cd(workdir) crappy = ar.getRootFolder() ar.extractall() Syn.common.cd(crappy) mapers = Syn.common.md5sumwd(".") lds = {} for f in mapers: fpath = f[1:] # remove the . (bin, local) = Syn.common.isInPath(fpath) if bin: l.l(l.PEDANTIC, f) (status, spew) = Syn.s.run("syn-ldd " + f) l.l(l.PEDANTIC, " S-> " + spew) if status != 0: spew = "[]" # default to nil lds[fpath] = json.loads(spew) Syn.common.cd(wd) Syn.common.rmdir(workdir) return lds
def uninstallArchive(pkg, ver): db = Syn.db.loadCanonicalDB() try: state = db.queryState(pkg, ver) if state['status'] != Syn.db.INSTALLED: raise Syn.errors.PackageUninstalledException("Package is not installed") l.l(l.LOG,"Package is installed. Phew.") except Syn.errors.PackageNotFoundException as e: l.l(l.LOG,"Package not found. Crap") raise e l.l(l.LOG,"Moving on with the package uninstall") # XXX: Someone fix below this, please. # use Syn.fspkg.fspkg() c.cd(Syn.reg.CHROOT + g.INSTALL_ROOT_PATH) c.cd(pkg) db.setState(pkg,ver,Syn.db.HALF_INSTALLED) db.sync() c.rmdir(ver) db.setState(pkg,ver,Syn.db.UNINSTALLED) db.sync()
def build(ar): l.l(l.PEDANTIC,"Extracting archive") ar.extractall() l.l(l.PEDANTIC,"Archive extracted") root = os.path.abspath(os.getcwd()) l.l(l.PEDANTIC,"Current root: %s" % ( root )) metainf = ar.getConf(g.SYN_SRC_DIR + g.SYN_BUILDDIR_META) pkg = metainf['package'] ver = metainf['version'] script = os.path.abspath( pkg + "-" + ver + "/" + g.SYN_SRC_DIR + g.SYN_BUILDDIR_SCRIPT ) l.l(l.PEDANTIC, "Maintainer is %s <%s>" % ( metainf['maintainer']['name'], metainf['maintainer']['email'] ) ) l.l(l.PEDANTIC,"Building %s version %s" % ( pkg, ver )) c.cd(pkg + "-" + ver) download = ar.getConf(g.SYN_SRC_DIR + g.SYN_BUILDDIR_META)['download'] sourceball = os.path.basename(download) upstream_archive = t.archive(sourceball) upstream_archive.extractall() hackdir = upstream_archive.getRootFolder() l.l(l.MESSAGE,"Root directory resolved as: " + hackdir) c.cd(hackdir) setupBuildEnv(ar) Syn.s.putenv(g.DESTDIR, root + "/" + g.ARCHIVE_FS_ROOT) c.mkdir(root + "/" + g.ARCHIVE_FS_ROOT) c.mkdir(root + "/" + g.LOG_FS_ROOT) try: ( scriptStatus, clog, blog, slog ) = callScript(script) logLog(root, "configure", clog) logLog(root, "build", blog) logLog(root, "stage", slog) if scriptStatus != 0: l.l(l.CRITICAL,"*****") l.l(l.CRITICAL,"FTBFS DETECTED!!!") l.l(l.CRITICAL,"*****") raise Syn.errors.BuildFailureException("FTBFS") except KeyboardInterrupt as e: raise Syn.errors.BuildFailureException("User abort.") c.cd("..") ( binary, log ) = package(metainf) return ( binary, log )
def sourceCheck( ar ): metafile = ar.getConf(g.SYN_SRC_DIR + g.SYN_BUILDDIR_META) policy = metafile["policy"] r_errs = checkFields(Syn.policy.META_REQUIRED, metafile, policy) n_errs = checkFields(Syn.policy.META_NEEDED, metafile, policy) g_errs = checkFields(Syn.policy.META_GOODTOHAVE, metafile, policy) if policy >= Syn.policy.META_REQUIRED["section"]: section = metafile["section"] try: section_flags = Syn.policy.SECTION_REQUIRED[section] r_errs += checkFields( section_flags, metafile, policy) except KeyError as e: l.l(l.MESSAGE,"") l.l(l.MESSAGE,"=== Potential issue! ===") l.l(l.MESSAGE,"No section checks on `" + section + "'") l.l(l.MESSAGE," Either this is brand new and no checks") l.l(l.MESSAGE," have been written, or this is a shitty") l.l(l.MESSAGE," section.") l.l(l.MESSAGE,"") n_errs += checkVersion(metafile) return ( r_errs, n_errs, g_errs )
def metafileCheck(ar): if ar.getClass() == t.BINARY: ( r_errs, n_errs, g_errs ) = binaryCheck(ar) elif ar.getClass() == t.SOURCE: ( r_errs, n_errs, g_errs ) = sourceCheck(ar) else: l.l(l.CRITICAL,"WTF Is this I don't even") raise Syn.errors.InvalidArchiveException("Unknown audit.") sane = False clean = False if r_errs + n_errs == 0: sane = True clean = True if r_errs == 0: sane = True l.l(l.MESSAGE,"Errors:") l.l(l.MESSAGE,"") l.l(l.MESSAGE," Serious: " + str(r_errs)) l.l(l.MESSAGE," Important: " + str(n_errs)) l.l(l.MESSAGE," Pedantic: " + str(g_errs)) l.l(l.MESSAGE,"") if clean: l.l(l.MESSAGE,"This package is acceptable to build. Check with") l.l(l.MESSAGE," your friendly project developer about it's archive") l.l(l.MESSAGE," status.") l.l(l.MESSAGE,"") elif sane: l.l(l.MESSAGE,"This package is acceptable for basic, unofficial use.") l.l(l.MESSAGE," It's not in shipp-able format, but it's OK to use") l.l(l.MESSAGE," locally.") l.l(l.MESSAGE,"") else: l.l(l.MESSAGE,"This package is *NOT* acceptable for something as") l.l(l.MESSAGE," simple as a simple install. Please fix the issues above.") l.l(l.MESSAGE,"") return ( r_errs, n_errs, g_errs )
def gensum(ar): if ar.getClass() != t.BINARY: raise Syn.errors.InvalidArchiveException("Not a binary package") metafile = ar.getConf(g.SYN_BINARY_FILESUMS) report = {"binary": {}, "local-binary": {}, "lib": {}, "local-lib": {}} for x in metafile: bpath = "/" + x[len(g.ARCHIVE_FS_ROOT) :] (path, good) = Syn.common.isInPath(bpath) if path: goodie = os.path.basename(bpath) l.l(l.MESSAGE, "New binary! " + goodie) if good: report["binary"][goodie] = goodie l.l(l.PEDANTIC, "New real binary") else: l.l(l.PEDANTIC, "New kludge binary") report["local-binary"][goodie] = goodie (path, good) = Syn.common.isInLibPath(bpath) if path: goodie = os.path.basename(bpath) l.l(l.MESSAGE, "New library! " + goodie) if good: report["lib"][goodie] = goodie l.l(l.PEDANTIC, "New real lib") else: l.l(l.PEDANTIC, "New kludge lib") report["local-lib"][goodie] = goodie return report
def readConfFile(f): l.l(l.PEDANTIC,"Reading Conf: " + f) meta = open(f) return json.loads(meta.read())