def execute(self, db): try: self.project.log.printo("Applying package changes") with self.project.buildenv: # Commit changes, update full package list and write # out new source.xml self.project.get_rpcaptcache().commit() dump_fullpkgs(self.project.xml, self.project.buildenv.rfs, self.project.get_rpcaptcache()) sourcexmlpath = path.join(self.project.builddir, "source.xml") self.project.xml.xml.write(sourcexmlpath) self.project.log.printo("Package changes applied successfully") db.reset_busy(self.project.builddir, "has_changes") except Exception as e: self.project.log.printo("Applying package changes failed") self.project.log.printo(str(e)) db.reset_busy(self.project.builddir, "build_failed")
def execute (self, db): try: self.project.log.printo( "Applying package changes" ) with self.project.buildenv: # Commit changes, update full package list and write # out new source.xml self.project.get_rpcaptcache().commit() dump_fullpkgs( self.project.xml, self.project.buildenv.rfs, self.project.get_rpcaptcache() ) sourcexmlpath = path.join( self.project.builddir, "source.xml" ) self.project.xml.xml.write( sourcexmlpath ) self.project.log.printo( "Package changes applied successfully" ) db.reset_busy( self.project.builddir, "has_changes" ) except Exception as e: self.project.log.printo( "Applying package changes failed" ) self.project.log.printo( str(e) ) db.reset_busy( self.project.builddir, "build_failed" )
def execute(self, db): success = self.build_failed try: logging.info("Applying package changes") with self.project.buildenv: # Commit changes, update full package list and write # out new source.xml self.project.get_rpcaptcache().commit() dump_fullpkgs(self.project.xml, self.project.buildenv.rfs, self.project.get_rpcaptcache()) sourcexmlpath = path.join(self.project.builddir, "source.xml") self.project.xml.xml.write(sourcexmlpath) except Exception: logging.exception("Applying package changes failed") else: if read_maxlevel(self.project.builddir) >= logging.ERROR: logging.info("Package changes applied with Error") else: logging.info("Package changes applied successfully") succes = self.has_changes finally: db.reset_busy(self.project.builddir, success)
def gen_update_pkg (project, xml_filename, upd_filename, override_buildtype = None, skip_validate = False, debug = False, cmd_dir = None, cfg_dir=None): if xml_filename: xml = ElbeXML( xml_filename, buildtype=override_buildtype, skip_validate=skip_validate ) if not xml.has("fullpkgs"): raise MissingData("Xml does not have fullpkgs list") if not project.xml.has("fullpkgs"): raise MissingData("Source Xml does not have fullpkgs list") if not project.buildenv.rfs: raise MissingData("Target does not have a build environment") cache = project.get_rpcaptcache() instpkgs = cache.get_installed_pkgs() instindex = {} for p in instpkgs: instindex[p.name] = p xmlpkgs = xml.node("/fullpkgs") xmlindex = {} fnamelist = [] for p in xmlpkgs: name = p.et.text ver = p.et.get('version') md5 = p.et.get('md5') xmlindex[name] = p if not name in instindex: print "package removed: " + name continue ipkg = instindex[name] comp = cache.compare_versions(ipkg.installed_version, ver) pfname = ipkg.installed_deb if comp == 0: print "package ok: " + name + "-" + ipkg.installed_version if debug: fnamelist.append( pfname ) continue if comp > 0: print "package upgrade: " + pfname fnamelist.append( pfname ) else: print "package downgrade: " + name + "-" + ipkg.installed_version for p in instpkgs: if p.name in xmlindex: continue print "package new installed " + p.name pfname = p.installed_deb fnamelist.append( pfname ) update = os.path.join(project.builddir, "update") if os.path.exists( update ): rmtree( update ) os.system( 'mkdir -p %s' % update ) if xml_filename: repodir = os.path.join(update, "repo" ) repo = UpdateRepo( xml, repodir, project.log ) for fname in fnamelist: path = os.path.join( project.chrootpath, "var/cache/apt/archives", fname ) repo.includedeb( path ) repo.finalize () dump_fullpkgs(project.xml, project.buildenv.rfs, cache) project.xml.xml.write( os.path.join( update, "new.xml" ) ) os.system( "cp %s %s" % (xml_filename, os.path.join( update, "base.xml" )) ) else: os.system( "cp source.xml update/new.xml") if project.presh_file: copyfile (project.presh_file, update + '/pre.sh') os.chmod (update + '/pre.sh', 0755) if project.postsh_file: copyfile (project.postsh_file, update + '/post.sh') os.chmod (update + '/post.sh', 0755) if cmd_dir: inlucdedir (update, 'cmd', cmd_dir, mode=0755) if cfg_dir: inlucdedir (update, 'conf', cfg_dir) create_zip_archive( upd_filename, update, "." ) if project.postbuild_file: project.log.h2 ("postbuild script") project.log.do (project.postbuild_file+' "%s %s %s"'%( upd_filename, project.xml.text ("project/version"), project.xml.text ("project/name")), allow_fail=True)
def gen_update_pkg(project, xml_filename, upd_filename, override_buildtype=None, skip_validate=False, debug=False, cmd_dir=None, cfg_dir=None): # pylint: disable=too-many-arguments # pylint: disable=too-many-locals # pylint: disable=too-many-statements # pylint: disable=too-many-branches if xml_filename: xml = ElbeXML(xml_filename, buildtype=override_buildtype, skip_validate=skip_validate) if not xml.has("fullpkgs"): raise MissingData("Xml does not have fullpkgs list") if not project.xml.has("fullpkgs"): raise MissingData("Source Xml does not have fullpkgs list") if not project.buildenv.rfs: raise MissingData("Target does not have a build environment") cache = project.get_rpcaptcache() instpkgs = cache.get_installed_pkgs() instindex = {} for p in instpkgs: instindex[p.name] = p xmlpkgs = xml.node("/fullpkgs") xmlindex = {} fnamelist = [] for p in xmlpkgs: name = p.et.text ver = p.et.get('version') md5 = p.et.get('md5') xmlindex[name] = p if name not in instindex: print("package removed: %s" % name) continue ipkg = instindex[name] comp = cache.compare_versions(ipkg.installed_version, ver) pfname = ipkg.installed_deb if comp == 0: print("package ok: %s-%s" % (name, ipkg.installed_version)) if debug: fnamelist.append(pfname) continue if comp > 0: print("package upgrade: %s" % pfname) fnamelist.append(pfname) else: print( "package downgrade: %s-%s" % (name, ipkg.installed_version)) for p in instpkgs: if p.name in xmlindex: continue print("package %s newly installed" % p.name) pfname = p.installed_deb fnamelist.append(pfname) update = os.path.join(project.builddir, "update") if os.path.exists(update): rmtree(update) os.system('mkdir -p %s' % update) if xml_filename: repodir = os.path.join(update, "repo") repo = UpdateRepo(xml, repodir, project.log) for fname in fnamelist: path = os.path.join( project.chrootpath, "var/cache/apt/archives", fname) repo.includedeb(path) repo.finalize() dump_fullpkgs(project.xml, project.buildenv.rfs, cache) project.xml.xml.write(os.path.join(update, "new.xml")) os.system( "cp %s %s" % (xml_filename, os.path.join( update, "base.xml"))) else: os.system("cp source.xml update/new.xml") if project.presh_file: copyfile(project.presh_file, update + '/pre.sh') os.chmod(update + '/pre.sh', 0o755) if project.postsh_file: copyfile(project.postsh_file, update + '/post.sh') os.chmod(update + '/post.sh', 0o755) if cmd_dir: inlucdedir(update, 'cmd', cmd_dir, mode=0o755) if cfg_dir: inlucdedir(update, 'conf', cfg_dir) create_zip_archive(upd_filename, update, ".") if project.postbuild_file: project.log.h2("postbuild script") project.log.do(project.postbuild_file + ' "%s %s %s"' % ( upd_filename, project.xml.text("project/version"), project.xml.text("project/name")), allow_fail=True)
def build(self, build_bin=False, build_sources=False, cdrom_size=None, skip_pkglist=False, skip_pbuild=False): # pylint: disable=too-many-arguments # pylint: disable=too-many-locals # pylint: disable=too-many-statements # pylint: disable=too-many-branches # Write the log header self.write_log_header() # Validate Apt Sources if build_sources: m = ValidationMode.CHECK_ALL else: m = ValidationMode.CHECK_BINARIES self.xml.validate_apt_sources(m, self.arch) if self.xml.has('target/pbuilder') and not skip_pbuild: if not os.path.exists(os.path.join(self.builddir, "pbuilder")): self.create_pbuilder(cross=False) for p in self.xml.node('target/pbuilder'): self.pbuild(p) # the package might be needed by a following pbuild, so update # the project repo that it can be installed in as # build-dependency self.repo.finalize() # To avoid update cache errors, the project repo needs to have # Release and Packages files, even if it's empty. So don't do this # in the if case above! self.repo.finalize() # Create the build environment, if it does not a valid one # self.buildenv might be set when we come here. # However, if its not a full_buildenv, we specify clean here, # so it gets rebuilt properly. if not self.has_full_buildenv(): do('mkdir -p "%s"' % self.chrootpath) self.buildenv = BuildEnv(self.xml, self.chrootpath, build_sources=build_sources, clean=True) skip_pkglist = False # Import keyring self.buildenv.import_keys() logging.info("Keys imported") # Install packages if not skip_pkglist: self.install_packages(self.buildenv) try: self.buildenv.rfs.dump_elbeversion(self.xml) except IOError: logging.exception("Dump elbeversion failed") # Extract target FS. We always create a new instance here with # clean=true, because we want a pristine directory. self.targetfs = TargetFs(self.targetpath, self.buildenv.xml, clean=True) os.chdir(self.buildenv.rfs.fname('')) extract_target(self.buildenv.rfs, self.xml, self.targetfs, self.get_rpcaptcache()) # Package validation and package list if not skip_pkglist: pkgs = self.xml.xml.node("/target/pkg-list") if self.xml.has("fullpkgs"): check_full_pkgs(pkgs, self.xml.xml.node("/fullpkgs"), self.get_rpcaptcache()) else: check_full_pkgs(pkgs, None, self.get_rpcaptcache()) dump_fullpkgs(self.xml, self.buildenv.rfs, self.get_rpcaptcache()) self.xml.dump_elbe_version() self.targetfs.write_fstab(self.xml) # Dump ELBE version try: self.targetfs.dump_elbeversion(self.xml) except MemoryError: logging.exception("Dump elbeversion failed") # install packages for buildenv if not skip_pkglist: self.install_packages(self.buildenv, buildenv=True) # Write source.xml try: sourcexmlpath = os.path.join(self.builddir, "source.xml") self.xml.xml.write(sourcexmlpath) except MemoryError: logging.exception("Write source.xml failed (archive to huge?)") # Elbe report cache = self.get_rpcaptcache() tgt_pkgs = elbe_report(self.xml, self.buildenv, cache, self.targetfs) # chroot' licenses self.gen_licenses("chroot", self.buildenv, [p.name for p in cache.get_installed_pkgs()]) self.gen_licenses("target", self.buildenv, tgt_pkgs) # Use some handwaving to determine grub version grub_arch = "ia32" if self.arch == "i386" else self.arch grub_fw_type = [] grub_version = 0 if self.get_rpcaptcache().is_installed('grub-pc'): grub_version = 202 grub_fw_type.append("bios") if self.get_rpcaptcache().is_installed('grub-efi-%s-bin' % grub_arch): grub_version = 202 grub_tgt = "x86_64" if self.arch == "amd64" else self.arch grub_fw_type.extend(["efi", grub_tgt + "-efi"]) if (self.get_rpcaptcache().is_installed('shim-signed') and self.get_rpcaptcache().is_installed( 'grub-efi-%s-signed' % grub_arch)): grub_version = 202 grub_fw_type.append("shimfix") if self.get_rpcaptcache().is_installed('grub-legacy'): logging.warning("package grub-legacy is installed, " "this is obsolete.") grub_version = 97 grub_fw_type.append("bios") elif not grub_fw_type: logging.warning( "neither package grub-pc nor grub-efi-%s-bin " "are installed, skipping grub", grub_arch) self.targetfs.part_target(self.builddir, grub_version, grub_fw_type) self.build_cdroms(build_bin, build_sources, cdrom_size, tgt_pkg_lst=tgt_pkgs) if self.postbuild_file: logging.info("Postbuild script") cmd = ' "%s %s %s"' % (self.builddir, self.xml.text("project/version"), self.xml.text("project/name")) do(self.postbuild_file + cmd, allow_fail=True) do_prj_finetuning(self.xml, self.buildenv, self.targetfs, self.builddir) self.targetfs.pack_images(self.builddir) system('cat "%s"' % self.validationpath)
def build(self, build_bin=False, build_sources=False, cdrom_size=None, skip_pkglist=False, skip_pbuild=False): # pylint: disable=too-many-arguments # pylint: disable=too-many-locals # pylint: disable=too-many-statements # pylint: disable=too-many-branches # Write the log header self.write_log_header() # Validate Apt Sources if build_sources: m = ValidationMode.CHECK_ALL else: m = ValidationMode.CHECK_BINARIES self.xml.validate_apt_sources(m, self.arch) if self.xml.has('target/pbuilder') and not skip_pbuild: if not os.path.exists(os.path.join(self.builddir, "pbuilder")): self.create_pbuilder() for p in self.xml.node('target/pbuilder'): self.pbuild(p) # the package might be needed by a following pbuild, so update # the project repo that it can be installed in as # build-dependency self.repo.finalize() # To avoid update cache errors, the project repo needs to have # Release and Packages files, even if it's empty. So don't do this # in the if case above! self.repo.finalize() # Create the build environment, if it does not a valid one # self.buildenv might be set when we come here. # However, if its not a full_buildenv, we specify clean here, # so it gets rebuilt properly. if not self.has_full_buildenv(): self.log.do('mkdir -p "%s"' % self.chrootpath) self.buildenv = BuildEnv(self.xml, self.log, self.chrootpath, build_sources=build_sources, clean=True) skip_pkglist = False # Import keyring self.buildenv.import_keys() self.log.printo("Keys imported") # Install packages if not skip_pkglist: self.install_packages(self.buildenv) try: self.buildenv.rfs.dump_elbeversion(self.xml) except IOError: self.log.printo("dump elbeversion failed") # Extract target FS. We always create a new instance here with # clean=true, because we want a pristine directory. self.targetfs = TargetFs(self.targetpath, self.log, self.buildenv.xml, clean=True) os.chdir(self.buildenv.rfs.fname('')) extract_target(self.buildenv.rfs, self.xml, self.targetfs, self.log, self.get_rpcaptcache()) # The validation file is created using check_full_pkgs() and # elbe_report(), both opening the file in append mode. So if an # old validation file already exists, it must be deleted first. if os.path.isfile(self.validationpath): os.unlink(self.validationpath) # Package validation and package list if not skip_pkglist: pkgs = self.xml.xml.node("/target/pkg-list") if self.xml.has("fullpkgs"): check_full_pkgs(pkgs, self.xml.xml.node("/fullpkgs"), self.validationpath, self.get_rpcaptcache()) else: check_full_pkgs(pkgs, None, self.validationpath, self.get_rpcaptcache()) dump_fullpkgs(self.xml, self.buildenv.rfs, self.get_rpcaptcache()) self.xml.dump_elbe_version() self.targetfs.write_fstab(self.xml) # Dump ELBE version try: self.targetfs.dump_elbeversion(self.xml) except MemoryError: self.log.printo("dump elbeversion failed") # install packages for buildenv if not skip_pkglist: self.install_packages(self.buildenv, buildenv=True) # Write source.xml try: sourcexmlpath = os.path.join(self.builddir, "source.xml") self.xml.xml.write(sourcexmlpath) except MemoryError: self.log.printo("write source.xml failed (archive to huge?)") # Elbe report reportpath = os.path.join(self.builddir, "elbe-report.txt") elbe_report(self.xml, self.buildenv, self.get_rpcaptcache(), reportpath, self.validationpath, self.targetfs) # the current license code raises an exception that interrupts the hole # build if a licence can't be converted to utf-8. Exception handling # can be removed as soon as the licence code is more stable lic_err = False try: f = io.open(os.path.join(self.builddir, "licence.txt"), "w+", encoding='utf-8') self.buildenv.rfs.write_licenses( f, self.log, os.path.join(self.builddir, "licence.xml")) except Exception: self.log.printo("error during generating licence.txt/xml") self.log.printo(sys.exc_info()[0]) lic_err = True finally: f.close() if lic_err: os.remove(os.path.join(self.builddir, "licence.txt")) os.remove(os.path.join(self.builddir, "licence.xml")) # Use some handwaving to determine grub version # jessie and wheezy grubs are 2.0 but differ in behaviour # # We might also want support for legacy grub if (self.get_rpcaptcache().is_installed('grub-pc') and self.get_rpcaptcache().is_installed('grub-efi-amd64-bin')): grub_version = 202 grub_fw_type = "hybrid" elif self.get_rpcaptcache().is_installed('grub-pc'): if self.codename == "wheezy": grub_version = 199 else: grub_version = 202 grub_fw_type = "bios" elif self.get_rpcaptcache().is_installed('grub-efi-amd64'): grub_version = 202 grub_fw_type = "efi" elif self.get_rpcaptcache().is_installed('grub-legacy'): self.log.printo("package grub-legacy is installed, " "this is obsolete, skipping grub") grub_version = 0 grub_fw_type = "" else: self.log.printo("package grub-pc is not installed, skipping grub") # version 0 == skip_grub grub_version = 0 grub_fw_type = "" self.targetfs.part_target(self.builddir, grub_version, grub_fw_type) self.build_cdroms(build_bin, build_sources, cdrom_size) if self.postbuild_file: self.log.h2("postbuild script:") self.log.do(self.postbuild_file + ' "%s %s %s"' % (self.builddir, self.xml.text("project/version"), self.xml.text("project/name")), allow_fail=True) do_prj_finetuning(self.xml, self.log, self.buildenv, self.targetfs, self.builddir) self.targetfs.pack_images(self.builddir) system('cat "%s"' % self.validationpath)
def build(self, skip_debootstrap=False, build_bin=False, build_sources=False, cdrom_size=None, debug=False, skip_pkglist=False): # Write the log header self.write_log_header() # Create the build environment, if it does not exist yet if not self.buildenv: self.log.do('mkdir -p "%s"' % self.chrootpath) self.buildenv = BuildEnv(self.xml, self.log, self.chrootpath, build_sources=build_sources) skip_pkglist = False # Install packages if not skip_pkglist: self.install_packages() try: self.buildenv.rfs.dump_elbeversion(self.xml) except IOError: self.log.printo("dump elbeversion failed") # Extract target FS. We always create a new instance here with # clean=true, because we want a pristine directory. self.targetfs = TargetFs(self.targetpath, self.log, self.buildenv.xml, clean=True) os.chdir(self.buildenv.rfs.fname('')) extract_target(self.buildenv.rfs, self.xml, self.targetfs, self.log, self.get_rpcaptcache()) # Package validation and package list if not skip_pkglist: validationpath = os.path.join(self.builddir, "validation.txt") pkgs = self.xml.xml.node("/target/pkg-list") if self.xml.has("fullpkgs"): check_full_pkgs(pkgs, self.xml.xml.node("/fullpkgs"), validationpath, self.get_rpcaptcache()) else: check_full_pkgs(pkgs, None, validationpath, self.get_rpcaptcache()) dump_fullpkgs(self.xml, self.buildenv.rfs, self.get_rpcaptcache()) self.xml.dump_elbe_version() self.targetfs.write_fstab(self.xml) # Dump ELBE version try: self.targetfs.dump_elbeversion(self.xml) except MemoryError: self.log.printo("dump elbeversion failed") # install packages for buildenv if not skip_pkglist: self.install_packages(buildenv=True) # Write source.xml try: sourcexmlpath = os.path.join(self.builddir, "source.xml") self.xml.xml.write(sourcexmlpath) except MemoryError: self.log.printo("write source.xml failed (archive to huge?)") # Elbe report reportpath = os.path.join(self.builddir, "elbe-report.txt") elbe_report(self.xml, self.buildenv, self.get_rpcaptcache(), reportpath, self.targetfs) # Licenses f = open(os.path.join(self.builddir, "licence.txt"), "w+") self.buildenv.rfs.write_licenses(f, self.log) f.close() # Read arch and codename from xml arch = self.xml.text("project/arch", key="arch") codename = self.xml.text("project/suite") # Use some handwaving to determine grub version # jessie and wheezy grubs are 2.0 but differ in behaviour # # We might also want support for legacy grub if self.get_rpcaptcache().is_installed('grub-pc'): if codename == "jessie": grub_version = 202 else: grub_version = 199 elif self.get_rpcaptcache().is_installed('grub-legacy'): self.log.printo( "package grub-legacy is installed, this is obsolete, skipping grub" ) grub_version = 0 else: self.log.printo("package grub-pc is not installed, skipping grub") # version 0 == skip_grub grub_version = 0 self.targetfs.part_target(self.builddir, grub_version) # Build cdrom images self.repo_images = [] with self.buildenv: init_codename = self.xml.get_initvm_codename() if build_bin: self.repo_images += mk_binary_cdrom(self.buildenv.rfs, arch, codename, init_codename, self.xml, self.builddir, self.log, cdrom_size=cdrom_size) if build_sources: try: self.repo_images += mk_source_cdrom(self.buildenv.rfs, arch, codename, init_codename, self.builddir, self.log, cdrom_size=cdrom_size) except SystemError as e: # e.g. no deb-src urls specified self.log.printo(str(e)) if self.postbuild_file: self.log.h2("postbuild script:") self.log.do(self.postbuild_file + ' "%s %s %s"' % (self.builddir, self.xml.text("project/version"), self.xml.text("project/name")), allow_fail=True) os.system('cat "%s"' % os.path.join(self.builddir, "validation.txt"))
def build(self, build_bin=False, build_sources=False, cdrom_size=None, skip_pkglist=False, skip_pbuild=False): # pylint: disable=too-many-arguments # pylint: disable=too-many-locals # pylint: disable=too-many-statements # pylint: disable=too-many-branches # Write the log header self.write_log_header() # Validate Apt Sources if build_sources: m = ValidationMode.CHECK_ALL else: m = ValidationMode.CHECK_BINARIES self.xml.validate_apt_sources(m, self.arch) if self.xml.has('target/pbuilder') and not skip_pbuild: if not os.path.exists(os.path.join(self.builddir, "pbuilder")): self.create_pbuilder() for p in self.xml.node('target/pbuilder'): self.pbuild(p) # the package might be needed by a following pbuild, so update # the project repo that it can be installed in as # build-dependency self.repo.finalize() # To avoid update cache errors, the project repo needs to have # Release and Packages files, even if it's empty. So don't do this # in the if case above! self.repo.finalize() # Create the build environment, if it does not a valid one # self.buildenv might be set when we come here. # However, if its not a full_buildenv, we specify clean here, # so it gets rebuilt properly. if not self.has_full_buildenv(): self.log.do('mkdir -p "%s"' % self.chrootpath) self.buildenv = BuildEnv(self.xml, self.log, self.chrootpath, build_sources=build_sources, clean=True) skip_pkglist = False # Import keyring self.buildenv.import_keys() self.log.printo("Keys imported") # Install packages if not skip_pkglist: self.install_packages(self.buildenv) try: self.buildenv.rfs.dump_elbeversion(self.xml) except IOError: self.log.printo("dump elbeversion failed") # Extract target FS. We always create a new instance here with # clean=true, because we want a pristine directory. self.targetfs = TargetFs(self.targetpath, self.log, self.buildenv.xml, clean=True) os.chdir(self.buildenv.rfs.fname('')) extract_target(self.buildenv.rfs, self.xml, self.targetfs, self.log, self.get_rpcaptcache()) # The validation file is created using check_full_pkgs() and # elbe_report(), both opening the file in append mode. So if an # old validation file already exists, it must be deleted first. if os.path.isfile(self.validationpath): os.unlink(self.validationpath) # Package validation and package list if not skip_pkglist: pkgs = self.xml.xml.node("/target/pkg-list") if self.xml.has("fullpkgs"): check_full_pkgs(pkgs, self.xml.xml.node("/fullpkgs"), self.validationpath, self.get_rpcaptcache()) else: check_full_pkgs(pkgs, None, self.validationpath, self.get_rpcaptcache()) dump_fullpkgs(self.xml, self.buildenv.rfs, self.get_rpcaptcache()) self.xml.dump_elbe_version() self.targetfs.write_fstab(self.xml) # Dump ELBE version try: self.targetfs.dump_elbeversion(self.xml) except MemoryError: self.log.printo("dump elbeversion failed") # install packages for buildenv if not skip_pkglist: self.install_packages(self.buildenv, buildenv=True) # Write source.xml try: sourcexmlpath = os.path.join(self.builddir, "source.xml") self.xml.xml.write(sourcexmlpath) except MemoryError: self.log.printo("write source.xml failed (archive to huge?)") # Elbe report reportpath = os.path.join(self.builddir, "elbe-report.txt") elbe_report(self.xml, self.buildenv, self.get_rpcaptcache(), reportpath, self.validationpath, self.targetfs) # the current license code raises an exception that interrupts the hole # build if a licence can't be converted to utf-8. Exception handling # can be removed as soon as the licence code is more stable lic_err = False try: f = io.open( os.path.join( self.builddir, "licence.txt"), "w+", encoding='utf-8') self.buildenv.rfs.write_licenses( f, self.log, os.path.join( self.builddir, "licence.xml")) except Exception: self.log.printo("error during generating licence.txt/xml") self.log.printo(sys.exc_info()[0]) lic_err = True finally: f.close() if lic_err: os.remove(os.path.join(self.builddir, "licence.txt")) os.remove(os.path.join(self.builddir, "licence.xml")) # Use some handwaving to determine grub version # jessie and wheezy grubs are 2.0 but differ in behaviour # # We might also want support for legacy grub if (self.get_rpcaptcache().is_installed('grub-pc') and self.get_rpcaptcache().is_installed('grub-efi-amd64-bin')): grub_version = 202 grub_fw_type = "hybrid" elif self.get_rpcaptcache().is_installed('grub-pc'): if self.codename == "wheezy": grub_version = 199 else: grub_version = 202 grub_fw_type = "bios" elif self.get_rpcaptcache().is_installed('grub-efi-amd64'): grub_version = 202 grub_fw_type = "efi" elif self.get_rpcaptcache().is_installed('grub-legacy'): self.log.printo("package grub-legacy is installed, " "this is obsolete, skipping grub") grub_version = 0 grub_fw_type = "" else: self.log.printo("package grub-pc is not installed, skipping grub") # version 0 == skip_grub grub_version = 0 grub_fw_type = "" self.targetfs.part_target(self.builddir, grub_version, grub_fw_type) self.build_cdroms(build_bin, build_sources, cdrom_size) if self.postbuild_file: self.log.h2("postbuild script:") self.log.do(self.postbuild_file + ' "%s %s %s"' % ( self.builddir, self.xml.text("project/version"), self.xml.text("project/name")), allow_fail=True) do_prj_finetuning(self.xml, self.log, self.buildenv, self.targetfs, self.builddir) self.targetfs.pack_images(self.builddir) os.system('cat "%s"' % self.validationpath)
def build (self, skip_debootstrap = False, build_bin = False, build_sources = False, cdrom_size = None, debug = False, skip_pkglist = False): # Write the log header self.write_log_header() # Create the build environment, if it does not exist yet if not self.buildenv: self.log.do( 'mkdir -p "%s"' % self.chrootpath ) self.buildenv = BuildEnv( self.xml, self.log, self.chrootpath, build_sources = build_sources ) skip_pkglist = False # Install packages if not skip_pkglist: self.install_packages() try: self.buildenv.rfs.dump_elbeversion (self.xml) except IOError: self.log.printo ("dump elbeversion failed") # Extract target FS. We always create a new instance here with # clean=true, because we want a pristine directory. self.targetfs = TargetFs( self.targetpath, self.log, self.buildenv.xml, clean=True ) os.chdir( self.buildenv.rfs.fname( '' ) ) extract_target( self.buildenv.rfs, self.xml, self.targetfs, self.log, self.get_rpcaptcache() ) # Package validation and package list if not skip_pkglist: validationpath = os.path.join( self.builddir, "validation.txt" ) pkgs = self.xml.xml.node( "/target/pkg-list" ) if self.xml.has( "fullpkgs" ): check_full_pkgs( pkgs, self.xml.xml.node( "/fullpkgs" ), validationpath, self.get_rpcaptcache() ) else: check_full_pkgs( pkgs, None, validationpath, self.get_rpcaptcache() ) dump_fullpkgs( self.xml, self.buildenv.rfs, self.get_rpcaptcache() ) self.xml.dump_elbe_version () self.targetfs.write_fstab (self.xml ) # Dump ELBE version try: self.targetfs.dump_elbeversion( self.xml ) except MemoryError: self.log.printo( "dump elbeversion failed" ) # install packages for buildenv if not skip_pkglist: self.install_packages(buildenv=True) # Write source.xml try: sourcexmlpath = os.path.join( self.builddir, "source.xml" ) self.xml.xml.write( sourcexmlpath ) except MemoryError: self.log.printo( "write source.xml failed (archive to huge?)" ) # Elbe report reportpath = os.path.join( self.builddir, "elbe-report.txt" ) elbe_report( self.xml, self.buildenv, self.get_rpcaptcache(), reportpath, self.targetfs ) # Licenses f = open( os.path.join( self.builddir, "licence.txt" ), "w+" ) self.buildenv.rfs.write_licenses(f, self.log) f.close() # Read arch and codename from xml arch = self.xml.text( "project/arch", key="arch" ) codename = self.xml.text( "project/suite" ) # Use some handwaving to determine grub version # jessie and wheezy grubs are 2.0 but differ in behaviour # # We might also want support for legacy grub if self.get_rpcaptcache().is_installed( 'grub-pc' ): if codename == "jessie": grub_version = 202 else: grub_version = 199 elif self.get_rpcaptcache().is_installed( 'grub-legacy' ): self.log.printo( "package grub-legacy is installed, this is obsolete, skipping grub" ) grub_version = 0 else: self.log.printo( "package grub-pc is not installed, skipping grub" ) # version 0 == skip_grub grub_version = 0 self.targetfs.part_target( self.builddir, grub_version ) # Build cdrom images self.repo_images = [] with self.buildenv: init_codename = self.xml.get_initvm_codename() if build_bin: self.repo_images += mk_binary_cdrom( self.buildenv.rfs, arch, codename, init_codename, self.xml, self.builddir, self.log, cdrom_size=cdrom_size ) if build_sources: try: self.repo_images += mk_source_cdrom( self.buildenv.rfs, arch, codename, init_codename, self.builddir, self.log, cdrom_size=cdrom_size ) except SystemError as e: # e.g. no deb-src urls specified self.log.printo( str (e) ) if self.postbuild_file: self.log.h2 ("postbuild script:") self.log.do (self.postbuild_file + ' "%s %s %s"' % ( self.builddir, self.xml.text ("project/version"), self.xml.text ("project/name")), allow_fail=True) os.system( 'cat "%s"' % os.path.join( self.builddir, "validation.txt" ) )
def build(self, skip_debootstrap=False, build_bin=False, build_sources=False, cdrom_size=None, debug=False, skip_pkglist=False, skip_pbuild=False): # Write the log header self.write_log_header() # Validate Apt Sources m = ValidationMode.NO_CHECK if build_bin: m = ValidationMode.CHECK_BINARIES if build_sources: m = ValidationMode.CHECK_ALL self.xml.validate_apt_sources(m, self.arch) if (self.xml.has('target/pbuilder') and not skip_pbuild): if not os.path.exists(os.path.join(self.builddir, "pbuilder")): self.create_pbuilder() for p in self.xml.node('target/pbuilder'): self.pbuild(p) # the package might be needed by a following pbuild, so update # the project repo that it can be installed in as # build-dependency self.repo.finalize() # To avoid update cache errors, the project repo needs to have # Release and Packages files, even if it's empty. So don't do this # in the if case above! self.repo.finalize() # Create the build environment, if it does not a valid one # self.buildenv might be set when we come here. # However, if its not a full_buildenv, we specify clean here, # so it gets rebuilt properly. if not self.has_full_buildenv(): self.log.do('mkdir -p "%s"' % self.chrootpath) self.buildenv = BuildEnv(self.xml, self.log, self.chrootpath, build_sources=build_sources, clean=True) skip_pkglist = False # Import keyring self.buildenv.import_keys() self.log.printo("Keys imported") # Install packages if not skip_pkglist: self.install_packages() try: self.buildenv.rfs.dump_elbeversion(self.xml) except IOError: self.log.printo("dump elbeversion failed") # Extract target FS. We always create a new instance here with # clean=true, because we want a pristine directory. self.targetfs = TargetFs(self.targetpath, self.log, self.buildenv.xml, clean=True) os.chdir(self.buildenv.rfs.fname('')) extract_target(self.buildenv.rfs, self.xml, self.targetfs, self.log, self.get_rpcaptcache()) # Package validation and package list if not skip_pkglist: validationpath = os.path.join(self.builddir, "validation.txt") pkgs = self.xml.xml.node("/target/pkg-list") if self.xml.has("fullpkgs"): check_full_pkgs(pkgs, self.xml.xml.node("/fullpkgs"), validationpath, self.get_rpcaptcache()) else: check_full_pkgs(pkgs, None, validationpath, self.get_rpcaptcache()) dump_fullpkgs(self.xml, self.buildenv.rfs, self.get_rpcaptcache()) self.xml.dump_elbe_version() self.targetfs.write_fstab(self.xml) # Dump ELBE version try: self.targetfs.dump_elbeversion(self.xml) except MemoryError: self.log.printo("dump elbeversion failed") # install packages for buildenv if not skip_pkglist: self.install_packages(buildenv=True) # Write source.xml try: sourcexmlpath = os.path.join(self.builddir, "source.xml") self.xml.xml.write(sourcexmlpath) except MemoryError: self.log.printo("write source.xml failed (archive to huge?)") # Elbe report reportpath = os.path.join(self.builddir, "elbe-report.txt") elbe_report(self.xml, self.buildenv, self.get_rpcaptcache(), reportpath, self.targetfs) # Licenses f = io.open(os.path.join(self.builddir, "licence.txt"), "w+", encoding='utf-8') self.buildenv.rfs.write_licenses( f, self.log, os.path.join(self.builddir, "licence.xml")) f.close() # Use some handwaving to determine grub version # jessie and wheezy grubs are 2.0 but differ in behaviour # # We might also want support for legacy grub if self.get_rpcaptcache().is_installed('grub-pc'): if self.codename == "wheezy": grub_version = 199 else: grub_version = 202 elif self.get_rpcaptcache().is_installed('grub-legacy'): self.log.printo( "package grub-legacy is installed, this is obsolete, skipping grub" ) grub_version = 0 else: self.log.printo("package grub-pc is not installed, skipping grub") # version 0 == skip_grub grub_version = 0 self.targetfs.part_target(self.builddir, grub_version) # Build cdrom images self.repo_images = [] with self.buildenv: init_codename = self.xml.get_initvm_codename() if build_bin: self.repo_images += mk_binary_cdrom(self.buildenv.rfs, self.arch, self.codename, init_codename, self.xml, self.builddir, self.log, cdrom_size=cdrom_size) if build_sources: try: self.repo_images += mk_source_cdrom(self.buildenv.rfs, self.arch, self.codename, init_codename, self.builddir, self.log, cdrom_size=cdrom_size, xml=self.xml) except SystemError as e: # e.g. no deb-src urls specified self.log.printo(str(e)) if self.postbuild_file: self.log.h2("postbuild script:") self.log.do(self.postbuild_file + ' "%s %s %s"' % (self.builddir, self.xml.text("project/version"), self.xml.text("project/name")), allow_fail=True) os.system('cat "%s"' % os.path.join(self.builddir, "validation.txt"))