[Pkg-bazaar-commits] r145 ./bzr-builddeb/people/jdw/merge_upstream: Create the import-dsc command.

James Westby jw+debian at jameswestby.net
Sun Jul 8 13:50:27 UTC 2007


------------------------------------------------------------
revno: 145
committer: James Westby <jw+debian at jameswestby.net>
branch nick: merge_upstream
timestamp: Sun 2007-07-08 14:50:27 +0100
message:
  Create the import-dsc command.
  
  This has a --snapshot option now, instead of import-snapshot command.
  
  It also saves the upstream tarballs so the branch is ready
  to build straight away.
modified:
  __init__.py
  import_dsc.py
-------------- next part --------------
=== modified file '__init__.py'
--- a/__init__.py	2007-07-08 10:19:58 +0000
+++ b/__init__.py	2007-07-08 13:50:27 +0000
@@ -304,7 +304,7 @@
   aliases = ['mu']
 
   package_opt = Option('package', help="The name of the source package.",
-                            type=str)
+                       type=str)
   takes_options = [package_opt]
 
   def run(self, path, version, package=None):
@@ -367,19 +367,57 @@
 register_command(cmd_merge_upstream)
 
 
-class cmd_import_snapshot(Command):
-
-  takes_args = ['package', 'directory?']
-
-  def run(self, package, directory=None):
-    from import_dsc import SnapshotImporter
-    if directory is None:
-      directory = package
-    importer = SnapshotImporter(package)
-    importer.import_dsc(directory)
-
-
-register_command(cmd_import_snapshot)
+class cmd_import_dsc(Command):
+  """Import a series of source packages.
+
+  Provide a number of source packages (.dsc files), and they will
+  be imported to create a branch with history that reflects those
+  packages. You must provide the --to option with the name of the
+  branch that will be created.
+
+  If there are packages that are available on snapshot.debian.net
+  then you can use the --snapshot option to supplement the packages
+  you provide with those available on that service. Pass the name
+  of the source package as on snapshot.debian.net as this option,
+  i.e. to import all versions of apt
+
+    import-dsc --snapshot apt
+
+  If you use the --snapshot option then you don't have to provide
+  any source packages on the command line, and if you omit the
+  --to option then the name of the package as passed to --snapshot
+  will be used as the branch name.
+  """
+
+  takes_args = ['files*']
+  
+  to_opt = Option('to', help="The branch to import to.", type=str)
+  snapshot_opt = Option('snapshot', help="Retrieve source packages from "
+                        "snapshot.debian.net.", type=str)
+
+  takes_options = [to_opt, snapshot_opt]
+
+  def run(self, files_list, to=None, snapshot=None):
+    from import_dsc import DscImporter, SnapshotImporter
+    if files_list is None:
+      files_list = []
+    if snapshot is None:
+      if len(files_list) < 1:
+        raise BzrCommandError("You must give the location of at least one "
+                              "source package to install")
+      if to is None:
+        raise BzrCommandError("You must specify the name of the "
+                              "destination branch using the --to option")
+      importer = DscImporter(files)
+    else:
+      if to is None:
+        to = snapshot
+      importer = SnapshotImporter(snapshot, other_sources=files_list)
+    orig_target = os.path.join(to, '../tarballs')
+    importer.import_dsc(to, orig_target=orig_target)
+
+
+register_command(cmd_import_dsc)
 
 
 def test_suite():

=== modified file 'import_dsc.py'
--- a/import_dsc.py	2007-07-01 18:39:48 +0000
+++ b/import_dsc.py	2007-07-08 13:50:27 +0000
@@ -209,6 +209,18 @@
                   transport=None, base_dir=None):
     f = open_file(origname, transport, base_dir=base_dir)[0]
     try:
+      if self.orig_target is not None:
+        if not os.path.isdir(self.orig_target):
+          os.mkdir(self.orig_target)
+        new_filename = os.path.join(self.orig_target,
+                                    os.path.basename(origname))
+        new_f = open(new_filename, 'wb')
+        try:
+          new_f.write(f.read())
+        finally:
+          new_f.close()
+        f.close()
+        f = open(new_filename)
       dangling_revid = None
       dangling_tree = None
       if last_upstream is not None:
@@ -459,9 +471,10 @@
       self._check_orig_exists(version)
       self._add_to_safe(diff_file, version, 'diff', base_dir, dsc_transport)
 
-  def import_dsc(self, target_dir):
+  def import_dsc(self, target_dir, orig_target=None):
     if os.path.exists(target_dir):
       raise FileExists(target_dir)
+    self.orig_target = orig_target
     self.cache = DscCache(transport=self.transport)
     self.dsc_files.sort(cmp=DscComp(self.cache).cmp)
     self.safe_files = []
@@ -511,7 +524,7 @@
 class SourcesImporter(DscImporter):
   """For importing all the .dsc files from a Sources file."""
 
-  def __init__(self, base, sources_path):
+  def __init__(self, base, sources_path, other_sources=[]):
     """Create a SourcesImporter.
 
     :param base: the base URI from which all paths should be interpreted.
@@ -537,6 +550,7 @@
         name = file_info['name']
         if name.endswith('.dsc'):
           dsc_files.append(urlutils.join(base_dir, name))
+    dsc_files += other_sources
     super(SourcesImporter, self).__init__(dsc_files)
 
   def _check_basedir(self, base_dir):
@@ -546,10 +560,10 @@
 class SnapshotImporter(SourcesImporter):
   """Import all versions of a package recorded on snapshot.debian.net."""
 
-  def __init__(self, package_name):
+  def __init__(self, package_name, other_sources=[]):
     base = 'http://snapshot.debian.net/archive/'
     path = 'pool/%s/%s/source/Sources.gz' % (package_name[0], package_name)
-    super(SnapshotImporter, self).__init__(base, path)
+    super(SnapshotImporter, self).__init__(base, path, other_sources=other_sources)
     warning("snapshot.debian.net has lost packages from before 12/03/2005, "
             "only packages from after that date will be imported.")
 



More information about the Pkg-bazaar-commits mailing list