def buildiso(mount, winnt_sif, iso_out, bootstrap, tmp_dir=None): """Builds an ISO file containing all our modifications.""" tempdir = tempfile.mkdtemp(dir=tmp_dir) # Copy all files to our temporary directory as mounted iso files are # read-only and we need lowercase (aka case-insensitive) filepaths. copytreelower(mount, tempdir) # Copy the boot image. shutil.copy(os.path.join(VMCLOAK_ROOT, 'data', 'boot.img'), tempdir) dst_winnt = os.path.join(tempdir, 'i386', 'winnt.sif') # Merge the existing winnt.sif with our changes. mode, winnt = ini_read(dst_winnt) ini_merge(winnt, winnt_sif, overwrite=True) # There are a couple of optional values that should be set if they have # not already been set. winnt_opt_sif = os.path.join(VMCLOAK_ROOT, 'data', 'winnt-opt.sif') ini_merge(winnt, winnt_opt_sif, overwrite=False) ini_write(dst_winnt, mode, winnt) osdir = os.path.join(tempdir, '$oem$', '$1') os.makedirs(os.path.join(osdir, 'vmcloak')) data_bootstrap = os.path.join(VMCLOAK_ROOT, 'data', 'bootstrap') for fname in os.listdir(data_bootstrap): shutil.copy(os.path.join(data_bootstrap, fname), os.path.join(osdir, 'vmcloak', fname)) copytreeinto(bootstrap, osdir) isocreate = get_path('genisoimage') if not isocreate: log.error('Either genisoimage or mkisofs is required!') shutil.rmtree(tempdir) return False try: args = [ isocreate, '-quiet', '-b', 'boot.img', '-no-emul-boot', '-boot-load-seg', '1984', '-boot-load-size', '4', '-iso-level', '2', '-J', '-l', '-D', '-N', '-joliet-long', '-relaxed-filenames', '-o', iso_out, tempdir ] subprocess.check_call(args) except subprocess.CalledProcessError as e: log.error('Error creating ISO file: %s', e) shutil.rmtree(tempdir) return False shutil.rmtree(tempdir) return True
def buildiso(self, mount, newiso, bootstrap, tmp_dir=None): """Builds an ISO file containing all our modifications.""" outdir = tempfile.mkdtemp(dir=tmp_dir) # Copy all files to our temporary directory as mounted iso files are # read-only and we need lowercase (aka case-insensitive) filepaths. copytreelower(mount, outdir) # Copy the boot image. shutil.copy(os.path.join(self.path, "boot.img"), outdir) # Allow the OS handler to write additional files. self.isofiles(outdir, tmp_dir) os.makedirs(os.path.join(outdir, self.osdir, "vmcloak")) data_bootstrap = os.path.join(self.data_path, "bootstrap") for fname in os.listdir(data_bootstrap): shutil.copy(os.path.join(data_bootstrap, fname), os.path.join(outdir, self.osdir, "vmcloak", fname)) copytreeinto(bootstrap, os.path.join(outdir, self.osdir)) isocreate = get_path("genisoimage") if not isocreate: log.error("Either genisoimage or mkisofs is required!") shutil.rmtree(outdir) return False args = [ isocreate, "-quiet", "-b", "boot.img", "-allow-limited-size", "-o", newiso, ] + self.genisoargs + [outdir] log.debug("Executing genisoimage: %s", " ".join(args)) p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = p.communicate() warning = re.sub("[\\s]+", " ", err).strip() if p.wait() or out or warning not in GENISOIMAGE_WARNINGS: log.error("Error creating ISO file (err=%d): %s %s", p.wait(), out, err) shutil.rmtree(outdir) return False shutil.rmtree(outdir) return True
def buildiso(self, mount, newiso, bootstrap, tmp_dir=None): """Builds an ISO file containing all our modifications.""" outdir = tempfile.mkdtemp(dir=tmp_dir) # Copy all files to our temporary directory as mounted iso files are # read-only and we need lowercase (aka case-insensitive) filepaths. copytreelower(mount, outdir) # Copy the boot image. shutil.copy(os.path.join(self.path, "boot.img"), outdir) # Allow the OS handler to write additional files. self.isofiles(outdir, tmp_dir) os.makedirs(os.path.join(outdir, self.osdir, "vmcloak")) data_bootstrap = os.path.join(self.data_path, "bootstrap") for fname in os.listdir(data_bootstrap): shutil.copy(os.path.join(data_bootstrap, fname), os.path.join(outdir, self.osdir, "vmcloak", fname)) copytreeinto(bootstrap, os.path.join(outdir, self.osdir)) isocreate = get_path("genisoimage") if not isocreate: log.error("Either genisoimage or mkisofs is required!") shutil.rmtree(outdir) return False args = [ isocreate, "-quiet", "-b", "boot.img", "-o", newiso, ] + self.genisoargs + [outdir] log.debug("Executing genisoimage: %s", " ".join(args)) p = subprocess.Popen( args, stdout=subprocess.PIPE, stderr=subprocess.PIPE ) out, err = p.communicate() warning = re.sub("[\\s]+", " ", err).strip() if p.wait() or out or warning not in GENISOIMAGE_WARNINGS: log.error( "Error creating ISO file (err=%d): %s %s", p.wait(), out, err ) shutil.rmtree(outdir) return False shutil.rmtree(outdir) return True
def buildiso(self, mount, newiso, bootstrap, tmp_dir=None): """Builds an ISO file containing all our modifications.""" outdir = tempfile.mkdtemp(dir=tmp_dir) # Copy all files to our temporary directory as mounted iso files are # read-only and we need lowercase (aka case-insensitive) filepaths. copytreelower(mount, outdir) # Copy the boot image. shutil.copy(os.path.join(self.path, 'boot.img'), outdir) # Allow the OS handler to write additional files. self.isofiles(outdir, tmp_dir) os.makedirs(os.path.join(outdir, self.osdir, 'vmcloak')) data_bootstrap = os.path.join(self.data_path, 'bootstrap') for fname in os.listdir(data_bootstrap): shutil.copy(os.path.join(data_bootstrap, fname), os.path.join(outdir, self.osdir, 'vmcloak', fname)) copytreeinto(bootstrap, os.path.join(outdir, self.osdir)) isocreate = get_path('genisoimage') if not isocreate: log.error('Either genisoimage or mkisofs is required!') shutil.rmtree(outdir) return False args = [ isocreate, '-quiet', '-b', 'boot.img', '-o', newiso, ] + self.genisoargs + [outdir] p = subprocess.Popen( args, stdout=subprocess.PIPE, stderr=subprocess.PIPE ) out, err = p.communicate() if p.wait() or out or err != GENISOIMAGE_ERROR: log.error( "Error creating ISO file (err=%d): %s %s", p.wait(), out, err ) shutil.rmtree(outdir) return False shutil.rmtree(outdir) return True
def buildiso(self, mount, newiso, bootstrap, tmp_dir=None): """Builds an ISO file containing all our modifications.""" outdir = tempfile.mkdtemp(dir=tmp_dir) # Copy all files to our temporary directory as mounted iso files are # read-only and we need lowercase (aka case-insensitive) filepaths. copytreelower(mount, outdir) # Copy the boot image. shutil.copy(os.path.join(self.path, 'boot.img'), outdir) # Allow the OS handler to write additional files. self.isofiles(outdir, tmp_dir) os.makedirs(os.path.join(outdir, self.osdir, 'vmcloak')) data_bootstrap = os.path.join(self.data_path, 'bootstrap') for fname in os.listdir(data_bootstrap): shutil.copy(os.path.join(data_bootstrap, fname), os.path.join(outdir, self.osdir, 'vmcloak', fname)) copytreeinto(bootstrap, os.path.join(outdir, self.osdir)) isocreate = get_path('genisoimage') if not isocreate: log.error('Either genisoimage or mkisofs is required!') shutil.rmtree(outdir) return False args = [ isocreate, '-quiet', '-b', 'boot.img', '-o', newiso, ] + self.genisoargs + [outdir] try: # TODO Properly suppress the ISO-9660 warning. subprocess.check_call(args) except subprocess.CalledProcessError as e: log.error('Error creating ISO file: %s', e) shutil.rmtree(outdir) return False shutil.rmtree(outdir) return True