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 finally: # unmount iso if not fs_tools.unmount(tmpMntIsoDir): self.log.error('Error unmounting %s; check log for details...' % (tmpMntIsoDir)) def update_boot_kernel(self): try: f = os.listdir('%s' % (os.path.join(self.__live_fs_dir, 'boot'))) for k in f: if k.find('initrd.img') > -1: if k.find('486') > -1: if self.__debian_version == '5': # copy the 486 initrd to iso dir shutil.copy('%s/boot/%s' % (self.__live_fs_dir, k), '%s/live/initrd1.img' % (self.__iso_fs_dir)) else: # copy the 486 initrd to iso dir shutil.copy('%s/boot/%s' % (self.__live_fs_dir, k), '%s/live/initrd.img' % (self.__iso_fs_dir)) elif k.find('686') > -1:
# 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 finally: # unmount iso if not fs_tools.unmount(tmpMntIsoDir): self.log.error('Error unmounting %s; check log for details...' % (tmpMntIsoDir)) if not fs_tools.unmount(tmpImgDir): self.log.error('Error unmounting %s; check log for details...' % (tmpImgDir)) #shutil.rmtree(tmpdir) def update_boot_kernel(self): # skip for now #self.log.info('Not yet implemented...') return True try: f = os.listdir('%s' % (os.path.join(self.__live_fs_dir, 'boot'))) for k in f: if k.find('initrd.img') > -1: # copy the initrd to iso dir shutil.copy('%s/boot/%s' % (self.__live_fs_dir, k), '%s/isolinux/initrd0.img' % (self.__iso_fs_dir))
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 finally: # unmount iso if not fs_tools.unmount(tmpMntIsoDir): self.log.error( 'Error unmounting %s; check log for details...' % (tmpMntIsoDir)) if not fs_tools.unmount(tmpImgDir): self.log.error( 'Error unmounting %s; check log for details...' % (tmpImgDir)) #shutil.rmtree(tmpdir) def update_boot_kernel(self): # skip for now #self.log.info('Not yet implemented...') return True try: f = os.listdir('%s' % (os.path.join(self.__live_fs_dir, 'boot')))
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 finally: # unmount iso if not fs_tools.unmount(tmpMntIsoDir): self.log.error( 'Error unmounting %s; check log for details...' % (tmpMntIsoDir)) def update_boot_kernel(self): try: f = os.listdir('%s' % (os.path.join(self.__live_fs_dir, 'boot'))) for k in f: if k.find('initrd.img') > -1: if k.find('486') > -1: if self.__debian_version == '5': # copy the 486 initrd to iso dir shutil.copy( '%s/boot/%s' % (self.__live_fs_dir, k), '%s/live/initrd1.img' % (self.__iso_fs_dir))
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))
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))