Exemplo n.º 1
0
 def _check_releaser_config(self):
     """
     Verify this release target has all the config options it needs.
     """
     for opt in self.GLOBAL_REQUIRED_CONFIG:
         if not self.releaser_config.has_option(self.target, opt):
             raise TitoException(
                     "Release target '%s' missing required option '%s'" %
                     (self.target, opt))
     for opt in self.REQUIRED_CONFIG:
         if not self.releaser_config.has_option(self.target, opt):
             raise TitoException(
                     "Release target '%s' missing required option '%s'" %
                     (self.target, opt))
Exemplo n.º 2
0
    def __init__(self, name=None, tag=None, build_dir=None,
            config=None, user_config=None,
            args=None, **kwargs):

        # Mock builders need to use the packages normally configured builder
        # to get at a proper SRPM:
        self.normal_builder = create_builder(name, tag, config,
                build_dir, user_config, args, **kwargs)

        Builder.__init__(self, name=name, tag=tag,
                build_dir=build_dir, config=config,
                user_config=user_config,
                args=args, **kwargs)

        self.mock_tag = args['mock'][0]
        self.mock_cmd_args = ""
        if 'mock_config_dir' in args:
            mock_config_dir = args['mock_config_dir'][0]
            if not mock_config_dir.startswith("/"):
                # If not an absolute path, assume below git root:
                mock_config_dir = os.path.join(self.git_root, mock_config_dir)
            if not os.path.exists(mock_config_dir):
                raise TitoException("No such mock config dir: %s" % mock_config_dir)
            self.mock_cmd_args = "%s --configdir=%s" % (self.mock_cmd_args, mock_config_dir)

        # Optional argument which will skip mock --init and add --no-clean
        # and --no-cleanup-after:
        self.speedup = False
        if 'speedup' in args:
            self.speedup = True
            self.mock_cmd_args = "%s --no-clean --no-cleanup-after" % \
                    (self.mock_cmd_args)

        if 'mock_args' in args:
            self.mock_cmd_args = "%s %s" % (self.mock_cmd_args, args['mock_args'][0])
Exemplo n.º 3
0
    def _update_package_metadata(self, new_version):
        """
        We track package metadata in the .tito/packages/ directory. Each
        file here stores the latest package version (for the git branch you
        are on) as well as the relative path to the project's code. (from the
        git root)
        """
        self._clear_package_metadata()

        new_version_w_suffix = self._get_suffixed_version(new_version)
        # Write out our package metadata:
        metadata_file = os.path.join(self.rel_eng_dir, "packages",
                self.project_name)

        with open(metadata_file, 'w') as f:
            f.write("%s %s\n" % (new_version_w_suffix, self.relative_project_dir))

        # Git add it (in case it's a new file):
        run_command("git add %s" % metadata_file)
        run_command("git add %s" % os.path.join(self.full_project_dir,
            self.spec_file_name))

        fmt = ('Automatic commit of package '
               '[%(name)s] %(release_type)s [%(version)s].')
        if self.config.has_option(BUILDCONFIG_SECTION, "tag_commit_message_format"):
            fmt = self.config.get(BUILDCONFIG_SECTION, "tag_commit_message_format")
        new_version_w_suffix = self._get_suffixed_version(new_version)
        try:
            msg = fmt % {
                'name': self.project_name,
                'release_type': self.release_type(),
                'version': new_version_w_suffix,
            }
        except KeyError:
            exc = sys.exc_info()[1]
            raise TitoException('Unknown placeholder %s in tag_commit_message_format'
                                % exc)

        run_command('git commit -m {0} -m {1} -m {2}'.format(
            quote(msg), quote("Created by command:"), quote(" ".join(sys.argv[:]))))

        new_tag = self._get_new_tag(new_version)
        tag_msg = "Tagging package [%s] version [%s] in directory [%s]." % \
                (self.project_name, new_tag,
                        self.relative_project_dir)

        # Optionally gpg sign the tag
        sign_tag = ""
        if self.config.has_option(BUILDCONFIG_SECTION, "sign_tag"):
            if self.config.getboolean(BUILDCONFIG_SECTION, "sign_tag"):
                sign_tag = "-s "

        run_command('git tag %s -m "%s" %s' % (sign_tag, tag_msg, new_tag))
        print
        info_out("Created tag: %s" % new_tag)
        print("   View: git show HEAD")
        print("   Undo: tito tag -u")
        print("   Push: git push --follow-tags origin")
Exemplo n.º 4
0
    def _parse_build_target(self, build_target):
        """ Parses a string in the format of branch:target """
        if not build_target:
            raise TitoException("Invalid build_target: %s. Format: <branch>:<target>"
                                % build_target)

        parts = build_target.split(":")
        if len(parts) != 2:
            raise TitoException("Invalid build_target: %s. Format: <branch>:<target>"
                                % build_target)
        branch = parts[0]
        if not branch in self.valid_branches:
            raise TitoException("Invalid build_target: %s. Unknown branch reference."
                                % build_target)
        target = parts[1]
        if not target:
            raise TitoException("Invalid build_target: %s. Empty target" % build_target)

        return (branch, target)
Exemplo n.º 5
0
    def _undo(self):
        """
        Undo the most recent tag.

        Tag commit must be the most recent commit, and the tag must not
        exist in the remote git repo, otherwise we report and error out.
        """
        tag = self._get_tag_for_version(get_latest_tagged_version(self.project_name))
        info_out("Undoing tag: %s" % tag)
        if not tag_exists_locally(tag):
            raise TitoException(
                "Cannot undo tag that does not exist locally.")
        if not self.offline and tag_exists_remotely(tag):
            raise TitoException("Cannot undo tag that has been pushed.")

        # Tag must be the most recent commit.
        if not head_points_to_tag(tag):
            raise TitoException("Cannot undo if tag is not the most recent commit.")

        # Everything looks good:
        print
        undo_tag(tag)
Exemplo n.º 6
0
 def check_tag_precondition(self):
     if self.config.has_option("tagconfig", "require_package"):
         packages = self.config.get("tagconfig", "require_package").split(',')
         ts = rpm.TransactionSet()
         missing_packages = []
         for p in packages:
             p = p.strip()
             mi = ts.dbMatch('name', p)
             if not mi:
                 missing_packages.append(p)
         if missing_packages:
             raise TitoException("To tag this package, you must first install: %s" %
                 ', '.join(missing_packages))
Exemplo n.º 7
0
    def __init__(self,
                 name=None,
                 version=None,
                 tag=None,
                 build_dir=None,
                 pkg_config=None,
                 global_config=None,
                 user_config=None,
                 args=None,
                 **kwargs):

        Builder.__init__(self,
                         name=name,
                         version=version,
                         tag=tag,
                         build_dir=build_dir,
                         pkg_config=pkg_config,
                         global_config=global_config,
                         user_config=user_config,
                         args=args,
                         **kwargs)

        self.mock_tag = args['mock']
        self.mock_cmd_args = ""
        if 'mock_config_dir' in args:
            mock_config_dir = args['mock_config_dir']
            if not mock_config_dir.startswith("/"):
                # If not an absolute path, assume below git root:
                mock_config_dir = os.path.join(self.git_root, mock_config_dir)
            if not os.path.exists(mock_config_dir):
                raise TitoException("No such mock config dir: %s" %
                                    mock_config_dir)
            self.mock_cmd_args = "%s --configdir=%s" % (self.mock_cmd_args,
                                                        mock_config_dir)

        # Optional argument which will skip mock --init and add --no-clean
        # and --no-cleanup-after:
        self.speedup = False
        if 'speedup' in args:
            self.speedup = True
            self.mock_cmd_args = "%s --no-clean --no-cleanup-after" % \
                    (self.mock_cmd_args)
Exemplo n.º 8
0
 def _check_required_args(self):
     for arg in self.REQUIRED_ARGS:
         if arg not in self.args:
             raise TitoException("Builder missing required argument: %s" %
                                 arg)