[Pkg-bazaar-commits] ./bzr-builddeb/trunk.old r234: Support basic importing of native packages.

James Westby jw+debian at jameswestby.net
Wed Dec 10 08:32:47 UTC 2008


------------------------------------------------------------
revno: 234
committer: James Westby <jw+debian at jameswestby.net>
branch nick: import
timestamp: Wed 2008-06-18 14:36:28 +0100
message:
  Support basic importing of native packages.
  
  There is no handling of pacakges that switch between native
  and non-native yet, and there is nothing stored that denotes
  the native packages.
modified:
  import_dsc.py
  tests/test_import_dsc.py
-------------- next part --------------
=== modified file 'import_dsc.py'
--- a/import_dsc.py	2008-06-11 12:13:49 +0000
+++ b/import_dsc.py	2008-06-18 13:36:28 +0000
@@ -1343,7 +1343,7 @@
         self.tree.branch.fetch(self.upstream_tree.branch,
                 last_revision=pull_revision)
 
-    def pull_version_from_branch(self, pull_branch, version):
+    def pull_version_from_branch(self, pull_branch, version, native=False):
         """Pull a version from a particular branch.
 
         Given a DistributionBranch and a version number this method
@@ -1361,6 +1361,8 @@
 
         :param pull_branch: the DistributionBranch to pull from.
         :param version: the Version to pull.
+        :param native: whether it is a native version that is being
+            imported.
         """
         pull_revision = pull_branch.revid_of_version(version)
         mutter("%s already has version %s so pulling from revision %s"
@@ -1368,11 +1370,13 @@
         self.tree.pull(pull_branch.tree.branch,
                 stop_revision=pull_revision)
         self.tag_version(version)
-        if not self.has_upstream_version(version):
+        if not native and not self.has_upstream_version(version):
             if pull_branch.has_upstream_version(version):
                 self.pull_upstream_from_branch(pull_branch, version)
             else:
                 assert False, "Can't find the needed upstream part"
+        elif native:
+            mutter("Not checking for upstream as it is a native package")
         else:
             mutter("Not importing the upstream part as it is already "
                     "present in the upstream branch")
@@ -1550,6 +1554,18 @@
         """
         return self._get_dsc_part(dsc, ".diff.gz")
 
+    def get_native_part(self, dsc):
+        """Gets the information about the native part from the dsc.
+
+        :param dsc: a deb822.Dsc object to take the information from.
+        :return: a tuple (path, md5), both strings, the former being
+            the path to the .tar.gz, the latter being the md5 reported
+            for it. If there is not native part both will be None.
+        """
+        (path, md5) = self._get_dsc_part(dsc, ".tar.gz")
+        assert not path.endswith(".orig.tar.gz")
+        return (path, md5)
+
     def _init_upstream_from_other(self, versions):
         parents = self.get_parents(versions)
         if len(parents) > 0:
@@ -1609,6 +1625,21 @@
             # Now we have the list of parents we need to import the .diff.gz
             self.import_debian(debian_part, version, parents, md5)
 
+    def get_native_parents(self, version, versions):
+        last_contained_version = self.last_contained_version(versions)
+        if last_contained_version is None:
+            return []
+        else:
+            return [self.revid_of_version(last_contained_version)]
+
+    def _import_native_package(self, version, versions, debian_part, md5):
+        pull_branch = self.branch_to_pull_version_from(version, md5)
+        if pull_branch is not None:
+            self.pull_version_from_branch(pull_branch, version, native=True)
+        else:
+            parents = self.get_native_parents(version, versions)
+            self.import_debian(debian_part, version, parents, md5)
+
     def import_package(self, dsc_filename):
         """Import a source package.
 
@@ -1622,13 +1653,18 @@
         tempdir = self.extract_dsc(dsc_filename)
         try:
             # TODO: make more robust against strange .dsc files.
-            (upstream_part, upstream_md5) = self.get_upstream_part(dsc)
-            (diff_filename, md5) = self.get_diff_part(dsc)
             upstream_part = os.path.join(tempdir,
                     "%s-%s.orig" % (name, str(version.upstream_version)))
             debian_part = os.path.join(tempdir,
                     "%s-%s" % (name, str(version.upstream_version)))
-            assert os.path.exists(upstream_part)
+            native = False
+            if not os.path.exists(upstream_part):
+                mutter("It's a native package")
+                native = True
+                (_, md5) = self.get_native_part(dsc)
+            else:
+                (_, upstream_md5) = self.get_upstream_part(dsc)
+                (_, md5) = self.get_diff_part(dsc)
             cl = self.get_changelog_from_source(debian_part)
             versions = cl.versions
             assert not self.has_version(version), \
@@ -1636,8 +1672,12 @@
             #TODO: check that the versions list is correctly ordered,
             # as some methods assume that, and it's not clear what
             # should happen if it isn't.
-            self._do_import_package(version, versions, debian_part, md5,
-                    upstream_part, upstream_md5)
+            if not native:
+                self._do_import_package(version, versions, debian_part, md5,
+                        upstream_part, upstream_md5)
+            else:
+                self._import_native_package(version, versions, debian_part,
+                        md5)
         finally:
             shutil.rmtree(tempdir)
 

=== modified file 'tests/test_import_dsc.py'
--- a/tests/test_import_dsc.py	2008-06-16 10:54:53 +0000
+++ b/tests/test_import_dsc.py	2008-06-18 13:36:28 +0000
@@ -2155,13 +2155,54 @@
         self.check_changes(up_rev_tree2.changes_from(up_rev_tree1),
                 modified=["README"])
 
+    def test_import_native(self):
+        version = Version("1.0")
+        builder = SourcePackageBuilder("package", version, native=True)
+        builder.add_default_control()
+        builder.build()
+        self.db1.import_package(builder.dsc_name())
+        rh1 = self.tree1.branch.revision_history()
+        up_rh1 = self.up_tree1.branch.revision_history()
+        self.assertEqual(len(rh1), 1)
+        self.assertEqual(len(up_rh1), 0)
+
+    def test_import_native_two(self):
+        version1 = Version("1.0")
+        version2 = Version("1.1")
+        builder = SourcePackageBuilder("package", version1, native=True)
+        builder.add_debian_file("COPYING", "don't do it\n")
+        builder.add_debian_file("README")
+        builder.add_default_control()
+        builder.build()
+        self.db1.import_package(builder.dsc_name())
+        builder.new_version(version2)
+        builder.remove_debian_file("README")
+        builder.add_debian_file("COPYING", "do it\n")
+        builder.add_debian_file("NEWS")
+        builder.build()
+        self.db1.import_package(builder.dsc_name())
+        rh1 = self.tree1.branch.revision_history()
+        up_rh1 = self.up_tree1.branch.revision_history()
+        self.assertEqual(len(rh1), 2)
+        self.assertEqual(len(up_rh1), 0)
+        rev_tree1 = self.tree1.branch.repository.revision_tree(rh1[0])
+        rev_tree2 = self.tree1.branch.repository.revision_tree(rh1[1])
+        self.assertEqual(rev_tree1.get_parent_ids(), [])
+        self.assertEqual(rev_tree2.get_parent_ids(), [rh1[0]])
+        self.check_changes(rev_tree2.changes_from(rev_tree1),
+                added=["NEWS"], removed=["README"],
+                modified=["debian/changelog", "COPYING"])
+        self.assertEqual(self.db1.revid_of_version(version1), rh1[0])
+        self.assertEqual(self.db1.revid_of_version(version2), rh1[1])
+
 
 class SourcePackageBuilder(object):
 
-    def __init__(self, name, version):
+    def __init__(self, name, version, native=False):
         self.upstream_files = {}
         self.debian_files = {}
         self.name = name
+        self.native = native
         cl = Changelog()
         cl.new_block(package=name, version=version,
                 distributions="unstable", urgency="low",
@@ -2201,13 +2242,6 @@
                 date="Wed, 19 Mar 2008 21:27:37 +0000")
         self._cl.add_change("  * foo")
 
-    def orig_name(self):
-        v_num = str(self._cl.version.upstream_version)
-        return "%s_%s.orig.tar.gz" % (self.name, v_num)
-
-    def diff_name(self):
-        return "%s_%s.diff.gz" % (self.name, str(self._cl.version))
-
     def dsc_name(self):
         return "%s_%s.dsc" % (self.name, str(self._cl.version))
 
@@ -2236,12 +2270,16 @@
 
     def build(self):
         basedir = self._make_base()
-        orig_basedir = basedir + ".orig"
-        shutil.copytree(basedir, orig_basedir)
+        if not self.native:
+            orig_basedir = basedir + ".orig"
+            shutil.copytree(basedir, orig_basedir)
+            cmd = "dpkg-source -sa -b %s" % (basedir)
+        else:
+            cmd = "dpkg-source -sn -b %s" % (basedir)
         self._make_files(self.debian_files, basedir)
         self._make_files({"debian/changelog": str(self._cl)}, basedir)
-        proc = subprocess.Popen("dpkg-source -sa -b %s" % (basedir),
-                shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+        proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE,
+                stderr=subprocess.PIPE)
         ret = proc.wait()
         assert ret == 0, "dpkg-source failed, output:\n%s\n%s" % \
                 (proc.stdout.read(), proc.stderr.read())



More information about the Pkg-bazaar-commits mailing list