def add_script(self, name, content): if not content.startswith("#!"): content = "#!/bin/sh\n" + content path = os.path.join("bin/", name) self.filesystem.append(pmfile.pmfile(path, content, mode=0o755))
def add_hook(self, name, content): if not name.endswith(".hook"): name = name + ".hook" path = os.path.join("etc/pacman.d/hooks/", name) self.filesystem.append(pmfile.pmfile(path, content))
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, PM_DBPATH) cachedir = os.path.join(self.root, PM_CACHEDIR) syncdir = os.path.join(self.root, SYNCREPO) tmpdir = os.path.join(self.root, TMPDIR) logdir = os.path.join(self.root, os.path.dirname(LOGFILE)) etcdir = os.path.join(self.root, os.path.dirname(PACCONF)) for dir in [dbdir, cachedir, syncdir, tmpdir, logdir, etcdir]: if not os.path.isdir(dir): vprint("\t%s" % dir[len(self.root)+1:]) os.makedirs(dir, 0755) # Configuration file vprint(" Creating configuration file") vprint("\t%s" % PACCONF) mkcfgfile(PACCONF, self.root, self.option, self.db) # Creating packages vprint(" Creating package archives") for pkg in self.localpkgs: vprint("\t%s" % os.path.join(TMPDIR, pkg.filename())) pkg.makepkg(tmpdir) for key, value in self.db.iteritems(): if key == "local": continue for pkg in value.pkgs: archive = pkg.filename() vprint("\t%s" % os.path.join(PM_CACHEDIR, archive)) pkg.makepkg(cachedir) pkg.sha1sum = getsha1sum(os.path.join(cachedir, archive)) pkg.csize = os.stat(os.path.join(cachedir, archive))[stat.ST_SIZE] # Populating databases vprint(" Populating databases") for key, value in self.db.iteritems(): for pkg in value.pkgs: vprint("\t%s/%s" % (key, pkg.fullname())) if key == "local": pkg.installdate = time.ctime() value.db_write(pkg) # Creating sync database archives vprint(" Creating sync database archives") for key, value in self.db.iteritems(): if key == "local": continue vprint("\t" + value.treename) value.gensync() serverpath = os.path.join(syncdir, value.treename) os.mkdir(serverpath) shutil.copy(value.dbfile, serverpath) # Filesystem vprint(" Populating file system") for pkg in self.db["local"].pkgs: vprint("\tinstalling %s" % pkg.fullname()) pkg.install_files(self.root) for f in self.filesystem: vprint("\t%s" % f) mkfile(os.path.join(self.root, f), f) # 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.pmfile(self.root, filename.replace(self.root + "/", "")) self.files.append(f) vprint("\t%s" % f.name)
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, PM_DBPATH) cachedir = os.path.join(self.root, PM_CACHEDIR) syncdir = os.path.join(self.root, SYNCREPO) tmpdir = os.path.join(self.root, TMPDIR) logdir = os.path.join(self.root, os.path.dirname(LOGFILE)) etcdir = os.path.join(self.root, os.path.dirname(PACCONF)) for dir in [dbdir, cachedir, syncdir, tmpdir, logdir, etcdir]: if not os.path.isdir(dir): vprint("\t%s" % dir[len(self.root) + 1 :]) os.makedirs(dir, 0755) # Configuration file vprint(" Creating configuration file") vprint("\t%s" % PACCONF) mkcfgfile(PACCONF, self.root, self.option, self.db) # Creating packages vprint(" Creating package archives") for pkg in self.localpkgs: vprint("\t%s" % os.path.join(TMPDIR, pkg.filename())) pkg.makepkg(tmpdir) for key, value in self.db.iteritems(): if key == "local": continue for pkg in value.pkgs: archive = pkg.filename() vprint("\t%s" % os.path.join(PM_CACHEDIR, archive)) pkg.makepkg(cachedir) pkg.sha1sum = getsha1sum(os.path.join(cachedir, archive)) pkg.csize = os.stat(os.path.join(cachedir, archive))[stat.ST_SIZE] # Populating databases vprint(" Populating databases") for key, value in self.db.iteritems(): for pkg in value.pkgs: vprint("\t%s/%s" % (key, pkg.fullname())) if key == "local": pkg.installdate = time.ctime() value.db_write(pkg) # Creating sync database archives vprint(" Creating sync database archives") for key, value in self.db.iteritems(): if key == "local": continue vprint("\t" + value.treename) value.gensync() serverpath = os.path.join(syncdir, value.treename) os.mkdir(serverpath) shutil.copy(value.dbfile, serverpath) # Filesystem vprint(" Populating file system") for pkg in self.db["local"].pkgs: vprint("\tinstalling %s" % pkg.fullname()) pkg.install_files(self.root) for f in self.filesystem: vprint("\t%s" % f) mkfile(os.path.join(self.root, f), f) # 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.pmfile(self.root, filename.replace(self.root + "/", "")) self.files.append(f) vprint("\t%s" % f.name)