def execute(self, log, buildenv, target): if self.node.et.text: fp = self.node.et.text log.printo("transfer gpg key to target: " + fp) os.environ['GNUPGHOME'] = "/var/cache/elbe/gnupg" key = BytesIO() ctx = gpgme.Context() ctx.armor = True ctx.export(fp, key) log.printo(str(key.getvalue())) with open((target.path + '/pub.key'), 'wb') as tkey: tkey.write(key.getvalue()) target.mkdir_p("/var/cache/elbe/gnupg", mode=0700) with target: os.environ['GNUPGHOME'] = target.path + "/var/cache/elbe/gnupg" log.do("gpg --import " + target.path + "/pub.key") log.printo("generate base repo") arch = target.xml.text("project/arch", key="arch") buildenv.rfs.mkdir_p('/tmp/pkgs') with buildenv: cache = get_rpcaptcache(buildenv.rfs, "updated-repo.log", arch) pkglist = cache.get_installed_pkgs() for pkg in pkglist: try: cache.download_binary(pkg.name, '/tmp/pkgs', pkg.installed_version) except ValueError as ve: log.printo("No Package " + pkg.name + "-" + pkg.installed_version) except FetchError as fe: log.printo("Package " + pkg.name + "-" + pkg.installed_version + " could not be downloaded") except TypeError as te: log.printo("Package " + pkg.name + "-" + pkg.installed_version + " missing name or version") r = UpdateRepo(target.xml, target.path + '/var/cache/elbe/repos/base', log) for d in buildenv.rfs.glob('tmp/pkgs/*.deb'): r.includedeb(d, 'main') slist = target.path + '/etc/apt/sources.list.d/base.list' slist_txt = 'deb file:///var/cache/elbe/repos/base ' slist_txt += target.xml.text("/project/suite") slist_txt += " main" with open(slist, 'w') as apt_source: apt_source.write(slist_txt) rmtree(buildenv.rfs.path + '/tmp/pkgs')
def execute(self, log, buildenv, target): if self.node.et.text: fp = self.node.et.text log.printo ("transfer gpg key to target: " + fp) os.environ ['GNUPGHOME'] = "/var/cache/elbe/gnupg" key = BytesIO () ctx = gpgme.Context () ctx.armor = True ctx.export (fp, key) log.printo (str (key.getvalue ())) with open ((target.path + '/pub.key'), 'wb') as tkey: tkey.write (key.getvalue ()) target.mkdir_p ("/var/cache/elbe/gnupg", mode=0700) with target: os.environ ['GNUPGHOME'] = target.path + "/var/cache/elbe/gnupg" log.do ("gpg --import " + target.path + "/pub.key") log.printo( "generate base repo") arch = target.xml.text ("project/arch", key="arch") buildenv.rfs.mkdir_p ('/tmp/pkgs') with buildenv: cache = get_rpcaptcache (buildenv.rfs, "updated-repo.log", arch) pkglist = cache.get_installed_pkgs() for pkg in pkglist: try: cache.download_binary (pkg.name, '/tmp/pkgs', pkg.installed_version) except ValueError as ve: log.printo( "No Package " + pkg.name + "-" + pkg.installed_version ) except FetchError as fe: log.printo( "Package " + pkg.name + "-" + pkg.installed_version + " could not be downloaded" ) except TypeError as te: log.printo( "Package " + pkg.name + "-" + pkg.installed_version + " missing name or version" ) r = UpdateRepo (target.xml, target.path + '/var/cache/elbe/repos/base', log) for d in buildenv.rfs.glob ('tmp/pkgs/*.deb'): r.includedeb (d, 'main') slist = target.path + '/etc/apt/sources.list.d/base.list' slist_txt = 'deb file:///var/cache/elbe/repos/base ' slist_txt += target.xml.text ("/project/suite") slist_txt += " main" with open (slist, 'w') as apt_source: apt_source.write (slist_txt) rmtree (buildenv.rfs.path + '/tmp/pkgs')
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 execute(self, buildenv, target): # pylint: disable=too-many-locals if self.node.et.text: fp = self.node.et.text logging.info("transfert gpg key to target: %s", fp) gpgdata = core.Data() ctx = core.Context() ctx.set_engine_info(PROTOCOL_OpenPGP, None, '/var/cache/elbe/gnupg') ctx.set_armor(True) unlock_key(fp) ctx.op_export(fp, 0, gpgdata) gpgdata.seek(0, os.SEEK_SET) key = gpgdata.read() logging.info(str(key)) with open((target.path + '/pub.key'), 'wb') as tkey: tkey.write(key) target.mkdir_p("/var/cache/elbe/gnupg", mode=0o700) with target: env_add = {'GNUPGHOME': target.path + "/var/cache/elbe/gnupg"} cmd = "gpg --import %s%s" % (target.path, "/pub.key") do(cmd, env_add=env_add) logging.info("generate base repo") arch = target.xml.text("project/arch", key="arch") buildenv.rfs.mkdir_p('/tmp/pkgs') with buildenv: cache = get_rpcaptcache(buildenv.rfs, arch) pkglist = cache.get_installed_pkgs() for pkg in pkglist: try: cache.download_binary(pkg.name, '/tmp/pkgs', pkg.installed_version) except ValueError: logging.exception("No package %s-%s", pkg.name, pkg.installed_version) except FetchError: logging.exception("Package %s-%s could not be downloaded", pkg.name, pkg.installed_version) except TypeError: logging.exception("Package %s-%s missing name or version", pkg.name, pkg.installed_version) r = UpdateRepo(target.xml, target.path + '/var/cache/elbe/repos/base') for d in buildenv.rfs.glob('tmp/pkgs/*.deb'): r.includedeb(d, 'main') r.finalize() slist = target.path + '/etc/apt/sources.list.d/base.list' slist_txt = 'deb [trusted=yes] file:///var/cache/elbe/repos/base ' slist_txt += target.xml.text("/project/suite") slist_txt += " main" with open(slist, 'w') as apt_source: apt_source.write(slist_txt) rmtree(buildenv.rfs.path + '/tmp/pkgs') # allow downgrades by default target.touch_file('/var/cache/elbe/.downgrade_allowed')
def execute(self, log, buildenv, target): # pylint: disable=too-many-locals if self.node.et.text: fp = self.node.et.text log.printo("transfer gpg key to target: " + fp) gpgdata = core.Data() ctx = core.Context() ctx.set_engine_info(PROTOCOL_OpenPGP, None, '/var/cache/elbe/gnupg') ctx.set_armor(True) unlock_key(fp) ctx.op_export(fp, 0, gpgdata) gpgdata.seek(0, os.SEEK_SET) key = gpgdata.read() log.printo(str(key)) with open((target.path + '/pub.key'), 'wb') as tkey: tkey.write(key) target.mkdir_p("/var/cache/elbe/gnupg", mode=0o700) with target: env_add = {'GNUPGHOME': target.path + "/var/cache/elbe/gnupg"} log.do("gpg --import " + target.path + "/pub.key", env_add=env_add) log.printo("generate base repo") arch = target.xml.text("project/arch", key="arch") buildenv.rfs.mkdir_p('/tmp/pkgs') with buildenv: cache = get_rpcaptcache(buildenv.rfs, "updated-repo.log", arch) pkglist = cache.get_installed_pkgs() for pkg in pkglist: try: cache.download_binary( pkg.name, '/tmp/pkgs', pkg.installed_version) except ValueError: log.printo( "No Package " + pkg.name + "-" + pkg.installed_version) except FetchError: log.printo( "Package " + pkg.name + "-" + pkg.installed_version + " could not be downloaded") except TypeError: log.printo( "Package " + pkg.name + "-" + pkg.installed_version + " missing name or version") r = UpdateRepo(target.xml, target.path + '/var/cache/elbe/repos/base', log) for d in buildenv.rfs.glob('tmp/pkgs/*.deb'): r.includedeb(d, 'main') r.finalize() slist = target.path + '/etc/apt/sources.list.d/base.list' slist_txt = 'deb [trusted=yes] file:///var/cache/elbe/repos/base ' slist_txt += target.xml.text("/project/suite") slist_txt += " main" with open(slist, 'w') as apt_source: apt_source.write(slist_txt) rmtree(buildenv.rfs.path + '/tmp/pkgs') # allow downgrades by default target.touch_file('/var/cache/elbe/.downgrade_allowed')