Ejemplo n.º 1
0
 def mkdirIfAbsent(self, *arguments):
     ''' creates a folder if it isnt already present 
         arguments: arguments -- the folder you want to be created in list form
     '''
     
     assert arguments, "no argument variable passed, or value is None"
     _file.mkdirIfAbsent(arguments)
Ejemplo n.º 2
0
 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  
Ejemplo n.º 3
0
 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)      
Ejemplo n.º 4
0
 def test_6_single_rmDirectoryRecursive(self):
     f.mkdirIfAbsent('test')
     f.rmDirectoryRecursive('test')
     exists = os.path.exists('test')
     assert exists == False  
Ejemplo n.º 5
0
 def test_4_mkdirIfAbsent(self):
     f.mkdirIfAbsent('test')
     exists = os.path.exists('test')    
     assert exists == True
     os.removedirs('test')
Ejemplo n.º 6
0
        def init(self, location=None):
            if not location:
                self.baseDir = location
            
            debug('attempting to lock chroot',DEBUG)
            lock = self._getChrootLock()
            if lock == True:
                debug('got lock',DEBUG)                
            
            debug('creating base directory if needed',DEBUG)
            file.mkdirIfAbsent(self.baseDir)
            
            
            systemDirectories = [
            'dev', 'opt', 'sbin',
            'sbin', 'sys','lib','proc', 'etc',
            'usr/lib'
            ]
            
            debug('creating skeleton directories',DEBUG)
            ## build all the directories
            for dir in systemDirectories:
                built = file.buildPath(self.baseDir,dir)    
                file.mkdirIfAbsent(built)
           
            ## essential files
            essentialFiles = [
                file.buildPath(self.baseDir,'etc','mtab'),
                file.buildPath(self.baseDir,'etc','fstab'),
            ]
            map(file.touch,essentialFiles)
            
            ## if you want to use /etc/resolv.conf
            if self.useResolv:
                resolvPath = file.buildPath(self.baseDir,'etc','resolv.conf')
                resolvDir  = file.buildPath(self.baseDir,'etc')
                
                ## delete if it does exist
                if os.path.exists(resolvPath):
                    os.remove(resolvPath)
                    
                ## copy from your base system    
                shutil.copy2('/etc/resolv.conf', resolvDir)

            ## self._copyDirs()    

            if self.internalDev:
                self._setupDev()
            
            ## try:
            ##  self._mountall()
            ##  if not self.chrootWasCleaned:
            ##    self.chroot_setup_cmd = 'update'
            ##    self._yum(self.chroot_setup_cmd, returnOutput=1)
            ## finally:
            ##   self._umountall()
            
            localTimeDir  = file.buildPath(self.baseDir,'etc')
            localTimePath = file.buildPath(self.baseDir,'etc', 'localtime')
            if os.path.exists(localTimePath):
                os.remove(localTimePath)
            
            shutil.copy2('/etc/localtime', localTimeDir)
            
            self._lddGet('gcc')
            self._lddGet('ls')