def release_output(self, config, destdir, release): """ Create release directory and files """ def _rpath(fn): """ release path """ return os.path.join(destdir, fn) outimages = self.outimage # new ks new_kspath = _rpath(self.name+'.ks') with open(config) as fr: with open(new_kspath, "w") as wf: # When building a release we want to make sure the .ks # file generates the same build even when --release not used. wf.write(fr.read().replace("@BUILD_ID@", release)) outimages.append(new_kspath) # save log file, logfile is only available in creator attrs if hasattr(self, 'logfile') and not self.logfile: log_path = _rpath(self.name + ".log") # touch the log file, else outimages will filter it out with open(log_path, 'w') as wf: wf.write('') msger.set_logfile(log_path) outimages.append(_rpath(self.name + ".log")) # rename iso and usbimg for f in os.listdir(destdir): if f.endswith(".iso"): newf = f[:-4] + '.img' elif f.endswith(".usbimg"): newf = f[:-7] + '.img' else: continue os.rename(_rpath(f), _rpath(newf)) outimages.append(_rpath(newf)) # generate MD5SUMS with open(_rpath("MD5SUMS"), "w") as wf: for f in os.listdir(destdir): if f == "MD5SUMS": continue if os.path.isdir(os.path.join(destdir, f)): continue md5sum = misc.get_md5sum(_rpath(f)) # There needs to be two spaces between the sum and # filepath to match the syntax with md5sum. # This way also md5sum -c MD5SUMS can be used by users wf.write("%s *%s\n" % (md5sum, f)) outimages.append("%s/MD5SUMS" % destdir) # Filter out the nonexist file for fp in outimages[:]: if not os.path.exists("%s" % fp): outimages.remove(fp)
def release_output(self, config, destdir, release): """ Create release directory and files """ def _rpath(fn): """ release path """ return os.path.join(destdir, fn) outimages = self.outimage # new ks new_kspath = _rpath(self.name + ".ks") with open(config) as fr: with open(new_kspath, "w") as wf: # When building a release we want to make sure the .ks # file generates the same build even when --release not used. wf.write(fr.read().replace("@BUILD_ID@", release)) outimages.append(new_kspath) # save log file, logfile is only available in creator attrs if hasattr(self, "logfile") and not self.logfile: log_path = _rpath(self.name + ".log") # touch the log file, else outimages will filter it out with open(log_path, "w") as wf: wf.write("") msger.set_logfile(log_path) outimages.append(_rpath(self.name + ".log")) # rename iso and usbimg for f in os.listdir(destdir): if f.endswith(".iso"): newf = f[:-4] + ".img" elif f.endswith(".usbimg"): newf = f[:-7] + ".img" else: continue os.rename(_rpath(f), _rpath(newf)) outimages.append(_rpath(newf)) # generate MANIFEST with open(_rpath("MANIFEST"), "w") as wf: for f in os.listdir(destdir): if f == "MANIFEST": continue if os.path.isdir(os.path.join(destdir, f)): continue md5sum = misc.get_md5sum(_rpath(f)) # There needs to be two spaces between the sum and # filepath to match the syntax with md5sum. # This way also md5sum -c MANIFEST can be used by users wf.write("%s *%s\n" % (md5sum, f)) outimages.append("%s/MANIFEST" % destdir) # Filter out the nonexist file for fp in outimages[:]: if not os.path.exists("%s" % fp): outimages.remove(fp)
def postoptparse(self): if self.options.verbose: msger.set_loglevel('verbose') if self.options.debug: msger.set_loglevel('debug') if self.options.logfile: msger.set_interactive(False) msger.set_logfile(self.options.logfile) configmgr.create['logfile'] = self.options.logfile if self.options.config: configmgr.reset() configmgr._siteconf = self.options.config if self.options.outdir is not None: configmgr.create['outdir'] = self.options.outdir if self.options.cachedir is not None: configmgr.create['cachedir'] = self.options.cachedir os.environ['ZYPP_LOCKFILE_ROOT'] = configmgr.create['cachedir'] if self.options.local_pkgs_path is not None: if not os.path.exists(self.options.local_pkgs_path): msger.error('Local pkgs directory: \'%s\' not exist' \ % self.options.local_pkgs_path) configmgr.create['local_pkgs_path'] = self.options.local_pkgs_path if self.options.release: configmgr.create['release'] = self.options.release if self.options.record_pkgs: configmgr.create['record_pkgs'] = [] for infotype in self.options.record_pkgs.split(','): if infotype not in ('name', 'content', 'license'): raise errors.Usage('Invalid pkg recording: %s, valid ones:' ' "name", "content", "license"' \ % infotype) configmgr.create['record_pkgs'].append(infotype) if self.options.arch is not None: supported_arch = sorted(rpmmisc.archPolicies.keys(), reverse=True) if self.options.arch in supported_arch: configmgr.create['arch'] = self.options.arch else: raise errors.Usage( 'Invalid architecture: "%s".\n' ' Supported architectures are: \n' ' %s\n' % (self.options.arch, ', '.join(supported_arch))) if self.options.pkgmgr is not None: configmgr.create['pkgmgr'] = self.options.pkgmgr if self.options.runtime: configmgr.create['runtime'] = self.options.runtime if self.options.compress_disk_image is not None: configmgr.create['compress_disk_image'] = \ self.options.compress_disk_image
def postoptparse(self): if self.options.verbose: msger.set_loglevel('verbose') if self.options.debug: msger.set_loglevel('debug') if self.options.logfile: msger.set_interactive(False) msger.set_logfile(self.options.logfile) configmgr.create['logfile'] = self.options.logfile if self.options.config: configmgr.reset() configmgr._siteconf = self.options.config if self.options.outdir is not None: configmgr.create['outdir'] = self.options.outdir if self.options.cachedir is not None: configmgr.create['cachedir'] = self.options.cachedir os.environ['ZYPP_LOCKFILE_ROOT'] = configmgr.create['cachedir'] if self.options.local_pkgs_path is not None: if not os.path.exists(self.options.local_pkgs_path): msger.error('Local pkgs directory: \'%s\' not exist' \ % self.options.local_pkgs_path) configmgr.create['local_pkgs_path'] = self.options.local_pkgs_path if self.options.release: configmgr.create['release'] = self.options.release if self.options.record_pkgs: configmgr.create['record_pkgs'] = [] for infotype in self.options.record_pkgs.split(','): if infotype not in ('name', 'content', 'license'): raise errors.Usage('Invalid pkg recording: %s, valid ones:' ' "name", "content", "license"' \ % infotype) configmgr.create['record_pkgs'].append(infotype) if self.options.arch is not None: supported_arch = sorted(rpmmisc.archPolicies.keys(), reverse=True) if self.options.arch in supported_arch: configmgr.create['arch'] = self.options.arch else: raise errors.Usage('Invalid architecture: "%s".\n' ' Supported architectures are: \n' ' %s\n' % (self.options.arch, ', '.join(supported_arch))) if self.options.pkgmgr is not None: configmgr.create['pkgmgr'] = self.options.pkgmgr if self.options.runtime: configmgr.create['runtime'] = self.options.runtime if self.options.compress_disk_image is not None: configmgr.create['compress_disk_image'] = \ self.options.compress_disk_image
def set_logfile(self, logfile = None): if not logfile: logfile = self.create['logfile'] logfile_dir = os.path.dirname(self.create['logfile']) if not os.path.exists(logfile_dir): os.makedirs(logfile_dir) msger.set_interactive(False) if inbootstrap(): mode = 'a' else: mode = 'w' msger.set_logfile(self.create['logfile'], mode)
def set_logfile(self, logfile=None): if not logfile: logfile = self.create['logfile'] logfile_dir = os.path.dirname(self.create['logfile']) if not os.path.exists(logfile_dir): os.makedirs(logfile_dir) msger.set_interactive(False) if inbootstrap(): mode = 'a' else: mode = 'w' msger.set_logfile(self.create['logfile'], mode)
def postoptparse(self): abspath = lambda pth: os.path.abspath(os.path.expanduser(pth)) if self.options.verbose: msger.set_loglevel('verbose') if self.options.debug: msger.set_loglevel('debug') if self.options.logfile: logfile_abs_path = abspath(self.options.logfile) if os.path.isdir(logfile_abs_path): raise errors.Usage("logfile's path %s should be file" % self.options.logfile) if not os.path.exists(os.path.dirname(logfile_abs_path)): os.makedirs(os.path.dirname(logfile_abs_path)) msger.set_interactive(False) msger.set_logfile(logfile_abs_path) configmgr.create['logfile'] = self.options.logfile if self.options.config: configmgr.reset() configmgr._siteconf = self.options.config if self.options.outdir is not None: configmgr.create['outdir'] = abspath(self.options.outdir) if self.options.cachedir is not None: configmgr.create['cachedir'] = abspath(self.options.cachedir) os.environ['ZYPP_LOCKFILE_ROOT'] = configmgr.create['cachedir'] for cdir in ('outdir', 'cachedir'): if os.path.exists(configmgr.create[cdir]) \ and not os.path.isdir(configmgr.create[cdir]): msger.error('Invalid directory specified: %s' \ % configmgr.create[cdir]) if self.options.local_pkgs_path is not None: if not os.path.exists(self.options.local_pkgs_path): msger.error('Local pkgs directory: \'%s\' not exist' \ % self.options.local_pkgs_path) configmgr.create['local_pkgs_path'] = self.options.local_pkgs_path if self.options.release: configmgr.create['release'] = self.options.release.rstrip('/') if self.options.record_pkgs: configmgr.create['record_pkgs'] = [] for infotype in self.options.record_pkgs.split(','): if infotype not in ('name', 'content', 'license', 'vcs'): raise errors.Usage('Invalid pkg recording: %s, valid ones:' ' "name", "content", "license", "vcs"' \ % infotype) configmgr.create['record_pkgs'].append(infotype) if self.options.arch is not None: supported_arch = sorted(rpmmisc.archPolicies.keys(), reverse=True) if self.options.arch in supported_arch: configmgr.create['arch'] = self.options.arch else: raise errors.Usage('Invalid architecture: "%s".\n' ' Supported architectures are: \n' ' %s' % (self.options.arch, ', '.join(supported_arch))) if self.options.pkgmgr is not None: configmgr.create['pkgmgr'] = self.options.pkgmgr if self.options.runtime: configmgr.set_runtime(self.options.runtime) if self.options.pack_to is not None: configmgr.create['pack_to'] = self.options.pack_to if self.options.copy_kernel: configmgr.create['copy_kernel'] = self.options.copy_kernel if self.options.install_pkgs: configmgr.create['install_pkgs'] = [] for pkgtype in self.options.install_pkgs.split(','): if pkgtype not in ('source', 'debuginfo', 'debugsource'): raise errors.Usage('Invalid parameter specified: "%s", ' 'valid values: source, debuginfo, ' 'debusource' % pkgtype) configmgr.create['install_pkgs'].append(pkgtype) if self.options.enabletmpfs: configmgr.create['enabletmpfs'] = self.options.enabletmpfs if self.options.repourl: for item in self.options.repourl: try: key, val = item.split('=') except: continue configmgr.create['repourl'][key] = val
def postoptparse(self): abspath = lambda pth: os.path.abspath(os.path.expanduser(pth)) if self.options.verbose: msger.set_loglevel('verbose') if self.options.debug: msger.set_loglevel('debug') if self.options.logfile: msger.set_interactive(False) msger.set_logfile(self.options.logfile) configmgr.create['logfile'] = self.options.logfile if self.options.config: configmgr.reset() configmgr._siteconf = self.options.config if self.options.outdir is not None: configmgr.create['outdir'] = abspath(self.options.outdir) if self.options.cachedir is not None: configmgr.create['cachedir'] = abspath(self.options.cachedir) os.environ['ZYPP_LOCKFILE_ROOT'] = configmgr.create['cachedir'] if self.options.local_pkgs_path is not None: if not os.path.exists(self.options.local_pkgs_path): msger.error('Local pkgs directory: \'%s\' not exist' \ % self.options.local_pkgs_path) configmgr.create['local_pkgs_path'] = self.options.local_pkgs_path if self.options.release: configmgr.create['release'] = self.options.release if self.options.record_pkgs: configmgr.create['record_pkgs'] = [] for infotype in self.options.record_pkgs.split(','): if infotype not in ('name', 'url', 'content', 'license'): raise errors.Usage('Invalid pkg recording: %s, valid ones:' ' "name", "url", "content", "license"' \ % infotype) configmgr.create['record_pkgs'].append(infotype) if self.options.arch is not None: supported_arch = sorted(rpmmisc.archPolicies.keys(), reverse=True) if self.options.arch in supported_arch: configmgr.create['arch'] = self.options.arch else: raise errors.Usage('Invalid architecture: "%s".\n' ' Supported architectures are: \n' ' %s' % (self.options.arch, ', '.join(supported_arch))) if self.options.pkgmgr is not None: configmgr.create['pkgmgr'] = self.options.pkgmgr if self.options.runtime: configmgr.create['runtime'] = self.options.runtime if self.options.pack_to is not None: configmgr.create['pack_to'] = self.options.pack_to if self.options.copy_kernel: configmgr.create['copy_kernel'] = self.options.copy_kernel if self.options.tokenmap: tokenmap = {} for pair in self.options.tokenmap.split(","): token, value = pair.split(":",1) tokenmap[token] = value if not "RELEASE" in tokenmap and self.options.release: tokenmap["RELEASE"] = self.options.release if not "BUILD_ID" in tokenmap and "RELEASE" in tokenmap: tokenmap["BUILD_ID"] = tokenmap["RELEASE"] configmgr.create['tokenmap'] = tokenmap