def install_package(self, root): """Install the package in the given root.""" for f in self.files: util.mkfile(root, f, f) path = os.path.join(root, f) if os.path.isfile(path): os.utime(path, (355, 355))
def generate(self): pkg_entries = [(pkg, self.db_write(pkg)) for pkg in self.pkgs] if self.dbdir: for pkg, entry in pkg_entries: path = os.path.join(self.dbdir, pkg.fullname()) util.mkdir(path) for name, data in entry.iteritems(): filename = os.path.join(path, name) util.mkfile(filename, data) if self.dbfile: tar = tarfile.open(self.dbfile, "w:gz") for pkg, entry in pkg_entries: # TODO: the addition of the directory is currently a # requirement for successful reading of a DB by libalpm info = tarfile.TarInfo(pkg.fullname()) info.type = tarfile.DIRTYPE tar.addfile(info) for name, data in entry.iteritems(): filename = os.path.join(pkg.fullname(), name) info = tarfile.TarInfo(filename) info.size = len(data) tar.addfile(info, StringIO(data)) tar.close() # TODO: this is a bit unnecessary considering only one test uses it serverpath = os.path.join(self.root, util.SYNCREPO, self.treename) util.mkdir(serverpath) shutil.copy(self.dbfile, serverpath)
def makepkg(self, path): """Creates an Arch Linux package archive. A package archive is generated in the location 'path', based on the data from the object. """ self.path = os.path.join(path, self.filename()) curdir = os.getcwd() tmpdir = tempfile.mkdtemp() os.chdir(tmpdir) # Generate package file system for f in self.files: util.mkfile(f, f) self.size += os.lstat(self.parse_filename(f))[stat.ST_SIZE] # .PKGINFO data = ["pkgname = %s" % self.name] data.append("pkgver = %s" % self.version) data.append("pkgdesc = %s" % self.desc) data.append("url = %s" % self.url) data.append("builddate = %s" % self.builddate) data.append("packager = %s" % self.packager) data.append("size = %s" % self.size) if self.arch: data.append("arch = %s" % self.arch) for i in self.license: data.append("license = %s" % i) for i in self.replaces: data.append("replaces = %s" % i) for i in self.groups: data.append("group = %s" % i) for i in self.depends: data.append("depend = %s" % i) for i in self.optdepends: data.append("optdepend = %s" % i) for i in self.conflicts: data.append("conflict = %s" % i) for i in self.provides: data.append("provides = %s" % i) for i in self.backup: data.append("backup = %s" % i) util.mkfile(".PKGINFO", "\n".join(data)) # .INSTALL if any(self.install.values()): util.mkfile(".INSTALL", self.installfile()) # safely create the dir util.mkdir(os.path.dirname(self.path)) # Generate package archive tar = tarfile.open(self.path, "w:gz") for i in os.listdir("."): tar.add(i) tar.close() os.chdir(curdir) shutil.rmtree(tmpdir)
def generate(self, pacman): print "==> Generating test environment" # Cleanup leftover files from a previous test session if os.path.isdir(self.root): shutil.rmtree(self.root) vprint("\t%s" % self.root) # Create directory structure vprint(" Creating directory structure:") dbdir = os.path.join(self.root, util.PM_SYNCDBPATH) cachedir = os.path.join(self.root, util.PM_CACHEDIR) syncdir = os.path.join(self.root, util.SYNCREPO) tmpdir = os.path.join(self.root, util.TMPDIR) logdir = os.path.join(self.root, os.path.dirname(util.LOGFILE)) etcdir = os.path.join(self.root, os.path.dirname(util.PACCONF)) bindir = os.path.join(self.root, "bin") ldconfig = os.path.basename(pacman["ldconfig"]) ldconfigdir = os.path.join(self.root, os.path.dirname(pacman["ldconfig"][1:])) shell = pacman["scriptlet-shell"][1:] shelldir = os.path.join(self.root, os.path.dirname(shell)) sys_dirs = [dbdir, cachedir, syncdir, tmpdir, logdir, etcdir, bindir, ldconfigdir, shelldir] for sys_dir in sys_dirs: if not os.path.isdir(sys_dir): vprint("\t%s" % sys_dir[len(self.root)+1:]) os.makedirs(sys_dir, 0755) # Only the dynamically linked binary is needed for fakechroot shutil.copy("/bin/sh", bindir) if shell != "bin/sh": shutil.copy("/bin/sh", os.path.join(self.root, shell)) shutil.copy(os.path.join(util.SELFPATH, "ldconfig.stub"), os.path.join(ldconfigdir, ldconfig)) ld_so_conf = open(os.path.join(etcdir, "ld.so.conf"), "w") ld_so_conf.close() # Configuration file vprint(" Creating configuration file") util.mkcfgfile(util.PACCONF, self.root, self.option, self.db) # Creating packages vprint(" Creating package archives") for pkg in self.localpkgs: vprint("\t%s" % os.path.join(util.TMPDIR, pkg.filename())) pkg.finalize() pkg.makepkg(tmpdir) for key, value in self.db.iteritems(): for pkg in value.pkgs: pkg.finalize() if key == "local" and not self.createlocalpkgs: continue for pkg in value.pkgs: vprint("\t%s" % os.path.join(util.PM_CACHEDIR, pkg.filename())) if self.cachepkgs: pkg.makepkg(cachedir) else: pkg.makepkg(os.path.join(syncdir, value.treename)) pkg.md5sum = util.getmd5sum(pkg.path) pkg.csize = os.stat(pkg.path)[stat.ST_SIZE] # Creating sync database archives vprint(" Creating databases") for key, value in self.db.iteritems(): vprint("\t" + value.treename) value.generate() # Filesystem vprint(" Populating file system") for f in self.filesystem: vprint("\t%s" % f) util.mkfile(self.root, f, f) path = os.path.join(self.root, f) if os.path.isfile(path): os.utime(path, (355, 355)) for pkg in self.db["local"].pkgs: vprint("\tinstalling %s" % pkg.fullname()) pkg.install_package(self.root) # Done. vprint(" Taking a snapshot of the file system") for roots, dirs, files in os.walk(self.root): for i in files: filename = os.path.join(roots, i) f = pmfile.PacmanFile(self.root, filename.replace(self.root + "/", "")) self.files.append(f) vprint("\t%s" % f.name)
def generate(self, pacman): tap.diag("==> Generating test environment") # Cleanup leftover files from a previous test session if os.path.isdir(self.root): shutil.rmtree(self.root) vprint("\t%s" % self.root) # Create directory structure vprint(" Creating directory structure:") dbdir = os.path.join(self.root, util.PM_SYNCDBPATH) cachedir = os.path.join(self.root, util.PM_CACHEDIR) syncdir = os.path.join(self.root, util.SYNCREPO) tmpdir = os.path.join(self.root, util.TMPDIR) logdir = os.path.join(self.root, os.path.dirname(util.LOGFILE)) etcdir = os.path.join(self.root, os.path.dirname(util.PACCONF)) bindir = os.path.join(self.root, "bin") shell = pacman["scriptlet-shell"][1:] shelldir = os.path.join(self.root, os.path.dirname(shell)) sys_dirs = [dbdir, cachedir, syncdir, tmpdir, logdir, etcdir, bindir, shelldir] for sys_dir in sys_dirs: if not os.path.isdir(sys_dir): vprint("\t%s" % sys_dir[len(self.root)+1:]) os.makedirs(sys_dir, 0o755) # Only the dynamically linked binary is needed for fakechroot shutil.copy("/bin/sh", bindir) if shell != "bin/sh": shutil.copy("/bin/sh", os.path.join(self.root, shell)) # Configuration file vprint(" Creating configuration file") util.mkcfgfile(util.PACCONF, self.root, self.option, self.db) # Creating packages vprint(" Creating package archives") for pkg in self.localpkgs: vprint("\t%s" % os.path.join(util.TMPDIR, pkg.filename())) pkg.finalize() pkg.makepkg(tmpdir) for key, value in self.db.items(): for pkg in value.pkgs: pkg.finalize() if key == "local" and not self.createlocalpkgs: continue for pkg in value.pkgs: vprint("\t%s" % os.path.join(util.PM_CACHEDIR, pkg.filename())) if self.cachepkgs: pkg.makepkg(cachedir) else: pkg.makepkg(os.path.join(syncdir, value.treename)) pkg.md5sum = util.getmd5sum(pkg.path) pkg.csize = os.stat(pkg.path)[stat.ST_SIZE] # Creating sync database archives vprint(" Creating databases") for key, value in self.db.items(): vprint("\t" + value.treename) value.generate() # Filesystem vprint(" Populating file system") for f in self.filesystem: if type(f) is pmfile.pmfile: vprint("\t%s" % f.path) f.mkfile(self.root); else: vprint("\t%s" % f) path = util.mkfile(self.root, f, f) if os.path.isfile(path): os.utime(path, (355, 355)) for pkg in self.db["local"].pkgs: vprint("\tinstalling %s" % pkg.fullname()) pkg.install_package(self.root) if self.db["local"].pkgs and self.dbver >= 9: path = os.path.join(self.root, util.PM_DBPATH, "local") util.mkfile(path, "ALPM_DB_VERSION", str(self.dbver)) # Done. vprint(" Taking a snapshot of the file system") for filename in self.snapshots_needed(): f = pmfile.snapshot(self.root, filename) self.files.append(f) vprint("\t%s" % f.name)
def install_package(self, root): """Install the package in the given root.""" for f in self.files: path = util.mkfile(root, f, f) if os.path.isfile(path): os.utime(path, (355, 355))
def generate(self): print "==> Generating test environment" # Cleanup leftover files from a previous test session if os.path.isdir(self.root): shutil.rmtree(self.root) vprint("\t%s" % self.root) # Create directory structure vprint(" Creating directory structure:") dbdir = os.path.join(self.root, util.PM_SYNCDBPATH) cachedir = os.path.join(self.root, util.PM_CACHEDIR) syncdir = os.path.join(self.root, util.SYNCREPO) tmpdir = os.path.join(self.root, util.TMPDIR) logdir = os.path.join(self.root, os.path.dirname(util.LOGFILE)) etcdir = os.path.join(self.root, os.path.dirname(util.PACCONF)) bindir = os.path.join(self.root, "bin") sbindir = os.path.join(self.root, "sbin") sys_dirs = [ dbdir, cachedir, syncdir, tmpdir, logdir, etcdir, bindir, sbindir ] for sys_dir in sys_dirs: if not os.path.isdir(sys_dir): vprint("\t%s" % sys_dir[len(self.root) + 1:]) os.makedirs(sys_dir, 0755) # Only the dynamically linked binary is needed for fakechroot shutil.copy("/bin/sh", bindir) shutil.copy(os.path.join(util.SELFPATH, "ldconfig.stub"), os.path.join(sbindir, "ldconfig")) ld_so_conf = open(os.path.join(etcdir, "ld.so.conf"), "w") ld_so_conf.close() # Configuration file vprint(" Creating configuration file") util.mkcfgfile(util.PACCONF, self.root, self.option, self.db) # Creating packages vprint(" Creating package archives") for pkg in self.localpkgs: vprint("\t%s" % os.path.join(util.TMPDIR, pkg.filename())) pkg.makepkg(tmpdir) for key, value in self.db.iteritems(): if key == "local" and not self.createlocalpkgs: continue for pkg in value.pkgs: vprint("\t%s" % os.path.join(util.PM_CACHEDIR, pkg.filename())) if self.cachepkgs: pkg.makepkg(cachedir) else: pkg.makepkg(os.path.join(syncdir, value.treename)) pkg.md5sum = util.getmd5sum(pkg.path) pkg.csize = os.stat(pkg.path)[stat.ST_SIZE] # Creating sync database archives vprint(" Creating databases") for key, value in self.db.iteritems(): vprint("\t" + value.treename) value.generate() # Filesystem vprint(" Populating file system") for pkg in self.db["local"].pkgs: vprint("\tinstalling %s" % pkg.fullname()) pkg.install_package(self.root) for f in self.filesystem: vprint("\t%s" % f) util.mkfile(self.root, f, f) path = os.path.join(self.root, f) if os.path.isfile(path): os.utime(path, (355, 355)) # Done. vprint(" Taking a snapshot of the file system") for roots, dirs, files in os.walk(self.root): for i in files: filename = os.path.join(roots, i) f = pmfile.PacmanFile(self.root, filename.replace(self.root + "/", "")) self.files.append(f) vprint("\t%s" % f.name)
def generate(self, pacman): tap.diag("==> Generating test environment") # Cleanup leftover files from a previous test session if os.path.isdir(self.root): shutil.rmtree(self.root) vprint("\t%s" % self.root) # Create directory structure vprint(" Creating directory structure:") dbdir = os.path.join(self.root, util.PM_SYNCDBPATH) cachedir = os.path.join(self.root, util.PM_CACHEDIR) syncdir = os.path.join(self.root, util.SYNCREPO) tmpdir = os.path.join(self.root, util.TMPDIR) logdir = os.path.join(self.root, os.path.dirname(util.LOGFILE)) etcdir = os.path.join(self.root, os.path.dirname(util.PACCONF)) bindir = os.path.join(self.root, "bin") ldconfig = os.path.basename(pacman["ldconfig"]) ldconfigdir = os.path.join(self.root, os.path.dirname(pacman["ldconfig"][1:])) shell = pacman["scriptlet-shell"][1:] shelldir = os.path.join(self.root, os.path.dirname(shell)) sys_dirs = [dbdir, cachedir, syncdir, tmpdir, logdir, etcdir, bindir, ldconfigdir, shelldir] for sys_dir in sys_dirs: if not os.path.isdir(sys_dir): vprint("\t%s" % sys_dir[len(self.root)+1:]) os.makedirs(sys_dir, 0o755) # Only the dynamically linked binary is needed for fakechroot shutil.copy("/bin/sh", bindir) if shell != "bin/sh": shutil.copy("/bin/sh", os.path.join(self.root, shell)) shutil.copy(os.path.join(util.SELFPATH, "ldconfig.stub"), os.path.join(ldconfigdir, ldconfig)) ld_so_conf = open(os.path.join(etcdir, "ld.so.conf"), "w") ld_so_conf.close() # Configuration file vprint(" Creating configuration file") util.mkcfgfile(util.PACCONF, self.root, self.option, self.db) # Creating packages vprint(" Creating package archives") for pkg in self.localpkgs: vprint("\t%s" % os.path.join(util.TMPDIR, pkg.filename())) pkg.finalize() pkg.makepkg(tmpdir) for key, value in self.db.items(): for pkg in value.pkgs: pkg.finalize() if key == "local" and not self.createlocalpkgs: continue for pkg in value.pkgs: vprint("\t%s" % os.path.join(util.PM_CACHEDIR, pkg.filename())) if self.cachepkgs: pkg.makepkg(cachedir) else: pkg.makepkg(os.path.join(syncdir, value.treename)) pkg.md5sum = util.getmd5sum(pkg.path) pkg.csize = os.stat(pkg.path)[stat.ST_SIZE] # Creating sync database archives vprint(" Creating databases") for key, value in self.db.items(): vprint("\t" + value.treename) value.generate() # Filesystem vprint(" Populating file system") for f in self.filesystem: if type(f) is pmfile.pmfile: vprint("\t%s" % f.path) f.mkfile(self.root); else: vprint("\t%s" % f) path = util.mkfile(self.root, f, f) if os.path.isfile(path): os.utime(path, (355, 355)) for pkg in self.db["local"].pkgs: vprint("\tinstalling %s" % pkg.fullname()) pkg.install_package(self.root) if self.db["local"].pkgs and self.dbver >= 9: path = os.path.join(self.root, util.PM_DBPATH, "local") util.mkfile(path, "ALPM_DB_VERSION", str(self.dbver)) # Done. vprint(" Taking a snapshot of the file system") for filename in self.snapshots_needed(): f = pmfile.snapshot(self.root, filename) self.files.append(f) vprint("\t%s" % f.name)
def test_mkfile(self): mkfile('test/test/test')