Example #1
0
 def extract_live_fs(self):
     '''Extracts squashfs_filename to self.__squashfs_dir'''
     try:
         # temp mount point for iso
         tmpMntIsoDir = os.path.join(tempfile.gettempdir(), 'r_iso')
         if not fs_tools.mount(self.__src_iso_filename, tmpMntIsoDir):
             self.log.error('Error mounting %s; check log for details...' %
                            (self._src_iso_filename))
             return
         # extract
         # fedora uses an ext image -- extract that first, then copy the contents
         tmpdir = tempfile.mkdtemp()
         tmpImgDir = tempfile.mkdtemp()
         self.log.debug('Extracting squash filesystem: %s' %
                        (self.__live_fs_filename))
         squash_tools.extract_squash_fs(unsquashfs_cmd=self.__unsquash,
                                        filename=self.__live_fs_filename,
                                        dest_dir=tmpdir)
         # mount the ext image
         self.log.debug('Mounting filesystem...')
         fs_tools.mount(
             os.path.join(tmpdir, 'LiveOS' + os.sep + 'ext3fs.img'),
             tmpImgDir)
         commands.getoutput('rsync -a %s/ %s/' %
                            (tmpImgDir, self.__live_fs_dir))
         return True
     except Exception, d:
         self.log.error('Error extracting live squash filesystem: %s' % (d))
         return False
Example #2
0
 def build_live_fs(self):
     try:
         self.log.debug('Creating sparse image...')
         tmpImgDir = tempfile.mkdtemp()
         tmpSquashDir = tmpImgDir + os.sep + 'LiveOS'
         tmpMntDir = tempfile.mkdtemp()
         os.makedirs(tmpSquashDir)
         os.system('dd if=/dev/zero of=%s/ext3fs.img bs=1M count=0 seek=4096' % (tmpSquashDir))
         os.system('mkfs.ext3 -F %s' % (os.path.join(tmpSquashDir, 'ext3fs.img')))
         # mount
         fs_tools.mount(os.path.join(tmpSquashDir, 'ext3fs.img'), tmpMntDir)
         # copy files
         os.system('rsync -a %s/ %s/' % (self.__live_fs_dir, tmpMntDir))
         self.log.info('Building squash filesystem: %s' % (self.__live_fs_filename))
         if squash_tools.create_squash_fs(mksquashfs_cmd=self.__mksquash, source_dir=tmpImgDir, dest_filename=self.__live_fs_filename, overwrite=True):
             if os.path.exists(self.__live_fs_filename):
                 self.log.debug('Live squash filesystem complete: %s' % (self.__live_fs_filename))
                 return True
             else:
                 self.log.error('Error creating squash filesystem; check log for details...')
                 return False
         else:
             self.log.error('Error creating squash filesystem; check log for details...')
             return False
     except Exception, d:
         self.log.error('Error creating squash filesystem: %s : %s' % (self.__live_fs_filename, d))
         return False  
Example #3
0
 def build_live_fs(self):
     try:
         self.log.debug('Creating sparse image...')
         tmpImgDir = tempfile.mkdtemp()
         tmpSquashDir = tmpImgDir + os.sep + 'LiveOS'
         tmpMntDir = tempfile.mkdtemp()
         os.makedirs(tmpSquashDir)
         # default fedora uses a 3GB image -- larger takes longer to boot and live env runs slower
         os.system('dd if=/dev/zero of=%s/ext3fs.img bs=1M count=0 seek=3072' % (tmpSquashDir))
         os.system('mkfs.ext3 -F %s' % (os.path.join(tmpSquashDir, 'ext3fs.img')))
         # mount
         fs_tools.mount(os.path.join(tmpSquashDir, 'ext3fs.img'), tmpMntDir)
         # copy files
         os.system('rsync -a %s/ %s/' % (self.__live_fs_dir, tmpMntDir))
         # TODO: relabel filesystem for selinux
         #self.log.info('Performing relabel on filesystem (selinux)...')
         #os.system('chroot %s /sbin/fixfiles relabel' % (tmpMntDir))
         self.log.info('Building squash filesystem: %s' % (self.__live_fs_filename))
         if squash_tools.create_squash_fs(mksquashfs_cmd=self.__mksquash, source_dir=tmpImgDir, dest_filename=self.__live_fs_filename, overwrite=True):
             if os.path.exists(self.__live_fs_filename):
                 self.log.debug('Live squash filesystem complete: %s' % (self.__live_fs_filename))
                 return True
             else:
                 self.log.error('Error creating squash filesystem; check log for details...')
                 return False
         else:
             self.log.error('Error creating squash filesystem; check log for details...')
             return False
     except Exception, d:
         self.log.error('Error creating squash filesystem: %s : %s' % (self.__live_fs_filename, d))
         return False  
Example #4
0
 def build_live_fs(self):
     try:
         self.log.debug('Creating sparse image...')
         tmpImgDir = tempfile.mkdtemp()
         tmpSquashDir = tmpImgDir + os.sep + 'LiveOS'
         tmpMntDir = tempfile.mkdtemp()
         os.makedirs(tmpSquashDir)
         os.system('dd if=/dev/zero of=%s/ext3fs.img bs=1M count=0 seek=8192' % (tmpSquashDir))
         os.system('mkfs.ext3 -F %s' % (os.path.join(tmpSquashDir, 'ext3fs.img')))
         # mount
         fs_tools.mount(os.path.join(tmpSquashDir, 'ext3fs.img'), tmpMntDir)
         # copy files
         os.system('rsync -a %s/ %s/' % (self.__live_fs_dir, tmpMntDir))
         self.log.info('Building squash filesystem: %s' % (self.__live_fs_filename))
         if squash_tools.create_squash_fs(mksquashfs_cmd=self.__mksquash, source_dir=tmpImgDir, dest_filename=self.__live_fs_filename, overwrite=True):
             if os.path.exists(self.__live_fs_filename):
                 self.log.debug('Live squash filesystem complete: %s' % (self.__live_fs_filename))
                 return True
             else:
                 self.log.error('Error creating squash filesystem; check log for details...')
                 return False
         else:
             self.log.error('Error creating squash filesystem; check log for details...')
             return False
     except Exception, d:
         self.log.error('Error creating squash filesystem: %s : %s' % (self.__live_fs_filename, d))
         return False  
Example #5
0
 def extract_live_fs(self):
     '''Extracts squashfs_filename to self.__squashfs_dir'''
     try:
         # temp mount point for iso
         tmpMntIsoDir = os.path.join(tempfile.gettempdir(), 'r_iso')
         if not fs_tools.mount(self.__src_iso_filename, tmpMntIsoDir):
             self.log.error('Error mounting %s; check log for details...' % (self._src_iso_filename))
             return
         # extract
         squash_tools.extract_squash_fs(unsquashfs_cmd=self.__unsquash, filename=self.__live_fs_filename, dest_dir=self.__live_fs_dir)
         info_file = os.path.join(self.__iso_fs_dir, '.disk' + os.sep + 'info')
         if os.path.exists(info_file):
             f = open(info_file, 'r')
             info = f.read()
             f.close()
             try:
                 self.__debian_version = info.split()[2].split('.')[0]
                 self.log.debug('Found Debian version {0}'.format(self.__debian_version))
             except:
                 # ignore errors
                 pass
         return True
     except Exception, d:
         self.log.error('Error extracting live squash filesystem: %s' % (d))
         return False
Example #6
0
 def extract_live_fs(self):
     '''Extracts squashfs_filename to self.__squashfs_dir'''
     try:
         # temp mount point for iso
         tmpMntIsoDir = os.path.join(tempfile.gettempdir(), 'r_iso')
         if not fs_tools.mount(self.__src_iso_filename, tmpMntIsoDir):
             self.log.error('Error mounting %s; check log for details...' %
                            (self._src_iso_filename))
             return
         # extract
         squash_tools.extract_squash_fs(unsquashfs_cmd=self.__unsquash,
                                        filename=self.__live_fs_filename,
                                        dest_dir=self.__live_fs_dir)
         info_file = os.path.join(self.__iso_fs_dir,
                                  '.disk' + os.sep + 'info')
         if os.path.exists(info_file):
             f = open(info_file, 'r')
             info = f.read()
             f.close()
             try:
                 self.__debian_version = info.split()[2].split('.')[0]
                 self.log.debug('Found Debian version {0}'.format(
                     self.__debian_version))
             except:
                 # ignore errors
                 pass
         return True
     except Exception, d:
         self.log.error('Error extracting live squash filesystem: %s' % (d))
         return False
Example #7
0
def extract(iso_filename=None, target_dir=None):
    '''Extracts ISO contents into target_dir'''
    try:
        # mount iso as loopback device
        # temporary mount point
        tmpMntDir = os.path.join(tempfile.gettempdir(), 'r_mnt')
        if not fs_tools.mount(iso_filename, tmpMntDir):
            log.error('ISO was not mounted correctly; Check log file for details.')
            return
        # check to make sure iso was mounted
        if len(os.listdir(tmpMntDir)) == 0:
            log.error('ISO was not mounted correctly; Check log file for details.')
            return
        # copy files
        # check for existing directory
        if os.path.exists(target_dir):
            log.warn('Removing existing extracted ISO directory...')
            os.system('rm -Rf %s' % (target_dir))
            while os.path.exists(target_dir): # HACK: make sure directory is deleted...
                time.sleep(1)
            time.sleep(5)
        else:
            # create target_dir
            log.info('Destination directory does not exist; creating...')
            os.makedirs(target_dir)
        # copy
        log.info('Copying files... Please wait...')
        os.system('rsync -a %s %s' % (tmpMntDir + os.sep, target_dir + os.sep))
        #shutil.copytree(tmpMntDir, self.__iso_fs_dir, True) # copy true symlinks
        #self.log.debug(commands.getoutput('rsync -avz %s %s' % (tmpMntDir, self.__iso_fs_dir))) # test fails with rsync??.... :|
        return True
    except Exception, d:
        log.error('Error extracting ISO: %s' % (d))
        return False
Example #8
0
 def build_live_fs(self):
     try:
         self.log.debug('Creating sparse image...')
         tmpImgDir = tempfile.mkdtemp()
         tmpSquashDir = tmpImgDir + os.sep + 'LiveOS'
         tmpMntDir = tempfile.mkdtemp()
         os.makedirs(tmpSquashDir)
         # default fedora uses a 3GB image -- larger takes longer to boot and live env runs slower
         os.system(
             'dd if=/dev/zero of=%s/ext3fs.img bs=1M count=0 seek=3072' %
             (tmpSquashDir))
         os.system('mkfs.ext3 -F %s' %
                   (os.path.join(tmpSquashDir, 'ext3fs.img')))
         # mount
         fs_tools.mount(os.path.join(tmpSquashDir, 'ext3fs.img'), tmpMntDir)
         # copy files
         os.system('rsync -a %s/ %s/' % (self.__live_fs_dir, tmpMntDir))
         # TODO: relabel filesystem for selinux
         #self.log.info('Performing relabel on filesystem (selinux)...')
         #os.system('chroot %s /sbin/fixfiles relabel' % (tmpMntDir))
         self.log.info('Building squash filesystem: %s' %
                       (self.__live_fs_filename))
         if squash_tools.create_squash_fs(
                 mksquashfs_cmd=self.__mksquash,
                 source_dir=tmpImgDir,
                 dest_filename=self.__live_fs_filename,
                 overwrite=True):
             if os.path.exists(self.__live_fs_filename):
                 self.log.debug('Live squash filesystem complete: %s' %
                                (self.__live_fs_filename))
                 return True
             else:
                 self.log.error(
                     'Error creating squash filesystem; check log for details...'
                 )
                 return False
         else:
             self.log.error(
                 'Error creating squash filesystem; check log for details...'
             )
             return False
     except Exception, d:
         self.log.error('Error creating squash filesystem: %s : %s' %
                        (self.__live_fs_filename, d))
         return False
Example #9
0
 def extract_live_fs(self):
     '''Extracts squashfs_filename to self.__squashfs_dir'''
     try:
         # temp mount point for iso
         tmpMntIsoDir = os.path.join(tempfile.gettempdir(), 'r_iso')
         if not fs_tools.mount(self.__src_iso_filename, tmpMntIsoDir):
             self.log.error('Error mounting %s; check log for details...' % (self._src_iso_filename))
             return
         # extract
         # fedora uses an ext image -- extract that first, then copy the contents
         tmpdir = tempfile.mkdtemp()
         tmpImgDir = tempfile.mkdtemp()
         self.log.debug('Extracting squash filesystem: %s' % (self.__live_fs_filename))
         squash_tools.extract_squash_fs(unsquashfs_cmd=self.__unsquash, filename=self.__live_fs_filename, dest_dir=tmpdir)
         # mount the ext image
         self.log.debug('Mounting filesystem...')
         fs_tools.mount(os.path.join(tmpdir, 'LiveOS' + os.sep + 'ext3fs.img'), tmpImgDir)
         commands.getoutput('rsync -a %s/ %s/' % (tmpImgDir, self.__live_fs_dir))
         return True
     except Exception, d:
         self.log.error('Error extracting live squash filesystem: %s' % (d))
         return False
Example #10
0
 def extract_live_fs(self):
     '''Extracts squashfs_filename to self.__squashfs_dir'''
     try:
         # temp mount point for iso
         tmpMntIsoDir = os.path.join(tempfile.gettempdir(), 'r_iso')
         if not fs_tools.mount(self.__src_iso_filename, tmpMntIsoDir):
             self.log.error('Error mounting %s; check log for details...' % (self._src_iso_filename))
             return
         # extract
         squash_tools.extract_squash_fs(unsquashfs_cmd=self.__unsquash, filename=self.__live_fs_filename, dest_dir=self.__live_fs_dir)
         return True
     except Exception, d:
         self.log.error('Error extracting live squash filesystem: %s' % (d))
         return False
Example #11
0
 def extract_live_fs(self):
     '''Extracts squashfs_filename to self.__squashfs_dir'''
     try:
         # temp mount point for iso
         tmpMntIsoDir = os.path.join(tempfile.gettempdir(), 'r_iso')
         if not fs_tools.mount(self.__src_iso_filename, tmpMntIsoDir):
             self.log.error('Error mounting %s; check log for details...' % (self._src_iso_filename))
             return
         # extract
         squash_tools.extract_squash_fs(unsquashfs_cmd=self.__unsquash, filename=self.__live_fs_filename, dest_dir=self.__live_fs_dir)
         return True
     except Exception, d:
         self.log.error('Error extracting live squash filesystem: %s' % (d))
         return False
Example #12
0
def extract(iso_filename=None, target_dir=None):
    '''Extracts ISO contents into target_dir'''
    try:
        # mount iso as loopback device
        # temporary mount point
        tmpMntDir = os.path.join(tempfile.gettempdir(), 'r_mnt')
        if not fs_tools.mount(iso_filename, tmpMntDir):
            log.error(
                'ISO was not mounted correctly; Check log file for details.')
            return
        # check to make sure iso was mounted
        if len(os.listdir(tmpMntDir)) == 0:
            log.error(
                'ISO was not mounted correctly; Check log file for details.')
            return
        # copy files
        # check for existing directory
        if os.path.exists(target_dir):
            log.warn('Removing existing extracted ISO directory...')
            os.system('rm -Rf %s' % (target_dir))
            while os.path.exists(
                    target_dir):  # HACK: make sure directory is deleted...
                time.sleep(1)
            time.sleep(5)
        else:
            # create target_dir
            log.info('Destination directory does not exist; creating...')
            os.makedirs(target_dir)
        # copy
        log.info('Copying files... Please wait...')
        os.system('rsync -a %s %s' % (tmpMntDir + os.sep, target_dir + os.sep))
        #shutil.copytree(tmpMntDir, self.__iso_fs_dir, True) # copy true symlinks
        #self.log.debug(commands.getoutput('rsync -avz %s %s' % (tmpMntDir, self.__iso_fs_dir))) # test fails with rsync??.... :|
        return True
    except Exception, d:
        log.error('Error extracting ISO: %s' % (d))
        return False
Example #13
0
 def testUnmount(self):
     self.assertTrue(fs_tools.mount(self.iso, self.tmp_dir))
     self.assertTrue(fs_tools.unmount(self.tmp_dir))
     self.assertFalse(os.path.exists(self.tmp_dir))
Example #14
0
 def testMount(self):
     self.assertTrue(fs_tools.mount(self.iso, self.tmp_dir))
     self.assert_(os.listdir(self.tmp_dir) != 0)
     self.assertTrue(fs_tools.unmount(self.tmp_dir))
Example #15
0
 def testUnmount(self):
     self.assertTrue(fs_tools.mount(self.iso, self.tmp_dir))
     self.assertTrue(fs_tools.unmount(self.tmp_dir))
     self.assertFalse(os.path.exists(self.tmp_dir))
Example #16
0
 def testMount(self):
     self.assertTrue(fs_tools.mount(self.iso, self.tmp_dir))
     self.assert_(os.listdir(self.tmp_dir) != 0)
     self.assertTrue(fs_tools.unmount(self.tmp_dir))