示例#1
0
def main():
    """
    Main entry point
    """
    setup_sigint_handler()
    shutil.rmtree(BUILD_DIR)
    os.mkdir(BUILD_DIR)
    spec = rpm.ts().parseSpec(sys.argv[1])
    clean = True
    if "-noclean" in sys.argv:
        clean = False

    # subdirectory of builddir in which the tarball is unpacked;
    # set by RPM after processing the spec file
    # if the source file isn't a tarball this won't be set!
    build_subdir = rpm.expandMacro("%buildsubdir")
    prepare_build_dir(spec, build_subdir)

    if os.path.isdir(os.path.join(BUILD_DIR, build_subdir, "debian")):
        shutil.rmtree(os.path.join(BUILD_DIR, build_subdir, "debian"))

    # a package with no original tarball is built as a 'native debian package'
    native = debianmisc.is_native(spec)

    if not native:
        # copy over the source, run the prep rule to unpack it, then
        # rename it as deb expects this should be based on the rewritten
        # (or not) source name in the debian package - build the debian
        # dir first and then rename the tarball as needed
        rename_source(spec, spec.sourceHeader['name'],
                      spec.sourceHeader['version'])

    debian_dir_from_spec(spec, os.path.join(BUILD_DIR, build_subdir),
                         sys.argv[1], native)

    cmd = "cd %s\ndpkg-source -b --auto-commit %s" % (BUILD_DIR, build_subdir)
    print cmd
    res = subprocess.call(cmd, shell=True)
    assert res == 0

    for i in glob.glob(os.path.join(BUILD_DIR, "*")):
        if build_subdir in i:
            continue
        shutil.copy2(i, SRPM_DIR)
        if clean:
            os.unlink(i)
    if clean:
        shutil.rmtree(TMPDIR)
    else:
        print "makedeb: dpkg input files in %s" % TMPDIR
示例#2
0
文件: spec.py 项目: johnelse/planex
    def __init__(self, path, target="rpm", map_name=None, dist="",
                 check_package_name=True, topdir=None):
        if map_name:
            self.map_package_name = map_name
        else:
            self.map_package_name = identity_list

        # _topdir defaults to $HOME/rpmbuild
        if topdir:
            rpm.addMacro('_topdir', topdir)

        rpm.addMacro('_specdir', os.path.dirname(path))

        self.path = os.path.join(specdir(), os.path.basename(path))
        with open(path) as spec:
            self.spectext = spec.readlines()

        # '%dist' in the host (where we build the source package)
        # might not match '%dist' in the chroot (where we build
        # the binary package).   We must override it on the host,
        # otherwise the names of packages in the dependencies won't
        # match the files actually produced by mock.
        self.dist = ""
        if target == "rpm":
            self.dist = dist

        rpm.addMacro('dist', self.dist)
        self.spec = rpm.ts().parseSpec(path)

        if check_package_name:
            file_basename = os.path.basename(path).split(".")[0]
            if file_basename != self.name():
                raise SpecNameMismatch(
                    "spec file name '%s' does not match package name '%s'" %
                    (path, self.name()))

        if target == "rpm":
            self.rpmfilenamepat = rpm.expandMacro('%_build_name_fmt')
            self.srpmfilenamepat = rpm.expandMacro('%_build_name_fmt')
            self.map_arch = identity

        else:
            separator = '.' if debianmisc.is_native(self.spec) else '-'
            basename = "%{NAME}_%{VERSION}" + separator
            self.rpmfilenamepat = basename + "%{RELEASE}_%{ARCH}.deb"
            self.srpmfilenamepat = basename + "%{RELEASE}.dsc"
            self.map_arch = map_arch_deb