def arguments(self): ''' Handles all of the arguments to the program''' ## Usage string parser = self.parseOptions() self.options, self.remainder = parser.parse_args() ## Specifying your own dirt file if self.options.dirt: self.config.putGlobal("dirt", self.options.dirt) ## Otherwise you get the default ;) else: self.config.putGlobal("dirt", 'dirt') ## For sandbox installs if self.options.sandbox: self.config.putGlobal("sandbox", True) ## Disable formatting if self.options.nonpretty: self.config.putGlobal("nonpretty", True) ## For debug verbosity if self.options.verbose: if int(self.options.verbose) > 3 or int(self.options.verbose) < 0: raise Exception('DebugLevelExceeded') else: self.config.putGlobal("debug", int(self.options.verbose)) ## For the specified lexer if self.options.lexer: self.config.putGlobal("lexer", self.options.lexer) else: self.config.putGlobal("lexer", 'yaml') ## Clean up the tmp/ directory if self.options.clean: print "Cleaning up." rmDirectoryRecursive("tmp/") sys.exit(0) ## Run internal tests if self.options.tests: self.config.putGlobal("tests",self.options.tests) ## For setting a config file if self.options.config: yOut = yaml.dump(self.config.getGlobalDump()) fHandle = open('.shovel', 'w') fHandle.write(yOut) fHandle.close() if self.options.recipe: import core.recipe as recipe r = recipe.recipe() r.runner('cbuilder')
def test_5_rmDirectoryRecursive(self): ## Create a bunch of directories to recursively delete f.mkdirIfAbsent('test') f.mkdirIfAbsent('test/me') f.mkdirIfAbsent('test/me/lots') f.mkdirIfAbsent('test/me/lots/of') f.mkdirIfAbsent('test/me/lots/of/times') f.rmDirectoryRecursive('test') exists = os.path.exists('test') assert exists == False
def _setupDev(self): ## Clean up dev file.rmDirectoryRecursive(file.buildPath(self.baseDir,"dev")) file.mkdirIfAbsent(file.buildPath(self.baseDir,"dev", "pts")) file.mkdirIfAbsent(file.buildPath(self.baseDir,"dev", "shm")) prevMask = os.umask(0000) devFiles = ( (stat.S_IFCHR | 0666, os.makedev(1, 3), "dev/null"), (stat.S_IFCHR | 0666, os.makedev(1, 7), "dev/full"), (stat.S_IFCHR | 0666, os.makedev(1, 5), "dev/zero"), (stat.S_IFCHR | 0666, os.makedev(1, 8), "dev/random"), (stat.S_IFCHR | 0444, os.makedev(1, 9), "dev/urandom"), (stat.S_IFCHR | 0666, os.makedev(5, 0), "dev/tty"), (stat.S_IFCHR | 0600, os.makedev(5, 1), "dev/console"), (stat.S_IFCHR | 0666, os.makedev(5, 2), "dev/ptmx"), ) for i in devFiles: ## create node os.mknod(file.buildPath(self.baseDir, i[2]), i[0], i[1]) ## set context. (only necessary if host running selinux enabled.) ## fails gracefully if chcon not installed. ## subprocess.Popen( ## ["chcon", "--reference=/%s"% i[2], self.makeChrootPath(i[2])] ## , raiseExc=0, shell=False) ## create all the stdin/stdout/stderr devices os.symlink("/proc/self/fd/0", file.buildPath(self.baseDir,"dev/stdin")) os.symlink("/proc/self/fd/1", file.buildPath(self.baseDir,"dev/stdout")) os.symlink("/proc/self/fd/2", file.buildPath(self.baseDir,"dev/stderr")) os.umask(prevMask) devUnMount = [ 'umount -n %s' % file.buildPath(self.baseDir,'/dev/pts'), 'umount -n %s' % file.buildPath(self.baseDir,'/dev/shm') ] devMount = [ 'mount -n -t devpts chroot_devpts %s' % file.buildPath(self.baseDir,'/dev/pts'), 'mount -n -t tmpfs chroot_shmfs %s' % file.buildPath(self.baseDir,'/dev/shm') ] ## mount/umount for cmd in devUnMount: if cmd not in self.umountCmds: self.umountCmds.append(cmd) for cmd in devMount: if cmd not in self.mountCmds: self.mountCmds.append(cmd)
def test_6_single_rmDirectoryRecursive(self): f.mkdirIfAbsent('test') f.rmDirectoryRecursive('test') exists = os.path.exists('test') assert exists == False