Esempio n. 1
0
 def _install_gerrit_dependencies(self, repo, project, install_path):
     try:
         review = GerritReview(repo.head.change_id, project.git_path)
         LOG.info("Installing '%s' pip dependencies to the virtualenv",
                  project.name)
         execute(project.install_command %
                 review.build_pip_dependencies(string=True), install_path)
     except Exception as e:
         LOG.warning("Could not install gerrit dependencies!!! "
                     "Error was: %s", e)
Esempio n. 2
0
    def build(self):
        distro = platform.linux_distribution()[0]
        if distro not in SUPPORTED_DISTROS.keys():
            raise Exception("Sorry, '%s' is an unsupported distribution" %
                            distro)
        target = SUPPORTED_DISTROS[distro]

        # not wrapping in a try block - handled by caller
        execute("fpm -s dir -t %s -n %s -v %s %s" %
                (target, self.name, self.version, self.path))
 def _install_gerrit_dependencies(self, repo, project, install_path):
     try:
         review = GerritReview(repo.head.change_id, project.git_path)
         LOG.info("Installing '%s' pip dependencies to the virtualenv",
                  project.name)
         execute(
             project.install_command %
             review.build_pip_dependencies(string=True), install_path)
     except Exception as e:
         LOG.warning(
             "Could not install gerrit dependencies!!! "
             "Error was: %s", e)
Esempio n. 4
0
    def build(self):
        target = self._get_platform_target()
        overwrite = ''
        if self.overwrite:
            overwrite = '-f'

        deps = ''
        if self.dependencies:
            deps = '-d %s' % (' -d '.join(self.dependencies))

        if not os.path.exists(self.output_dir):
            os.makedirs(self.output_dir)

        # not wrapping in a try block - handled by caller
        execute("fpm %s -s dir -t %s -n %s -v %s %s %s" % (overwrite,
                target, self.name, self.version, deps, self.install_path),
                self.output_dir)
Esempio n. 5
0
    def build(self):
        target = self._get_platform_target()
        overwrite = ''
        if self.overwrite:
            overwrite = '-f'

        deps = ''
        if self.dependencies:
            deps = '-d %s' % (' -d '.join(self.dependencies))

        if not os.path.exists(self.output_dir):
            os.makedirs(self.output_dir)

        # not wrapping in a try block - handled by caller
        execute(
            "fpm %s -s dir -t %s -n %s -v %s %s %s" %
            (overwrite, target, self.name, self.version, deps,
             self.install_path), self.output_dir)
Esempio n. 6
0
    def _build(self):
        spec = self._spec

        self._tempdir = tempfile.mkdtemp(prefix='giftwrap')
        src_path = os.path.join(self._tempdir, 'src')
        build_path = os.path.join(self._tempdir, 'build')
        os.makedirs(build_path)
        LOG.debug("Temporary working directory: %s", self._tempdir)

        for project in spec.projects:
            LOG.info("Beginning to build '%s'", project.name)

            install_path = os.path.join(build_path,
                                        relative_pathify(project.install_path))
            LOG.debug("Installing '%s' to '%s'", project.name, install_path)
            os.makedirs(install_path)

            # clone the project's source to a temporary directory
            project_src_path = os.path.join(src_path, project.name)
            os.makedirs(project_src_path)

            LOG.info("Fetching source code for '%s'", project.name)
            repo = OpenstackGitRepo(project.giturl, project.gitref)
            repo.clone(project_src_path)

            # tell package users where this came from
            gitinfo_file = os.path.join(install_path, 'gitinfo')
            with open(gitinfo_file, 'w') as fh:
                fh.write("%s %s" % (project.giturl, repo.head.hexsha))

            # start building the virtualenv for the project
            LOG.info("Creating the virtualenv for '%s'", project.name)
            execute(project.venv_command, install_path)

            # install into the virtualenv
            LOG.info("Installing '%s' to the virtualenv", project.name)
            venv_python_path = os.path.join(install_path, 'bin/python')
            venv_pip_path = os.path.join(install_path, 'bin/pip')

            deps = " ".join(project.pip_dependencies)
            execute("%s install %s" % (venv_pip_path, deps))

            if spec.settings.gerrit_dependencies:
                self._install_gerrit_dependencies(repo, project, install_path)

            execute("%s setup.py install" % venv_python_path, project_src_path)
            execute("%s install pbr" % venv_pip_path)

            # now build the package
            pkg = Package(project.package_name, project.version, build_path,
                          relative_pathify(project.install_path),
                          spec.settings.force_overwrite,
                          project.system_dependencies)
            pkg.build()
Esempio n. 7
0
    def build(self):
        distro = platform.linux_distribution()[0]
        if distro not in SUPPORTED_DISTROS.keys():
            raise Exception("Sorry, '%s' is an unsupported distribution" %
                            distro)
        target = SUPPORTED_DISTROS[distro]

        overwrite = ''
        if self.overwrite:
            overwrite = '-f'

        deps = ''
        if self.dependencies:
            deps = '-d %s' % (' -d '.join(self.dependencies))

        # not wrapping in a try block - handled by caller
        execute("fpm %s -s dir -t %s -n %s -v %s %s %s" % (overwrite, target,
                self.name, self.version, deps, self.install_path),
                self.build_path)
Esempio n. 8
0
    def _build(self):
        spec = self._spec

        tempdir = tempfile.mkdtemp(prefix='giftwrap')
        src_dir = os.path.join(tempdir, 'src')
        LOG.debug("Temporary working directory: %s", tempdir)

        for project in spec.projects:
            LOG.info("Beginning to build '%s'", project.name)

            # if anything is in our way, see if we can get rid of it
            if os.path.exists(project.install_path):
                if spec.settings.force_overwrite:
                    LOG.info("force_overwrite is set, so removing "
                             "existing path '%s'" % project.install_path)
                    shutil.rmtree(project.install_path)
                else:
                    raise Exception("Install path '%s' already exists" %
                                    project.install_path)
            os.makedirs(project.install_path)

            # clone the project's source to a temporary directory
            project_src_path = os.path.join(src_dir, project.name)
            os.makedirs(project_src_path)

            LOG.info("Fetching source code for '%s'", project.name)
            repo = OpenstackGitRepo(project.giturl, project.gitref)
            repo.clone(project_src_path)

            # start building the virtualenv for the project
            LOG.info("Creating the virtualenv for '%s'", project.name)
            execute(project.venv_command, project.install_path)

            # install into the virtualenv
            LOG.info("Installing '%s' to the virtualenv", project.name)
            venv_python_path = os.path.join(project.install_path, 'bin/python')
            venv_pip_path = os.path.join(project.install_path, 'bin/pip')

            deps = " ".join(project.pip_dependencies)
            execute("%s install %s" % (venv_pip_path, deps))

            if spec.settings.gerrit_dependencies:
                self._install_gerrit_dependencies(repo, project)

            execute("%s setup.py install" % venv_python_path, project_src_path)
            execute("%s install pbr" % venv_pip_path)

            # now build the package
            pkg = Package(project.package_name, project.version,
                          project.install_path, spec.settings.force_overwrite,
                          project.system_dependencies)
            pkg.build()
Esempio n. 9
0
    def build(self):
        """ this is where all the magic happens """

        try:
            spec = self._spec
            for project in self._spec.projects:
                LOG.info("Beginning to build '%s'", project.name)
                os.makedirs(project.install_path)

                LOG.info("Fetching source code for '%s'", project.name)
                repo = OpenstackGitRepo(project.giturl, project.gitref)
                repo.clone(project.install_path)
                review = GerritReview(repo.change_id, project.git_path)

                LOG.info("Creating the virtualenv for '%s'", project.name)
                execute(project.venv_command, project.install_path)

                LOG.info("Installing '%s' pip dependencies to the virtualenv",
                         project.name)
                execute(project.install_command %
                        review.build_pip_dependencies(string=True),
                        project.install_path)

                LOG.info("Installing '%s' to the virtualenv", project.name)
                execute(".venv/bin/python setup.py install",
                        project.install_path)

                if not spec.settings.all_in_one:
                    pkg = Package(project.package_name, project.version,
                                  project.install_path, True)
                    pkg.build()

        except Exception as e:
            LOG.exception("Oops. Something went wrong. Error was:\n%s", e)
            sys.exit(-1)
Esempio n. 10
0
    def _build(self):
        spec = self._spec

        self._tempdir = tempfile.mkdtemp(prefix='giftwrap')
        src_path = os.path.join(self._tempdir, 'src')
        LOG.debug("Temporary working directory: %s", self._tempdir)

        for project in spec.projects:
            LOG.info("Beginning to build '%s'", project.name)

            install_path = project.install_path
            LOG.debug("Installing '%s' to '%s'", project.name, install_path)

            # if anything is in our way, see if we can get rid of it
            if os.path.exists(install_path):
                if spec.settings.force_overwrite:
                    LOG.info("force_overwrite is set, so removing "
                             "existing path '%s'" % install_path)
                    shutil.rmtree(install_path)
                else:
                    raise Exception("Install path '%s' already exists" %
                                    install_path)
            os.makedirs(install_path)

            # clone the project's source to a temporary directory
            project_src_path = os.path.join(src_path, project.name)
            os.makedirs(project_src_path)

            LOG.info("Fetching source code for '%s'", project.name)
            repo = OpenstackGitRepo(project.giturl,
                                    project.name,
                                    project.gitref,
                                    depth=project.gitdepth)
            repo.clone(project_src_path)

            # tell package users where this came from
            gitinfo_file = os.path.join(install_path, 'gitinfo')
            with open(gitinfo_file, 'w') as fh:
                fh.write("%s %s" % (project.giturl, repo.head.hexsha))

            # start building the virtualenv for the project
            LOG.info("Creating the virtualenv for '%s'", project.name)
            execute(project.venv_command, install_path)

            # install into the virtualenv
            LOG.info("Installing '%s' to the virtualenv", project.name)
            venv_python_path = os.path.join(install_path, 'bin/python')
            venv_pip_path = os.path.join(install_path, 'bin/pip')

            deps = " ".join(project.pip_dependencies)
            execute("%s install %s" % (venv_pip_path, deps))

            if spec.settings.include_config:
                src_config = os.path.join(project_src_path, 'etc')
                dest_config = os.path.join(install_path, 'etc')
                if not os.path.exists(src_config):
                    LOG.warning(
                        "Project configuration does not seem to exist "
                        "in source repo '%s'. Skipping.", project.name)
                else:
                    LOG.debug("Copying config from '%s' to '%s'", src_config,
                              dest_config)
                    distutils.dir_util.copy_tree(src_config, dest_config)

            if spec.settings.gerrit_dependencies:
                self._install_gerrit_dependencies(repo, project, install_path)

            execute("%s setup.py install" % venv_python_path, project_src_path)
            execute("%s install pbr" % venv_pip_path)

            # now build the package
            pkg = Package(project.package_name, project.version, install_path,
                          spec.settings.output_dir,
                          spec.settings.force_overwrite,
                          project.system_dependencies)
            pkg.build()
Esempio n. 11
0
 def test_execute_raises_exception_on_error(self):
     cmd = 'echo stderr >&2 && false'
     with self.assertRaises(Exception):
         util.execute(cmd)
Esempio n. 12
0
    def test_execute_returns_stderr_tuple(self):
        cmd = 'echo stderr >&2'
        _, _, err = util.execute(cmd)

        self.assertEquals('stderr\n', err)
Esempio n. 13
0
    def test_execute_returns_stdout_tuple(self):
        cmd = 'echo stdout'
        _, out, _ = util.execute(cmd)

        self.assertEquals('stdout\n', out)
Esempio n. 14
0
    def test_execute_returns_exitcode_tuple(self):
        cmd = 'test true'
        result, _, _ = util.execute(cmd)

        self.assertEquals(0, result)
Esempio n. 15
0
 def _execute(self, command, cwd=None, exit=0):
     return execute(command, cwd, exit)
Esempio n. 16
0
 def test_nonzero_exit_code(self):
     cmd = 'echo stdout && false'
     out = util.execute(cmd, exit=1)
     self.assertEqual(b'stdout\n', out)
Esempio n. 17
0
    def _build(self):
        spec = self._spec

        self._tempdir = tempfile.mkdtemp(prefix='giftwrap')
        src_path = os.path.join(self._tempdir, 'src')
        LOG.debug("Temporary working directory: %s", self._tempdir)

        for project in spec.projects:
            LOG.info("Beginning to build '%s'", project.name)

            install_path = project.install_path
            LOG.debug("Installing '%s' to '%s'", project.name, install_path)

            # if anything is in our way, see if we can get rid of it
            if os.path.exists(install_path):
                if spec.settings.force_overwrite:
                    LOG.info("force_overwrite is set, so removing "
                             "existing path '%s'" % install_path)
                    shutil.rmtree(install_path)
                else:
                    raise Exception("Install path '%s' already exists" %
                                    install_path)
            os.makedirs(install_path)

            # clone the project's source to a temporary directory
            project_src_path = os.path.join(src_path, project.name)
            os.makedirs(project_src_path)

            LOG.info("Fetching source code for '%s'", project.name)
            repo = OpenstackGitRepo(project.giturl, project.name,
                                    project.gitref,
                                    depth=project.gitdepth)
            repo.clone(project_src_path)

            # tell package users where this came from
            gitinfo_file = os.path.join(install_path, 'gitinfo')
            with open(gitinfo_file, 'w') as fh:
                fh.write("%s %s" % (project.giturl, repo.head.hexsha))

            # start building the virtualenv for the project
            LOG.info("Creating the virtualenv for '%s'", project.name)
            execute(project.venv_command, install_path)

            # install into the virtualenv
            LOG.info("Installing '%s' to the virtualenv", project.name)
            venv_pip_path = os.path.join(install_path, 'bin/pip')

            deps = " ".join(project.pip_dependencies)
            execute("%s install %s" % (venv_pip_path, deps))

            if spec.settings.include_config:
                src_config = os.path.join(project_src_path, 'etc')
                dest_config = os.path.join(install_path, 'etc')
                if not os.path.exists(src_config):
                    LOG.warning("Project configuration does not seem to exist "
                                "in source repo '%s'. Skipping.", project.name)
                else:
                    LOG.debug("Copying config from '%s' to '%s'", src_config,
                              dest_config)
                    distutils.dir_util.copy_tree(src_config, dest_config)

            if spec.settings.gerrit_dependencies:
                self._install_gerrit_dependencies(repo, project, install_path)

            execute("%s install %s" % (venv_pip_path, project_src_path))

            # now build the package
            pkg = Package(project.package_name, project.version,
                          install_path, spec.settings.output_dir,
                          spec.settings.force_overwrite,
                          project.system_dependencies)
            pkg.build()
Esempio n. 18
0
 def test_execute_returns_stdout(self):
     cmd = 'echo stdout'
     out = util.execute(cmd)
     self.assertEqual(b'stdout\n', out)
Esempio n. 19
0
 def _execute(self, command, cwd=None, exit=0):
     return execute(command, cwd, exit)
Esempio n. 20
0
 def test_nonzero_exit_code(self):
     cmd = 'echo stdout && false'
     out = util.execute(cmd, exit=1)
     self.assertEqual(b'stdout\n', out)
Esempio n. 21
0
 def test_execute_raises_exception_on_error(self):
     cmd = 'echo stderr >&2 && false'
     with self.assertRaises(Exception):
         util.execute(cmd)
Esempio n. 22
0
 def test_execute_returns_stdout(self):
     cmd = 'echo stdout'
     out = util.execute(cmd)
     self.assertEqual(b'stdout\n', out)