[game-data-packager] 10/25: packaging: allow looking up a PackagingSystem by (FORMAT, DISTRO) pair

Simon McVittie smcv at debian.org
Sun Oct 9 21:26:06 UTC 2016


This is an automated email from the git hooks/post-receive script.

smcv pushed a commit to branch master
in repository game-data-packager.

commit 91a0f41abbb26ca93f7b09401b28e7f02ba5b1ae
Author: Simon McVittie <smcv at debian.org>
Date:   Sun Oct 9 14:06:40 2016 +0100

    packaging: allow looking up a PackagingSystem by (FORMAT, DISTRO) pair
---
 game_data_packager/packaging/__init__.py | 10 ++++---
 game_data_packager/packaging/arch.py     |  2 +-
 game_data_packager/packaging/deb.py      |  2 +-
 game_data_packager/packaging/rpm.py      | 46 +++++++++++++++++++++-----------
 4 files changed, 39 insertions(+), 21 deletions(-)

diff --git a/game_data_packager/packaging/__init__.py b/game_data_packager/packaging/__init__.py
index 61eb7e0..d25557e 100644
--- a/game_data_packager/packaging/__init__.py
+++ b/game_data_packager/packaging/__init__.py
@@ -204,9 +204,11 @@ class PackagingSystem(metaclass=ABCMeta):
                 return k
         return package
 
+def get_packaging_system(format, distro=None):
+    mod = 'game_data_packager.packaging.{}'.format(format)
+    return importlib.import_module(mod).get_packaging_system(distro)
+
 def get_native_packaging_system():
     # lazy import when actually needed
-    from ..version import (FORMAT)
-
-    mod = 'game_data_packager.packaging.{}'.format(FORMAT)
-    return importlib.import_module(mod).get_distro_packaging()
+    from ..version import (FORMAT, DISTRO)
+    return get_packaging_system(FORMAT, DISTRO)
diff --git a/game_data_packager/packaging/arch.py b/game_data_packager/packaging/arch.py
index 476cbda..702a19b 100644
--- a/game_data_packager/packaging/arch.py
+++ b/game_data_packager/packaging/arch.py
@@ -109,5 +109,5 @@ class ArchPackaging(PackagingSystem):
 
         return self.rename_package(pr.package)
 
-def get_distro_packaging():
+def get_packaging_system(distro=None):
     return ArchPackaging()
diff --git a/game_data_packager/packaging/deb.py b/game_data_packager/packaging/deb.py
index ef3f7f6..184746e 100644
--- a/game_data_packager/packaging/deb.py
+++ b/game_data_packager/packaging/deb.py
@@ -207,5 +207,5 @@ class DebPackaging(PackagingSystem):
 
         return self.rename_package(pr.package)
 
-def get_distro_packaging():
+def get_packaging_system(distro=None):
     return DebPackaging()
diff --git a/game_data_packager/packaging/rpm.py b/game_data_packager/packaging/rpm.py
index 04ed96d..3c52645 100644
--- a/game_data_packager/packaging/rpm.py
+++ b/game_data_packager/packaging/rpm.py
@@ -34,9 +34,12 @@ class RpmPackaging(PackagingSystem):
                   'amd64': 'x86_64',
                   }
 
-    def __init__(self, distro):
+    def __init__(self, distro=None):
         super(RpmPackaging, self).__init__()
-        self._contexts = (distro, 'rpm', 'generic')
+        if distro is None or distro == 'generic':
+            self._contexts = ('rpm', 'generic')
+        else:
+            self._contexts = (distro, 'rpm', 'generic')
 
     def is_installed(self, package):
         try:
@@ -117,8 +120,8 @@ class DnfPackaging(RpmPackaging):
                   'unrar-nonfree': 'unrar',
                   }
 
-    def __init__(self):
-        super(DnfPackaging, self).__init__('fedora')
+    def __init__(self, distro='fedora'):
+        super(DnfPackaging, self).__init__(distro)
         self.available = None
 
     def read_architecture(self):
@@ -171,8 +174,8 @@ class ZypperPackaging(RpmPackaging):
                   'unrar-nonfree': 'unrar',
                   }
 
-    def __init__(self):
-        super(ZypperPackaging, self).__init__('suse')
+    def __init__(self, distro='suse'):
+        super(ZypperPackaging, self).__init__(distro)
 
     def is_available(self, package):
         try:
@@ -214,8 +217,8 @@ class UrpmiPackaging(RpmPackaging):
                   'unrar-nonfree': 'unrar',
                   }
 
-    def __init__(self):
-        super(UrpmiPackaging, self).__init__('mageia')
+    def __init__(self, distro='mageia'):
+        super(UrpmiPackaging, self).__init__(distro)
 
     def is_available(self, package):
         try:
@@ -234,21 +237,34 @@ class UrpmiPackaging(RpmPackaging):
         except subprocess.CalledProcessError:
             return None
 
-def get_distro_packaging():
+def get_packaging_system(distro=None):
+    if distro is None:
+        distro = _get_distro()
+
+    if distro == 'mageia':
+        return UrpmiPackaging(distro)
+    elif distro == 'fedora':
+        return DnfPackaging(distro)
+    elif distro == 'suse':
+        return ZypperPackaging(distro)
+
+    return RpmPackaging(distro)
+
+def _get_distro():
     if os.path.isfile('/etc/mageia-release'):
-        return UrpmiPackaging()
+        return 'mageia'
 
     if os.path.isfile('/etc/redhat-release'):
-        return DnfPackaging()
+        return 'fedora'
 
     if os.path.isfile('/etc/SuSE-release'):
-        return ZypperPackaging()
+        return 'suse'
 
     try:
         maybe = DnfPackaging()
 
         if maybe.is_available('rpm'):
-            return maybe
+            return 'fedora'
     except:
         pass
 
@@ -256,8 +272,8 @@ def get_distro_packaging():
         maybe = ZypperPackaging()
 
         if maybe.is_available('rpm'):
-            return maybe
+            return 'suse'
     except:
         pass
 
-    return RpmPackaging()
+    return 'generic'

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/game-data-packager.git



More information about the Pkg-games-commits mailing list