def make_deb_repo(repo, distro, build_os, spec): # Note: the Debian repository Packages files must be generated # very carefully in order to be usable. oldpwd=os.getcwd() os.chdir(repo+"../../../../../../") try: dirs=set([os.path.dirname(deb)[2:] for deb in backtick(["find", ".", "-name", "*.deb"]).split()]) for d in dirs: s=backtick(["dpkg-scanpackages", d, "/dev/null"]) f=open(d+"/Packages", "w") try: f.write(s) finally: f.close() b=backtick(["gzip", "-9c", d+"/Packages"]) f=open(d+"/Packages.gz", "wb") try: f.write(b) finally: f.close() finally: os.chdir(oldpwd) # Notes: the Release{,.gpg} files must live in a special place, # and must be created after all the Packages.gz files have been # done. s="""Origin: mongodb Label: mongodb Suite: mongodb Codename: %s/mongodb-enterprise Architectures: amd64 Components: %s Description: MongoDB packages """ % (distro.repo_os_version(build_os), distro.repo_component()) if os.path.exists(repo+"../../Release"): os.unlink(repo+"../../Release") if os.path.exists(repo+"../../Release.gpg"): os.unlink(repo+"../../Release.gpg") oldpwd=os.getcwd() os.chdir(repo+"../../") s2=backtick(["apt-ftparchive", "release", "."]) try: f=open("Release", 'w') try: f.write(s) f.write(s2) finally: f.close() arg=None for line in backtick(["gpg", "--list-keys"]).split("\n"): tokens=line.split() if len(tokens)>0 and tokens[0] == "uid": arg=tokens[-1] break # Note: for some reason, I think --no-tty might be needed # here, but maybe not. sysassert(["gpg", "-r", arg, "--no-secmem-warning", "-abs", "--output", "Release.gpg", "Release"]) finally: os.chdir(oldpwd)
def write_debian_changelog(path, spec, srcdir): oldcwd = os.getcwd() os.chdir(srcdir) preamble = "" try: s = preamble + backtick([ "sh", "-c", "git archive %s debian/changelog | tar xOf -" % spec.metadata_gitspec() ]) finally: os.chdir(oldcwd) f = open(path, 'w') lines = s.split("\n") # If the first line starts with "mongodb", it's not a revision # preamble, and so frob the version number. lines[0] = re.sub("^mongodb \\(.*\\)", "mongodb (%s)" % (spec.pversion(Distro("debian"))), lines[0]) # Rewrite every changelog entry starting in mongodb<space> lines = [ re.sub("^mongodb ", "mongodb%s " % (spec.suffix()), l) for l in lines ] lines = [re.sub("^ --", " --", l) for l in lines] s = "\n".join(lines) try: f.write(s) finally: f.close()
def make_deb_repo(repo, distro, build_os): """Make the Debian repo.""" # Note: the Debian repository Packages files must be generated # very carefully in order to be usable. oldpwd = os.getcwd() os.chdir(repo + "../../../../../../") try: dirs = { os.path.dirname(deb)[2:] for deb in packager.backtick(["find", ".", "-name", "*.deb" ]).decode('utf-8').split() } for directory in dirs: st = packager.backtick( ["dpkg-scanpackages", directory, "/dev/null"]) with open(directory + "/Packages", "wb") as fh: fh.write(st) bt = packager.backtick(["gzip", "-9c", directory + "/Packages"]) with open(directory + "/Packages.gz", "wb") as fh: fh.write(bt) finally: os.chdir(oldpwd) # Notes: the Release{,.gpg} files must live in a special place, # and must be created after all the Packages.gz files have been # done. s1 = """Origin: mongodb Label: mongodb Suite: %s Codename: %s/mongodb-enterprise Architectures: amd64 ppc64el s390x arm64 Components: %s Description: MongoDB packages """ % (distro.repo_os_version(build_os), distro.repo_os_version(build_os), distro.repo_component()) if os.path.exists(repo + "../../Release"): os.unlink(repo + "../../Release") if os.path.exists(repo + "../../Release.gpg"): os.unlink(repo + "../../Release.gpg") oldpwd = os.getcwd() os.chdir(repo + "../../") s2 = packager.backtick(["apt-ftparchive", "release", "."]) try: with open("Release", 'wb') as fh: fh.write(s1.encode('utf-8')) fh.write(s2) finally: os.chdir(oldpwd)
def make_deb_repo(repo, distro, build_os): """Make the Debian repo.""" # Note: the Debian repository Packages files must be generated # very carefully in order to be usable. oldpwd = os.getcwd() os.chdir(repo + "../../../../../../") try: dirs = set([ os.path.dirname(deb)[2:] for deb in packager.backtick(["find", ".", "-name", "*.deb"]).split() ]) for directory in dirs: st = packager.backtick(["dpkg-scanpackages", directory, "/dev/null"]) with open(directory + "/Packages", "w") as fh: fh.write(st) bt = packager.backtick(["gzip", "-9c", directory + "/Packages"]) with open(directory + "/Packages.gz", "wb") as fh: fh.write(bt) finally: os.chdir(oldpwd) # Notes: the Release{,.gpg} files must live in a special place, # and must be created after all the Packages.gz files have been # done. s1 = """Origin: mongodb Label: mongodb Suite: %s Codename: %s/mongodb-enterprise Architectures: amd64 ppc64el s390x arm64 Components: %s Description: MongoDB packages """ % (distro.repo_os_version(build_os), distro.repo_os_version(build_os), distro.repo_component()) if os.path.exists(repo + "../../Release"): os.unlink(repo + "../../Release") if os.path.exists(repo + "../../Release.gpg"): os.unlink(repo + "../../Release.gpg") oldpwd = os.getcwd() os.chdir(repo + "../../") s2 = packager.backtick(["apt-ftparchive", "release", "."]) try: with open("Release", 'w') as fh: fh.write(s1) fh.write(s2) finally: os.chdir(oldpwd)
def write_debian_changelog(path, spec, srcdir): oldcwd=os.getcwd() os.chdir(srcdir) preamble="" try: s=preamble+backtick(["sh", "-c", "git archive %s debian/changelog | tar xOf -" % spec.metadata_gitspec()]) finally: os.chdir(oldcwd) f=open(path, 'w') lines=s.split("\n") # If the first line starts with "mongodb", it's not a revision # preamble, and so frob the version number. lines[0]=re.sub("^mongodb \\(.*\\)", "mongodb (%s)" % (spec.pversion(Distro("debian"))), lines[0]) # Rewrite every changelog entry starting in mongodb<space> lines=[re.sub("^mongodb ", "mongodb%s " % (spec.suffix()), l) for l in lines] lines=[re.sub("^ --", " --", l) for l in lines] s="\n".join(lines) try: f.write(s) finally: f.close()
def make_rpm(distro, build_os, arch, spec, srcdir): # Create the specfile. suffix=spec.suffix() sdir=setupdir(distro, build_os, arch, spec) # Use special suse init script if we're building for SUSE # if distro.name() == "suse": os.unlink(sdir+"rpm/init.d-mongod") os.link(sdir+"rpm/init.d-mongod.suse", sdir+"rpm/init.d-mongod") specfile=srcdir+"rpm/mongodb%s.spec" % suffix topdir=ensure_dir('%s/rpmbuild/%s/' % (os.getcwd(), build_os)) for subdir in ["BUILD", "RPMS", "SOURCES", "SPECS", "SRPMS"]: ensure_dir("%s/%s/" % (topdir, subdir)) distro_arch=distro.archname(arch) # RPM tools take these macro files that define variables in # RPMland. Unfortunately, there's no way to tell RPM tools to use # a given file *in addition* to the files that it would already # load, so we have to figure out what it would normally load, # augment that list, and tell RPM to use the augmented list. To # figure out what macrofiles ordinarily get loaded, older RPM # versions had a parameter called "macrofiles" that could be # extracted from "rpm --showrc". But newer RPM versions don't # have this. To tell RPM what macros to use, older versions of # RPM have a --macros option that doesn't work; on these versions, # you can put a "macrofiles" parameter into an rpmrc file. But # that "macrofiles" setting doesn't do anything for newer RPM # versions, where you have to use the --macros flag instead. And # all of this is to let us do our work with some guarantee that # we're not clobbering anything that doesn't belong to us. Why is # RPM so braindamaged? macrofiles=[l for l in backtick(["rpm", "--showrc"]).split("\n") if l.startswith("macrofiles")] flags=[] macropath=os.getcwd()+"/macros" write_rpm_macros_file(macropath, topdir, distro.release_dist(build_os)) if len(macrofiles)>0: macrofiles=macrofiles[0]+":"+macropath rcfile=os.getcwd()+"/rpmrc" write_rpmrc_file(rcfile, macrofiles) flags=["--rpmrc", rcfile] else: # This hard-coded hooey came from some box running RPM # 4.4.2.3. It may not work over time, but RPM isn't sanely # configurable. flags=["--macros", "/usr/lib/rpm/macros:/usr/lib/rpm/%s-linux/macros:/etc/rpm/macros.*:/etc/rpm/macros:/etc/rpm/%s-linux/macros:~/.rpmmacros:%s" % (distro_arch, distro_arch, macropath)] # Put the specfile and the tar'd up binaries and stuff in # place. FIXME: see if shutil.copyfile can do this without too # much hassle. sysassert(["cp", "-v", specfile, topdir+"SPECS/"]) oldcwd=os.getcwd() os.chdir(sdir+"/../") try: sysassert(["tar", "-cpzf", topdir+"SOURCES/mongodb%s-%s.tar.gz" % (suffix, spec.pversion(distro)), os.path.basename(os.path.dirname(sdir))]) finally: os.chdir(oldcwd) # Do the build. flags.extend(["-D", "dynamic_version " + spec.pversion(distro), "-D", "dynamic_release " + spec.prelease()]) sysassert(["rpmbuild", "-ba", "--target", distro_arch] + flags + ["%s/SPECS/mongodb%s.spec" % (topdir, suffix)]) r=distro.repodir(arch, build_os, spec) ensure_dir(r) # FIXME: see if some combination of shutil.copy<hoohah> and glob # can do this without shelling out. sysassert(["sh", "-c", "cp -v \"%s/RPMS/%s/\"*.rpm \"%s\""%(topdir, distro_arch, r)]) return r