Change UpstreamSource to have PkgPolicy
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Mon, 9 Jul 2012 12:17:24 +0000 (15:17 +0300)
committerGuido Günther <agx@sigxcpu.org>
Thu, 24 Jul 2014 18:06:40 +0000 (20:06 +0200)
The UpstreamSource class now gets a PkgPolicy in it's initialization.
Also, introduces new DebiaUpstreamSource class which is taken in use in
the scripts.

The PkgPolicy is not yet used for anything in UpstreamSource.

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
gbp/deb/dscfile.py
gbp/deb/upstreamsource.py [new file with mode: 0644]
gbp/pkg/__init__.py
gbp/scripts/buildpackage.py
gbp/scripts/common/import_orig.py
gbp/scripts/import_dsc.py
gbp/scripts/import_orig.py

index e2492dcc6692c9895e517225f7a58dcc868579a0..0671328812c50b1da16b2599b2842b8d2b35f7ca 100644 (file)
@@ -20,12 +20,12 @@ import os
 import re
 
 from gbp.errors import GbpError
-from gbp.pkg import UpstreamSource
+from gbp.deb.upstreamsource import DebianUpstreamSource
 from gbp.deb.policy import DebianPkgPolicy
 
 class DscFile(object):
     """Keeps all needed data read from a dscfile"""
-    compressions = r"(%s)" % '|'.join(UpstreamSource.known_compressions())
+    compressions = r"(%s)" % '|'.join(DebianUpstreamSource.known_compressions())
     pkg_re = re.compile(r'Source:\s+(?P<pkg>.+)\s*')
     version_re = re.compile(r'Version:\s((?P<epoch>\d+)\:)?'
                              '(?P<version>[%s]+)\s*$'
diff --git a/gbp/deb/upstreamsource.py b/gbp/deb/upstreamsource.py
new file mode 100644 (file)
index 0000000..7eb555a
--- /dev/null
@@ -0,0 +1,28 @@
+# vim: set fileencoding=utf-8 :
+#
+# (C) 2013 Intel Corporation <markus.lehtonen@linux.intel.com>
+#    This program is free software; you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License as published by
+#    the Free Software Foundation; either version 2 of the License, or
+#    (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with this program; if not, write to the Free Software
+#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+"""Debian-specific upstream sources"""
+
+from gbp.pkg import UpstreamSource
+from gbp.deb.policy import DebianPkgPolicy
+
+
+class DebianUpstreamSource(UpstreamSource):
+    """Upstream source class for Debian"""
+    def __init__(self, name, unpacked=None):
+        super(DebianUpstreamSource, self).__init__(name,
+                                                   unpacked,
+                                                   DebianPkgPolicy)
index 1fd17418d9b1b8306f956a2580e3895d69576905..2e24648a2144de85796197ea96dcf56d9ab4a148 100644 (file)
@@ -179,8 +179,9 @@ class UpstreamSource(object):
     @cvar _unpacked: path to the unpacked source tree
     @type _unpacked: string
     """
-    def __init__(self, name, unpacked=None):
+    def __init__(self, name, unpacked=None, pkg_policy=PkgPolicy):
         self._orig = False
+        self._pkg_policy = pkg_policy
         self._path = name
         self.unpacked = unpacked
 
@@ -317,7 +318,7 @@ class UpstreamSource(object):
         except gbpc.CommandExecFailed:
             # repackArchive already printed an error
             raise GbpError
-        return UpstreamSource(newarchive)
+        return type(self)(newarchive)
 
     @staticmethod
     def known_compressions():
index 8d79e8be0106c2c7654922142368c177037dd300..457673c9ce28b87b849f00f4a476032f221facd1 100755 (executable)
@@ -30,6 +30,7 @@ from gbp.config import (GbpOptionParserDebian, GbpOptionGroup)
 from gbp.deb.git import (GitRepositoryError, DebianGitRepository)
 from gbp.deb.source import DebianSource, DebianSourceError
 from gbp.git.vfs import GitVfs
+from gbp.deb.upstreamsource import DebianUpstreamSource
 from gbp.errors import GbpError
 import gbp.log
 import gbp.notifications
@@ -37,8 +38,7 @@ from gbp.scripts.common.buildpackage import (index_name, wc_name,
                                              git_archive_submodules,
                                              git_archive_single, dump_tree,
                                              write_wc, drop_index)
-from gbp.pkg import (UpstreamSource, compressor_opts, compressor_aliases,
-                     parse_archive_filename)
+from gbp.pkg import compressor_opts, compressor_aliases, parse_archive_filename
 
 def git_archive(repo, cp, output_dir, treeish, comp_type, comp_level, with_submodules):
     "create a compressed orig tarball in output_dir using git_archive"
@@ -172,7 +172,7 @@ def extract_orig(orig_tarball, dest_dir):
     gbp.log.info("Extracting %s to '%s'" % (os.path.basename(orig_tarball), dest_dir))
 
     move_old_export(dest_dir)
-    upstream = UpstreamSource(orig_tarball)
+    upstream = DebianUpstreamSource(orig_tarball)
     upstream.unpack(dest_dir)
 
     # Check if tarball extracts into a single folder or not:
index c2c53a6443d3c1e94382ecf6a1383d73e8d7dd27..8e18e978f0a104076836bdd6fa2897a6789e2a40 100644 (file)
@@ -32,29 +32,26 @@ except ImportError:
     pass
 
 
-class OrigUpstreamSource(UpstreamSource):
-    """Upstream source that will be imported"""
-
-    def needs_repack(self, options):
-        """
-        Determine if the upstream sources needs to be repacked
-
-        We repack if
-         1. we want to filter out files and use pristine tar since we want
-            to make a filtered tarball available to pristine-tar
-         2. when we don't have a suitable upstream tarball (e.g. zip archive or unpacked dir)
-            and want to use filters
-         3. when we don't have a suitable upstream tarball (e.g. zip archive or unpacked dir)
-            and want to use pristine-tar
-        """
-        if ((options.pristine_tar and options.filter_pristine_tar and len(options.filters) > 0)):
+def orig_needs_repack(upstream_source, options):
+    """
+    Determine if the upstream sources needs to be repacked
+
+    We repack if
+     1. we want to filter out files and use pristine tar since we want
+        to make a filtered tarball available to pristine-tar
+     2. when we don't have a suitable upstream tarball (e.g. zip archive or unpacked dir)
+        and want to use filters
+     3. when we don't have a suitable upstream tarball (e.g. zip archive or unpacked dir)
+        and want to use pristine-tar
+    """
+    if ((options.pristine_tar and options.filter_pristine_tar and len(options.filters) > 0)):
+        return True
+    elif not upstream_source.is_orig():
+        if len(options.filters):
             return True
-        elif not self.is_orig():
-            if len(options.filters):
-                return True
-            elif options.pristine_tar:
-                return True
-        return False
+        elif options.pristine_tar:
+            return True
+    return False
 
 
 def cleanup_tmp_tree(tree):
index 600b394d5388ef50814108f6966d3aaa1e484c87..ce97fcb09cb4f484d5f11543a0b253fa3c049754 100644 (file)
@@ -26,8 +26,8 @@ import glob
 import pipes
 import time
 import gbp.command_wrappers as gbpc
-from gbp.pkg import UpstreamSource
 from gbp.deb.dscfile import DscFile
+from gbp.deb.upstreamsource import DebianUpstreamSource
 from gbp.deb.git import (DebianGitRepository, GitRepositoryError)
 from gbp.deb.changelog import ChangeLog
 from gbp.git import rfc822_date_to_git
@@ -328,7 +328,7 @@ def main(argv):
                 set_bare_repo_options(options)
 
             dirs['tmp'] = os.path.abspath(tempfile.mkdtemp(dir='..'))
-            upstream = UpstreamSource(src.tgz)
+            upstream = DebianUpstreamSource(src.tgz)
             upstream.unpack(dirs['tmp'], options.filters)
 
             format = [(options.upstream_tag, "Upstream"), (options.debian_tag, "Debian")][src.native]
index 542896ef55fb86a71e75f2115ee133dbf260d2bf..f81d2493701aad61dd4261bd57b784bb5fcc8ed0 100644 (file)
@@ -23,13 +23,14 @@ import sys
 import tempfile
 import gbp.command_wrappers as gbpc
 from gbp.deb import (DebianPkgPolicy, parse_changelog_repo)
+from gbp.deb.upstreamsource import DebianUpstreamSource
 from gbp.deb.uscan import (Uscan, UscanError)
 from gbp.deb.changelog import ChangeLog, NoChangeLogError
 from gbp.deb.git import (GitRepositoryError, DebianGitRepository)
 from gbp.config import GbpOptionParserDebian, GbpOptionGroup, no_upstream_branch_msg
 from gbp.errors import GbpError
 import gbp.log
-from gbp.scripts.common.import_orig import (OrigUpstreamSource, cleanup_tmp_tree,
+from gbp.scripts.common.import_orig import (orig_needs_repack, cleanup_tmp_tree,
                                             ask_package_name, ask_package_version,
                                             repack_source, is_link_target)
 
@@ -167,7 +168,7 @@ def find_source(use_uscan, args):
     elif len(args) == 0:
         raise GbpError("No archive to import specified. Try --help.")
     else:
-        archive = OrigUpstreamSource(args[0])
+        archive = DebianUpstreamSource(args[0])
         return archive
 
 
@@ -300,7 +301,7 @@ def main(argv):
             source.unpack(tmpdir, options.filters)
             gbp.log.debug("Unpacked '%s' to '%s'" % (source.path, source.unpacked))
 
-        if source.needs_repack(options):
+        if orig_needs_repack(source, options):
             gbp.log.debug("Filter pristine-tar: repacking '%s' from '%s'" % (source.path, source.unpacked))
             (source, tmpdir)  = repack_source(source, sourcepackage, version, tmpdir, options.filters)