Beispiel #1
0
    def _write_python_tarball(self, instance, pkg_dir, ensure_exists=None):
        def prefix_exists(text, in_what):
            for t in in_what:
                if t.startswith(text):
                    return True
            return False

        pkg_name = instance.egg_info['name']
        version = instance.egg_info['version']
        base_name = "%s-%s" % (pkg_name, version)
        cmdline = [
            sys.executable,
            "setup.py",
            "sdist",
            "--formats=tar",
            "--dist-dir",
            self.rpm_sources_dir,
        ]
        out_filename = sh.joinpths(self.log_dir,
                                   "sdist-%s.log" % (instance.name))
        sh.execute_save_output(cmdline, cwd=pkg_dir, out_filename=out_filename)
        archive_name = sh.joinpths(self.rpm_sources_dir,
                                   "%s.tar" % (base_name))
        if ensure_exists:
            with contextlib.closing(tarfile.open(archive_name, 'r')) as tfh:
                tar_entries = [t.path for t in tfh.getmembers()]
            missing_paths = {}
            for path in ensure_exists:
                tar_path = sh.joinpths(base_name, path)
                source_path = sh.joinpths(pkg_dir, path)
                if not prefix_exists(tar_path,
                                     tar_entries) and sh.exists(source_path):
                    missing_paths[tar_path] = source_path
            if missing_paths:
                utils.log_iterable(
                    sorted(missing_paths.keys()),
                    logger=LOG,
                    header='%s paths were not archived and will now be' %
                    (len(missing_paths)))
                with contextlib.closing(tarfile.open(archive_name,
                                                     'a')) as tfh:
                    for (tar_path, source_path) in missing_paths.items():
                        tfh.add(source_path, tar_path)
        sh.gzip(archive_name)
        sh.unlink(archive_name)
Beispiel #2
0
    def _write_python_tarball(self, instance, pkg_dir, ensure_exists=None):

        def prefix_exists(text, in_what):
            for t in in_what:
                if t.startswith(text):
                    return True
            return False

        pkg_name = instance.egg_info['name']
        version = instance.egg_info['version']
        base_name = "%s-%s" % (pkg_name, version)
        cmdline = [
            sys.executable,
            "setup.py",
            "sdist",
            "--formats=tar",
            "--dist-dir", self.rpm_sources_dir,
        ]
        env_overrides = {
            'PBR_VERSION': version,
        }
        out_filename = sh.joinpths(self.log_dir, "sdist-%s.log" % (instance.name))
        sh.execute_save_output(cmdline, out_filename,
                               cwd=pkg_dir, env_overrides=env_overrides)
        archive_name = sh.joinpths(self.rpm_sources_dir, "%s.tar" % (base_name))
        if ensure_exists:
            with contextlib.closing(tarfile.open(archive_name, 'r')) as tfh:
                tar_entries = [t.path for t in tfh.getmembers()]
            missing_paths = {}
            for path in ensure_exists:
                tar_path = sh.joinpths(base_name, path)
                source_path = sh.joinpths(pkg_dir, path)
                if not prefix_exists(tar_path, tar_entries) and sh.exists(source_path):
                    missing_paths[tar_path] = source_path
            if missing_paths:
                utils.log_iterable(sorted(missing_paths.keys()),
                                   logger=LOG,
                                   header='%s paths were not archived and will now be' % (len(missing_paths)))
                with contextlib.closing(tarfile.open(archive_name, 'a')) as tfh:
                    for (tar_path, source_path) in missing_paths.items():
                        tfh.add(source_path, tar_path)
        sh.gzip(archive_name)
        sh.unlink(archive_name)
Beispiel #3
0
 def _write_git_tarball(self, pkg_dir, spec_filename):
     cmdline = [
         "rpm",
         "-q",
         "--specfile", spec_filename,
         "--qf", "%{NAME}-%{VERSION}\n"
     ]
     tar_base = sh.execute(cmdline, cwd=pkg_dir)[0].splitlines()[0].strip()
     # git 1.7.1 from RHEL doesn't understand --format=tar.gz
     output_filename = sh.joinpths(self.rpm_sources_dir,
                                   "%s.tar" % tar_base)
     cmdline = [
         "git",
         "archive",
         "--format=tar",
         "--prefix=%s/" % tar_base,
         "--output=%s" % output_filename,
         "HEAD",
     ]
     sh.execute(cmdline, cwd=pkg_dir)
     sh.gzip(output_filename)
     sh.unlink(output_filename)
Beispiel #4
0
    def _write_git_tarball(self, instance, pkg_dir, spec_filename):
        cmdline = [
            "rpm", "-q", "--specfile", spec_filename, "--qf",
            "%{NAME}-%{VERSION}\n"
        ]
        tar_base = sh.execute(cmdline, cwd=pkg_dir)[0].splitlines()[0].strip()

        # NOTE(harlowja): git 1.7.1 from RHEL doesn't understand --format=tar.gz
        output_filename = sh.joinpths(self.rpm_sources_dir,
                                      "%s.tar" % tar_base)
        cmdline = [
            "git",
            "archive",
            "--format=tar",
            "--prefix=%s/" % tar_base,
            "--output=%s" % output_filename,
            "HEAD",
        ]
        out_filename = sh.joinpths(self.log_dir,
                                   "git-tar-%s.log" % instance.name)
        sh.execute_save_output(cmdline, cwd=pkg_dir, out_filename=out_filename)
        sh.gzip(output_filename)
        sh.unlink(output_filename)