예제 #1
0
class ReleaserTests(unittest.TestCase):
    @mock.patch("tito.release.main.create_builder")
    @mock.patch("tito.release.main.mkdtemp")
    def setUp(self, mkdtemp, create_builder):
        self.config = RawConfigParser()

        self.releaser_config = RawConfigParser()
        self.releaser_config.add_section("test")
        self.releaser_config.set('test', "releaser", "tito.release.Releaser")

        self.releaser = Releaser("titotestpkg", None, "/tmp/tito/",
                                 self.config, {}, "test", self.releaser_config,
                                 False, False, False, **{"offline": True})

    @mock.patch(builtins_input)
    def test_ask_yes_or_no(self, input_mock):
        input_mock.side_effect = "y"
        assert self.releaser._ask_yes_no()

        input_mock.side_effect = "n"
        assert not self.releaser._ask_yes_no()

        input_mock.side_effect = ["yy", "y"]
        assert self.releaser._ask_yes_no()

        input_mock.side_effect = ["yy", "no"]
        assert not self.releaser._ask_yes_no()
예제 #2
0
파일: cli.py 프로젝트: Conan-Kudo/tito
 def _read_releaser_config(self):
     """
     Read the releaser targets from .tito/releasers.conf.
     """
     rel_eng_dir = os.path.join(find_git_root(), tito_config_dir())
     filename = os.path.join(rel_eng_dir, RELEASERS_CONF_FILENAME)
     config = RawConfigParser()
     config.read(filename)
     return config
예제 #3
0
 def _read_releaser_config(self):
     """
     Read the releaser targets from .tito/releasers.conf.
     """
     rel_eng_dir = os.path.join(find_git_root(), tito_config_dir())
     filename = os.path.join(rel_eng_dir, RELEASERS_CONF_FILENAME)
     config = RawConfigParser()
     config.read(filename)
     return config
예제 #4
0
    def setUp(self, mkdtemp, create_builder):
        self.config = RawConfigParser()

        self.releaser_config = RawConfigParser()
        self.releaser_config.add_section("test")
        self.releaser_config.set('test', "releaser", "tito.release.Releaser")

        self.releaser = Releaser("titotestpkg", None, "/tmp/tito/",
                                 self.config, {}, "test", self.releaser_config,
                                 False, False, False, **{"offline": True})
예제 #5
0
    def setUp(self):
        TitoGitTestFixture.setUp(self)

        self.create_project(PKG_NAME)
        os.chdir(self.repo_dir)

        self.config = RawConfigParser()
        self.config.add_section("buildconfig")
        self.config.set("buildconfig", "builder", "tito.builder.Builder")
        self.config.set("buildconfig", "offline", "true")

        self.releaser_config = RawConfigParser()
        self.releaser_config.add_section('test')
        self.releaser_config.set('test', 'releaser', 'tito.release.Releaser')
예제 #6
0
    def setUp(self):
        TitoGitTestFixture.setUp(self)

        self.create_project(PKG_NAME)
        os.chdir(self.repo_dir)

        self.config = RawConfigParser()
        self.config.add_section("buildconfig")
        self.config.set("buildconfig", "builder", "tito.builder.Builder")
        self.config.set("buildconfig", "offline", "true")

        self.releaser_config = RawConfigParser()
        self.releaser_config.add_section('test')
        self.releaser_config.set('test', 'releaser',
            'tito.release.Releaser')
예제 #7
0
파일: cli.py 프로젝트: Conan-Kudo/tito
    def _read_config(self):
        """
        Read global build.py configuration from the .tito dir of the git
        repository we're being run from.

        NOTE: We always load the latest config file, not tito.props as it
        was for the tag being operated on.
        """
        # List of filepaths to config files we'll be loading:
        rel_eng_dir = os.path.join(find_git_root(), tito_config_dir())
        filename = os.path.join(rel_eng_dir, TITO_PROPS)
        if not os.path.exists(filename):
            error_out("Unable to locate branch configuration: %s"
                "\nPlease run 'tito init'" % filename)

        # Load the global config. Later, when we know what tag/package we're
        # building, we may also load that and potentially override some global
        # settings.
        config = RawConfigParser()
        config.read(filename)

        self._check_legacy_globalconfig(config)
        return config
예제 #8
0
    def _read_config(self):
        """
        Read global build.py configuration from the .tito dir of the git
        repository we're being run from.

        NOTE: We always load the latest config file, not tito.props as it
        was for the tag being operated on.
        """
        # List of filepaths to config files we'll be loading:
        rel_eng_dir = os.path.join(find_git_root(), tito_config_dir())
        filename = os.path.join(rel_eng_dir, TITO_PROPS)
        if not os.path.exists(filename):
            error_out("Unable to locate branch configuration: %s"
                      "\nPlease run 'tito init'" % filename)

        # Load the global config. Later, when we know what tag/package we're
        # building, we may also load that and potentially override some global
        # settings.
        config = RawConfigParser()
        config.read(filename)

        self._check_legacy_globalconfig(config)
        return config
예제 #9
0
def main():
    """The main function allows converting a git repo the is stup for "normal"
    tito to use classed defined here instead
    """
    options = parse_args()
    rel_eng_dir = os.path.join(find_git_root(), tito_config_dir())
    releasers_filename = os.path.join(rel_eng_dir, RELEASERS_CONF_FILENAME)
    releasers_config = RawConfigParser()
    releasers_config.read(releasers_filename)
    print("Read configuration file: {0}".format(releasers_filename))
    for section in releasers_config.sections():
        print("  found section: {0}".format(section))
        if releasers_config.has_option(section, 'releaser'):
            old_releaser = releasers_config.get(section, 'releaser')
            print("  releaser is set to: {0}".format(old_releaser))
            if old_releaser.startswith('tito.release.'):
                new_releaser = old_releaser.replace('tito.release.',
                                                    'mocktito.', 1)
                print("  replaced with: {0}".format(new_releaser))
                releasers_config.set(section, 'releaser', new_releaser)
            elif old_releaser.startswith('mocktito.'):
                pass
            else:
                stderr.write("Found a releaser type I don't know, aborting\n")
                exit(1)
            if options.extra_yum_repos:
                print("  adding extra yum repos")
                releasers_config.set(section, EXTRA_YUM_REPOS,
                                     "\n".join(options.extra_yum_repos))
            if options.extra_yum_repos_for:
                print("  adding extra yum repos for branches")
                releasers_config.set(section, EXTRA_YUM_REPOS_FOR,
                                     json.dumps(options.extra_yum_repos_for))
    with open(releasers_filename, 'w') as rfp:
        releasers_config.write(rfp)
예제 #10
0
    def setUp(self):
        TitoGitTestFixture.setUp(self)
        os.chdir(self.repo_dir)

        self.config = RawConfigParser()
        self.output_dir = tempfile.mkdtemp("-titotestoutput")
예제 #11
0
class SingleProjectTests(TitoGitTestFixture):

    def setUp(self):
        TitoGitTestFixture.setUp(self)

        self.create_project(PKG_NAME)
        os.chdir(self.repo_dir)

        self.config = RawConfigParser()
        self.config.add_section("buildconfig")
        self.config.set("buildconfig", "builder", "tito.builder.Builder")
        self.config.set("buildconfig", "offline", "true")

        self.releaser_config = RawConfigParser()
        self.releaser_config.add_section('test')
        self.releaser_config.set('test', 'releaser',
            'tito.release.Releaser')

    def test_init_worked(self):
        # Not actually running init here, just making sure it worked when
        # run during setup.
        self.assertTrue(os.path.exists(os.path.join(self.repo_dir, ".tito")))
        self.assertTrue(os.path.exists(os.path.join(self.repo_dir, ".tito",
            "packages")))
        self.assertTrue(os.path.exists(os.path.join(self.repo_dir, ".tito",
            "tito.props")))

    def test_initial_tag(self):
        self.assertTrue(tag_exists_locally("%s-0.0.1-1" % PKG_NAME))

    def test_tag(self):
        tito("tag --accept-auto-changelog --debug")
        check_tag_exists("%s-0.0.2-1" % PKG_NAME, offline=True)

    def test_tag_with_version(self):
        tito("tag --accept-auto-changelog --debug --use-version 9.0.0")
        check_tag_exists("%s-9.0.0-1" % PKG_NAME, offline=True)

    def test_undo_tag(self):
        os.chdir(self.repo_dir)
        original_head = getoutput('git show-ref -s refs/heads/master')

        # Create tito tag, which adds a new commit and moves head.
        tito("tag --accept-auto-changelog --debug")
        tag = "%s-0.0.2-1" % PKG_NAME
        check_tag_exists(tag, offline=True)
        new_head = getoutput('git show-ref -s refs/heads/master')
        self.assertNotEqual(original_head, new_head)

        # Undo tito tag, which rewinds one commit to original head.
        tito("tag -u")
        self.assertFalse(tag_exists_locally(tag))
        new_head = getoutput('git show-ref -s refs/heads/master')
        self.assertEqual(original_head, new_head)

    def test_latest_tgz(self):
        tito("build --tgz -o %s" % self.repo_dir)

    def test_build_tgz_tag(self):
        tito("build --tgz --tag=%s-0.0.1-1 -o %s" % (PKG_NAME,
            self.repo_dir))
        self.assertTrue(os.path.exists(os.path.join(self.repo_dir,
            "%s-0.0.1.tar.gz" % PKG_NAME)))

    def test_build_latest_srpm(self):
        tito("build --srpm")

    def test_build_srpm_tag(self):
        tito("build --srpm --tag=%s-0.0.1-1 -o %s" % (PKG_NAME, self.repo_dir))

    def test_build_latest_rpm(self):
        tito("build --rpm -o %s" % self.repo_dir)

    def test_build_rpm_tag(self):
        tito("build --rpm --tag=%s-0.0.1-1 -o %s" % (PKG_NAME,
            self.repo_dir))

    def test_release(self):
        releaser = Releaser(PKG_NAME, None, '/tmp/tito/',
            self.config, {}, 'test', self.releaser_config, False,
            False, False, **{'offline': True})
        self.assertTrue(isinstance(releaser.builder, Builder))
        releaser.release(dry_run=True)

    def test_release_override_builder(self):
        self.releaser_config.set('test', 'builder',
            'tito.builder.UpstreamBuilder')
        releaser = Releaser(PKG_NAME, None, '/tmp/tito/',
            self.config, {}, 'test', self.releaser_config, False,
            False, False, **{'offline': True})
        self.assertTrue(isinstance(releaser.builder,
            UpstreamBuilder))
        releaser.release(dry_run=True)
예제 #12
0
class SingleProjectTests(TitoGitTestFixture):

    def setUp(self):
        TitoGitTestFixture.setUp(self)

        self.create_project(PKG_NAME)
        os.chdir(self.repo_dir)

        self.config = RawConfigParser()
        self.config.add_section("buildconfig")
        self.config.set("buildconfig", "builder", "tito.builder.Builder")
        self.config.set("buildconfig", "offline", "true")

        self.releaser_config = RawConfigParser()
        self.releaser_config.add_section('test')
        self.releaser_config.set('test', 'releaser',
            'tito.release.Releaser')

    def test_init_worked(self):
        # Not actually running init here, just making sure it worked when
        # run during setup.
        self.assertTrue(os.path.exists(os.path.join(self.repo_dir, ".tito")))
        self.assertTrue(os.path.exists(os.path.join(self.repo_dir, ".tito",
            "packages")))
        self.assertTrue(os.path.exists(os.path.join(self.repo_dir, ".tito",
            "tito.props")))

    def test_initial_tag(self):
        self.assertTrue(tag_exists_locally("%s-0.0.1-1" % PKG_NAME))

    def test_tag(self):
        tito("tag --accept-auto-changelog --debug")
        check_tag_exists("%s-0.0.2-1" % PKG_NAME, offline=True)

    def test_tag_with_version(self):
        tito("tag --accept-auto-changelog --debug --use-version 9.0.0")
        check_tag_exists("%s-9.0.0-1" % PKG_NAME, offline=True)

    def test_tag_with_changelog(self):
        tito("tag --accept-auto-changelog --use-version 9.0.0 --changelog='-Test'")
        check_tag_exists("%s-9.0.0-1" % PKG_NAME, offline=True)

        changelog = getoutput("cat *.spec")
        self.assertTrue('-Test' in changelog)

    def test_tag_with_changelog_format(self):
        tito("tag --accept-auto-changelog --use-version 9.0.0 --changelog=Test")
        check_tag_exists("%s-9.0.0-1" % PKG_NAME, offline=True)

        changelog = getoutput("cat *.spec")
        self.assertTrue('- Test' in changelog)

    def test_tag_with_changelog_multiple(self):
        tito("tag --accept-auto-changelog --use-version 9.0.0 --changelog=Test --changelog=Fake")
        check_tag_exists("%s-9.0.0-1" % PKG_NAME, offline=True)

        changelog = getoutput("cat *.spec")
        self.assertTrue('- Test' in changelog)
        self.assertTrue('- Fake' in changelog)

    def test_undo_tag(self):
        os.chdir(self.repo_dir)
        original_head = getoutput('git show-ref -s refs/heads/master')

        # Create tito tag, which adds a new commit and moves head.
        tito("tag --accept-auto-changelog --debug")
        tag = "%s-0.0.2-1" % PKG_NAME
        check_tag_exists(tag, offline=True)
        new_head = getoutput('git show-ref -s refs/heads/master')
        self.assertNotEqual(original_head, new_head)

        # Undo tito tag, which rewinds one commit to original head.
        tito("tag -u")
        self.assertFalse(tag_exists_locally(tag))
        new_head = getoutput('git show-ref -s refs/heads/master')
        self.assertEqual(original_head, new_head)

    def test_tag_with_custom_message(self):
        os.chdir(self.repo_dir)
        with open(os.path.join(self.repo_dir, '.tito', 'tito.props'), 'a') as f:
            f.write('tag_commit_message_format = No info plz\n')

        tito("tag --accept-auto-changelog")

        last_msg = getoutput('git log -n 1 --pretty=format:%s')
        self.assertEqual('No info plz', last_msg.strip())

    def test_tag_with_custom_message_bad_placeholder(self):
        os.chdir(self.repo_dir)
        with open(os.path.join(self.repo_dir, '.tito', 'tito.props'), 'a') as f:
            f.write('tag_commit_message_format = %(ultimate_answer)s\n')

        with Capture(silent=True) as capture:
            self.assertRaises(SystemExit, tito, "tag --accept-auto-changelog")
        self.assertIn("Unknown placeholder 'ultimate_answer' in tag_commit_message_format",
                      capture.err)

    def test_tag_with_custom_message_containing_quotes(self):
        os.chdir(self.repo_dir)
        with open(os.path.join(self.repo_dir, '.tito', 'tito.props'), 'a') as f:
            f.write('tag_commit_message_format = Hack"%(name)s\\\n')

        tito("tag --accept-auto-changelog")

        last_msg = getoutput('git log -n 1 --pretty=format:%s')
        self.assertEqual('Hack"titotestpkg\\', last_msg.strip())

    def test_latest_tgz(self):
        tito("build --tgz -o %s" % self.repo_dir)

    def test_build_tgz_tag(self):
        tito("build --tgz --tag=%s-0.0.1-1 -o %s" % (PKG_NAME,
            self.repo_dir))
        self.assertTrue(os.path.exists(os.path.join(self.repo_dir,
            "%s-0.0.1.tar.gz" % PKG_NAME)))

    def test_build_latest_srpm(self):
        tito("build --srpm")

    def test_build_srpm_tag(self):
        tito("build --srpm --tag=%s-0.0.1-1 -o %s" % (PKG_NAME, self.repo_dir))

    def test_build_latest_rpm(self):
        tito("build --rpm -o %s" % self.repo_dir)

    def test_build_rpm_tag(self):
        tito("build --rpm --tag=%s-0.0.1-1 -o %s" % (PKG_NAME,
            self.repo_dir))

    def test_release(self):
        releaser = Releaser(PKG_NAME, None, '/tmp/tito/',
            self.config, {}, 'test', self.releaser_config, False,
            False, False, **{'offline': True})
        self.assertTrue(isinstance(releaser.builder, Builder))
        releaser.release(dry_run=True)

    def test_release_override_builder(self):
        self.releaser_config.set('test', 'builder',
            'tito.builder.UpstreamBuilder')
        releaser = Releaser(PKG_NAME, None, '/tmp/tito/',
            self.config, {}, 'test', self.releaser_config, False,
            False, False, **{'offline': True})
        self.assertTrue(isinstance(releaser.builder,
            UpstreamBuilder))
        releaser.release(dry_run=True)
예제 #13
0
 def setUp(self):
     self.config = RawConfigParser()
예제 #14
0
def main():
    """The main function allows converting a git repo the is stup for "normal"
    tito to use classed defined here instead
    """
    options = parse_args()
    rel_eng_dir = os.path.join(find_git_root(), tito_config_dir())
    releasers_filename = os.path.join(rel_eng_dir, RELEASERS_CONF_FILENAME)
    releasers_config = RawConfigParser()
    releasers_config.read(releasers_filename)
    print("Read configuration file: {0}".format(releasers_filename))
    for section in releasers_config.sections():
        print("  found section: {0}".format(section))
        if releasers_config.has_option(section, "releaser"):
            old_releaser = releasers_config.get(section, "releaser")
            print("  releaser is set to: {0}".format(old_releaser))
            if old_releaser.startswith("tito.release."):
                new_releaser = old_releaser.replace("tito.release.", "mocktito.", 1)
                print("  replaced with: {0}".format(new_releaser))
                releasers_config.set(section, "releaser", new_releaser)
            elif old_releaser.startswith("mocktito."):
                pass
            else:
                stderr.write("Found a releaser type I don't know, aborting\n")
                exit(1)
            if options.extra_yum_repos:
                print("  adding extra yum repos")
                releasers_config.set(section, EXTRA_YUM_REPOS, "\n".join(options.extra_yum_repos))
            if options.extra_yum_repos_for:
                print("  adding extra yum repos for branches")
                releasers_config.set(section, EXTRA_YUM_REPOS_FOR, json.dumps(options.extra_yum_repos_for))
    with open(releasers_filename, "w") as rfp:
        releasers_config.write(rfp)
예제 #15
0
class SingleProjectTests(TitoGitTestFixture):

    def setUp(self):
        TitoGitTestFixture.setUp(self)

        self.create_project(PKG_NAME)
        os.chdir(self.repo_dir)

        self.config = RawConfigParser()
        self.config.add_section("buildconfig")
        self.config.set("buildconfig", "builder", "tito.builder.Builder")
        self.config.set("buildconfig", "offline", "true")

        self.releaser_config = RawConfigParser()
        self.releaser_config.add_section('test')
        self.releaser_config.set('test', 'releaser',
            'tito.release.Releaser')

    def test_init_worked(self):
        # Not actually running init here, just making sure it worked when
        # run during setup.
        self.assertTrue(os.path.exists(os.path.join(self.repo_dir, ".tito")))
        self.assertTrue(os.path.exists(os.path.join(self.repo_dir, ".tito",
            "packages")))
        self.assertTrue(os.path.exists(os.path.join(self.repo_dir, ".tito",
            "tito.props")))

    def test_initial_tag(self):
        self.assertTrue(tag_exists_locally("%s-0.0.1-1" % PKG_NAME))

    def test_tag(self):
        tito("tag --accept-auto-changelog --debug")
        check_tag_exists("%s-0.0.2-1" % PKG_NAME, offline=True)

    def test_tag_with_version(self):
        tito("tag --accept-auto-changelog --debug --use-version 9.0.0")
        check_tag_exists("%s-9.0.0-1" % PKG_NAME, offline=True)

    def test_tag_with_changelog(self):
        tito("tag --accept-auto-changelog --use-version 9.0.0 --changelog='-Test'")
        check_tag_exists("%s-9.0.0-1" % PKG_NAME, offline=True)

        changelog = getoutput("cat *.spec")
        self.assertTrue('-Test' in changelog)

    def test_tag_with_changelog_format(self):
        tito("tag --accept-auto-changelog --use-version 9.0.0 --changelog=Test")
        check_tag_exists("%s-9.0.0-1" % PKG_NAME, offline=True)

        changelog = getoutput("cat *.spec")
        self.assertTrue('- Test' in changelog)

    def test_tag_with_changelog_multiple(self):
        tito("tag --accept-auto-changelog --use-version 9.0.0 --changelog=Test --changelog=Fake")
        check_tag_exists("%s-9.0.0-1" % PKG_NAME, offline=True)

        changelog = getoutput("cat *.spec")
        self.assertTrue('- Test' in changelog)
        self.assertTrue('- Fake' in changelog)

    def test_undo_tag(self):
        os.chdir(self.repo_dir)
        original_head = getoutput('git show-ref -s refs/heads/master')

        # Create tito tag, which adds a new commit and moves head.
        tito("tag --accept-auto-changelog --debug")
        tag = "%s-0.0.2-1" % PKG_NAME
        check_tag_exists(tag, offline=True)
        new_head = getoutput('git show-ref -s refs/heads/master')
        self.assertNotEqual(original_head, new_head)

        # Undo tito tag, which rewinds one commit to original head.
        tito("tag -u")
        self.assertFalse(tag_exists_locally(tag))
        new_head = getoutput('git show-ref -s refs/heads/master')
        self.assertEqual(original_head, new_head)

    def test_latest_tgz(self):
        tito("build --tgz -o %s" % self.repo_dir)

    def test_build_tgz_tag(self):
        tito("build --tgz --tag=%s-0.0.1-1 -o %s" % (PKG_NAME,
            self.repo_dir))
        self.assertTrue(os.path.exists(os.path.join(self.repo_dir,
            "%s-0.0.1.tar.gz" % PKG_NAME)))

    def test_build_latest_srpm(self):
        tito("build --srpm")

    def test_build_srpm_tag(self):
        tito("build --srpm --tag=%s-0.0.1-1 -o %s" % (PKG_NAME, self.repo_dir))

    def test_build_latest_rpm(self):
        tito("build --rpm -o %s" % self.repo_dir)

    def test_build_rpm_tag(self):
        tito("build --rpm --tag=%s-0.0.1-1 -o %s" % (PKG_NAME,
            self.repo_dir))

    def test_release(self):
        releaser = Releaser(PKG_NAME, None, '/tmp/tito/',
            self.config, {}, 'test', self.releaser_config, False,
            False, False, **{'offline': True})
        self.assertTrue(isinstance(releaser.builder, Builder))
        releaser.release(dry_run=True)

    def test_release_override_builder(self):
        self.releaser_config.set('test', 'builder',
            'tito.builder.UpstreamBuilder')
        releaser = Releaser(PKG_NAME, None, '/tmp/tito/',
            self.config, {}, 'test', self.releaser_config, False,
            False, False, **{'offline': True})
        self.assertTrue(isinstance(releaser.builder,
            UpstreamBuilder))
        releaser.release(dry_run=True)