예제 #1
0
 def test_subsitute_not_fully_expanded(self):
     source =self.make_branch_and_tree("source")
     source.commit("one")
     source.commit("two")
     branch1 = BaseRecipeBranch("source", "{revno:packaging}", 0.2)
     resolve_revisions(branch1, substitute_branch_vars=substitute_branch_vars)
     self.assertRaises(errors.BzrCommandError, check_expanded_deb_version, branch1)
예제 #2
0
 def test_substitute_git(self):
     source = self.make_branch_and_tree("source")
     source.commit("one", 
         rev_id="git-v1:a029d7b2cc83c26a53d8b2a24fa12c340fcfac58")
     branch1 = BaseRecipeBranch("source", "foo-{git-commit}", 0.4)
     resolve_revisions(branch1,
         substitute_branch_vars=substitute_branch_vars)
     self.assertEqual("foo-a029d7b", branch1.deb_version)
예제 #3
0
 def test_substitute_revtime(self):
     br = self.make_branch("source")
     source = br.create_checkout("checkout")
     source.commit("one")
     source.commit("two", timestamp=1307708628, timezone=0)
     branch1 = BaseRecipeBranch("source", "foo-{revtime}", 0.4)
     resolve_revisions(branch1,
             substitute_branch_vars=substitute_branch_vars)
     self.assertEqual("foo-201106101223", branch1.deb_version)
예제 #4
0
 def test_latest_tag(self):
     source = self.make_branch_and_tree("source")
     revid = source.commit("one")
     source.branch.tags.set_tag("millbank", revid)
     source.commit("two")
     branch1 = BaseRecipeBranch("source", "foo-{latest-tag}", 0.4)
     resolve_revisions(branch1,
         substitute_branch_vars=substitute_branch_vars)
     self.assertEqual("foo-millbank", branch1.deb_version)
예제 #5
0
 def test_substitute_svn(self):
     br = self.make_branch("source")
     source = br.create_checkout("checkout")
     source.commit("one")
     source.commit("two",
         rev_id="svn-v4:be7e6eca-30d4-0310-a8e5-ac0d63af7070:trunk:5344")
     branch1 = BaseRecipeBranch("source", "foo-{svn-revno}", 0.4)
     resolve_revisions(branch1, substitute_branch_vars=substitute_branch_vars)
     self.assertEqual("foo-5344", branch1.deb_version)
예제 #6
0
 def test_substitute_supports_debupstream(self):
     # resolve_revisions should leave debupstream parameters alone and not
     # complain.
     source =self.make_branch_and_tree("source")
     source.commit("one")
     source.commit("two")
     branch1 = BaseRecipeBranch("source", "{debupstream}-{revno}", 0.2)
     resolve_revisions(branch1,
         substitute_branch_vars=substitute_branch_vars)
     self.assertEqual("{debupstream}-2", branch1.deb_version)
예제 #7
0
 def run(self,
         location,
         working_directory,
         manifest=None,
         if_changed_from=None,
         revision=None):
     if revision is not None and len(revision) > 0:
         if len(revision) != 1:
             raise errors.BzrCommandError("only a single revision can be "
                                          "specified")
         revspec = revision[0]
     else:
         revspec = None
     possible_transports = []
     base_branch = get_prepared_branch_from_location(
         location, possible_transports=possible_transports, revspec=revspec)
     if if_changed_from is not None:
         old_recipe = get_old_recipe(if_changed_from, possible_transports)
     else:
         old_recipe = None
     changed = resolve_revisions(base_branch, if_changed_from=old_recipe)
     if not changed:
         trace.note("Unchanged")
         return 0
     manifest_path = manifest or os.path.join(working_directory,
                                              "bzr-builder.manifest")
     build_tree(base_branch, working_directory)
     write_manifest_to_transport(manifest_path, base_branch,
                                 possible_transports)
예제 #8
0
 def test_unchanged_command(self):
     source =self.make_branch_and_tree("source")
     source.commit("one")
     branch1 = BaseRecipeBranch("source", "{revno}", 0.2)
     branch2 = BaseRecipeBranch("source", "{revno}", 0.2)
     branch1.run_command("touch test1")
     branch2.run_command("touch test1")
     self.assertEqual(False, resolve_revisions(branch1,
         if_changed_from=branch2,
         substitute_branch_vars=substitute_branch_vars))
     self.assertEqual("source", branch1.url)
예제 #9
0
 def test_unchanged_not_explicit(self):
     source =self.make_branch_and_tree("source")
     revid = source.commit("one")
     branch1 = BaseRecipeBranch("source", "{revno}", 0.2)
     branch2 = BaseRecipeBranch("source", "{revno}", 0.2,
             revspec="revid:%s" % revid)
     self.assertEqual(False, resolve_revisions(branch1,
         if_changed_from=branch2,
         substitute_branch_vars=substitute_branch_vars))
     self.assertEqual("source", branch1.url)
     self.assertEqual(revid, branch1.revid)
     self.assertEqual(None, branch1.revspec)
     self.assertEqual("1", branch1.deb_version)
예제 #10
0
 def test_substitute(self):
     source =self.make_branch_and_tree("source")
     revid1 = source.commit("one")
     source.commit("two")
     branch1 = BaseRecipeBranch("source",
             "{revno}-{revno:packaging}", 0.2, revspec="1")
     branch2 = RecipeBranch("packaging", "source")
     branch1.nest_branch("debian", branch2)
     self.assertEqual(True, resolve_revisions(branch1,
        substitute_branch_vars=substitute_branch_vars))
     self.assertEqual("source", branch1.url)
     self.assertEqual(revid1, branch1.revid)
     self.assertEqual("1", branch1.revspec)
     self.assertEqual("1-2", branch1.deb_version)
예제 #11
0
 def test_changed_shape(self):
     source =self.make_branch_and_tree("source")
     revid = source.commit("one")
     branch1 = BaseRecipeBranch("source", "{revno}", 0.2, revspec="1")
     branch2 = BaseRecipeBranch("source", "{revno}", 0.2,
             revspec="revid:%s" % revid)
     branch3 = RecipeBranch("nested", "source")
     branch1.nest_branch("foo", branch3)
     self.assertEqual(True, resolve_revisions(branch1,
         if_changed_from=branch2,
         substitute_branch_vars=substitute_branch_vars))
     self.assertEqual("source", branch1.url)
     self.assertEqual(revid, branch1.revid)
     self.assertEqual("1", branch1.revspec)
     self.assertEqual("1", branch1.deb_version)
예제 #12
0
 def test_unchanged_multilevel(self):
     source =self.make_branch_and_tree("source")
     revid = source.commit("one")
     branch1 = BaseRecipeBranch("source", "{revno}", 0.2)
     branch2 = RecipeBranch("nested1", "source")
     branch3 = RecipeBranch("nested2", "source")
     branch2.nest_branch("bar", branch3)
     branch1.nest_branch("foo", branch2)
     branch4 = BaseRecipeBranch("source", "{revno}", 0.2,
             revspec="revid:%s" % revid)
     branch5 = RecipeBranch("nested1", "source",
             revspec="revid:%s" % revid)
     branch6 = RecipeBranch("nested2", "source",
             revspec="revid:%s" % revid)
     branch5.nest_branch("bar", branch6)
     branch4.nest_branch("foo", branch5)
     self.assertEqual(False, resolve_revisions(branch1,
             if_changed_from=branch4,
             substitute_branch_vars=substitute_branch_vars))
     self.assertEqual("source", branch1.url)
     self.assertEqual(revid, branch1.revid)
     self.assertEqual(None, branch1.revspec)
     self.assertEqual("1", branch1.deb_version)
예제 #13
0
    def run(self,
            location,
            working_basedir=None,
            manifest=None,
            if_changed_from=None,
            package=None,
            distribution=None,
            dput=None,
            key_id=None,
            no_build=None,
            watch_ppa=False,
            append_version=None,
            safe=False,
            allow_fallback_to_native=False):
        try:
            try:
                import debian
            except ImportError:
                # In older versions of python-debian the main package was named
                # debian_bundle
                import debian_bundle
        except ImportError:
            raise errors.BzrCommandError(
                "The 'debian' python module "
                "is required for 'bzr dailydeb'. Install the "
                "python-debian package.")

        from breezy.plugins.builder.deb_util import (
            add_autobuild_changelog_entry,
            build_source_package,
            calculate_package_dir,
            changelog,
            debian_source_package_name,
            dput_source_package,
            extract_upstream_tarball,
            force_native_format,
            get_source_format,
            sign_source_package,
            target_from_dput,
        )
        from breezy.plugins.builder.deb_version import (
            check_expanded_deb_version,
            substitute_branch_vars,
            substitute_time,
        )

        if dput is not None and key_id is None:
            raise errors.BzrCommandError("You must specify --key-id if you "
                                         "specify --dput.")
        if watch_ppa:
            if not dput:
                raise errors.BzrCommandError(
                    "cannot watch a ppa without doing dput.")
            else:
                # Check we can calculate a PPA url.
                target_from_dput(dput)

        possible_transports = []
        base_branch = get_prepared_branch_from_location(
            location, safe=safe, possible_transports=possible_transports)
        # Save the unsubstituted version
        template_version = base_branch.deb_version
        if if_changed_from is not None:
            old_recipe = get_old_recipe(if_changed_from, possible_transports)
        else:
            old_recipe = None
        if base_branch.deb_version is not None:
            time = datetime.datetime.utcnow()
            substitute_time(base_branch, time)
            changed = resolve_revisions(
                base_branch,
                if_changed_from=old_recipe,
                substitute_branch_vars=substitute_branch_vars)
            check_expanded_deb_version(base_branch)
        else:
            changed = resolve_revisions(base_branch,
                                        if_changed_from=old_recipe)
        if not changed:
            trace.note("Unchanged")
            return 0
        if working_basedir is None:
            temp_dir = tempfile.mkdtemp(prefix="bzr-builder-")
            working_basedir = temp_dir
        else:
            temp_dir = None
            if not os.path.exists(working_basedir):
                os.makedirs(working_basedir)
        package_name = self._calculate_package_name(location, package)
        if template_version is None:
            working_directory = os.path.join(working_basedir,
                                             "%s-direct" % (package_name, ))
        else:
            working_directory = os.path.join(
                working_basedir, "%s-%s" % (package_name, template_version))
        try:
            # we want to use a consistent package_dir always to support
            # updates in place, but debuild etc want PACKAGE-UPSTREAMVERSION
            # on disk, so we build_tree with the unsubstituted version number
            # and do a final rename-to step before calling into debian build
            # tools. We then rename the working dir back.
            manifest_path = os.path.join(working_directory, "debian",
                                         "bzr-builder.manifest")
            build_tree(base_branch, working_directory)
            control_path = os.path.join(working_directory, "debian", "control")
            if not os.path.exists(control_path):
                if package is None:
                    raise errors.BzrCommandError(
                        "No control file to "
                        "take the package name from, and --package not "
                        "specified.")
            else:
                package = debian_source_package_name(control_path)
            write_manifest_to_transport(manifest_path, base_branch,
                                        possible_transports)
            autobuild = (base_branch.deb_version is not None)
            if autobuild:
                # Add changelog also substitutes {debupstream}.
                add_autobuild_changelog_entry(base_branch,
                                              working_directory,
                                              package,
                                              distribution=distribution,
                                              append_version=append_version)
            else:
                if append_version:
                    raise errors.BzrCommandError(
                        "--append-version only "
                        "supported for autobuild recipes (with a 'deb-version' "
                        "header)")
            with open(os.path.join(working_directory, "debian",
                                   "changelog")) as cl_f:
                contents = cl_f.read()
            cl = changelog.Changelog(file=contents)
            package_name = cl.package
            package_version = cl.version
            package_dir = calculate_package_dir(package_name, package_version,
                                                working_basedir)
            # working_directory -> package_dir: after this debian stuff works.
            os.rename(working_directory, package_dir)
            try:
                current_format = get_source_format(package_dir)
                if (package_version.debian_version is not None
                        or current_format == "3.0 (quilt)"):
                    # Non-native package
                    try:
                        extract_upstream_tarball(
                            base_branch.branch, package_name,
                            package_version.upstream_version, working_basedir)
                    except errors.NoSuchTag, e:
                        if not allow_fallback_to_native:
                            raise errors.BzrCommandError(
                                "Unable to find the upstream source. Import it "
                                "as tag %s or build with "
                                "--allow-fallback-to-native." % e.tag_name)
                        else:
                            force_native_format(package_dir, current_format)
                if not no_build:
                    build_source_package(
                        package_dir, tgz_check=not allow_fallback_to_native)
                    if key_id is not None:
                        sign_source_package(package_dir, key_id)
                    if dput is not None:
                        dput_source_package(package_dir, dput)
            finally:
                if not no_build:
                    # package_dir -> working_directory
                    # FIXME: may fail in error unwind, masking the
                    # original exception.
                    os.rename(package_dir, working_directory)
            # Note that this may write a second manifest.
            if manifest is not None:
                write_manifest_to_transport(manifest, base_branch,
                                            possible_transports)