[game-data-packager] 08/25: Packaging: if tool is not installed, assume no packages are either

Simon McVittie smcv at debian.org
Sun Oct 9 21:26:05 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 f521d63f3ecf8f417becd3ae86cea289357a0d5f
Author: Simon McVittie <smcv at debian.org>
Date:   Sun Oct 9 14:02:17 2016 +0100

    Packaging: if tool is not installed, assume no packages are either
---
 game_data_packager/packaging/arch.py | 22 ++++++++----
 game_data_packager/packaging/deb.py  | 31 ++++++++++++-----
 game_data_packager/packaging/rpm.py  | 66 ++++++++++++++++++++++++------------
 3 files changed, 82 insertions(+), 37 deletions(-)

diff --git a/game_data_packager/packaging/arch.py b/game_data_packager/packaging/arch.py
index 14df682..476cbda 100644
--- a/game_data_packager/packaging/arch.py
+++ b/game_data_packager/packaging/arch.py
@@ -51,22 +51,30 @@ class ArchPackaging(PackagingSystem):
             self._foreign_architectures = set(['i386'])
 
     def is_installed(self, package):
-        return subprocess.call(['pacman', '-Q', package],
-                                stdout=subprocess.DEVNULL,
-                                stderr=subprocess.DEVNULL) == 0
+        try:
+            return subprocess.call(['pacman', '-Q', package],
+                                    stdout=subprocess.DEVNULL,
+                                    stderr=subprocess.DEVNULL) == 0
+        except FileNotFoundError:
+            return False
 
     def current_version(self, package):
         try:
             return check_output(['pacman', '-Q', package],
                                 stderr=subprocess.DEVNULL,
                                 universal_newlines=True).split()[1]
+        except FileNotFoundError:
+            return None
         except subprocess.CalledProcessError:
             return None
 
     def is_available(self, package):
-        return subprocess.call(['pacman', '-Si', package],
-                                stdout=subprocess.DEVNULL,
-                                stderr=subprocess.DEVNULL) == 0
+        try:
+            return subprocess.call(['pacman', '-Si', package],
+                                    stdout=subprocess.DEVNULL,
+                                    stderr=subprocess.DEVNULL) == 0
+        except FileNotFoundError:
+            return False
 
     def available_version(self, package):
         try:
@@ -78,6 +86,8 @@ class ArchPackaging(PackagingSystem):
                 if k == 'Version':
                     return v
 
+        except FileNotFoundError:
+            return None
         except subprocess.CalledProcessError:
             return None
 
diff --git a/game_data_packager/packaging/deb.py b/game_data_packager/packaging/deb.py
index ec6b29e..ef3f7f6 100644
--- a/game_data_packager/packaging/deb.py
+++ b/game_data_packager/packaging/deb.py
@@ -88,11 +88,15 @@ class DebPackaging(PackagingSystem):
             return True
 
         if self.__installed is None:
+            try:
+                proc = subprocess.Popen(['dpkg-query', '--show',
+                            '--showformat', '${Package}\\n'],
+                        universal_newlines=True,
+                        stdout=subprocess.PIPE)
+            except FileNotFoundError:
+                return False
+
             cache = set()
-            proc = subprocess.Popen(['dpkg-query', '--show',
-                        '--showformat', '${Package}\\n'],
-                    universal_newlines=True,
-                    stdout=subprocess.PIPE)
             for line in proc.stdout:
                 cache.add(line.rstrip())
             self.__installed = cache
@@ -101,10 +105,14 @@ class DebPackaging(PackagingSystem):
 
     def is_available(self, package):
         if self.__available is None:
+            try:
+                proc = subprocess.Popen(['apt-cache', 'pkgnames'],
+                        universal_newlines=True,
+                        stdout=subprocess.PIPE)
+            except FileNotFoundError:
+                return False
+
             cache = set()
-            proc = subprocess.Popen(['apt-cache', 'pkgnames'],
-                    universal_newlines=True,
-                    stdout=subprocess.PIPE)
             for line in proc.stdout:
                 cache.add(line.rstrip())
             self.__available = cache
@@ -118,12 +126,17 @@ class DebPackaging(PackagingSystem):
         try:
             return check_output(['dpkg-query', '--show',
               '--showformat', '${Version}', package], universal_newlines=True)
+        except FileNotFoundError:
+            return None
         except subprocess.CalledProcessError:
             return None
 
     def available_version(self, package):
-        current_ver = check_output(['apt-cache', 'madison', package],
-                                    universal_newlines=True)
+        try:
+            current_ver = check_output(['apt-cache', 'madison', package],
+                                        universal_newlines=True)
+        except FileNotFoundError:
+            return None
         current_ver = current_ver.splitlines()[0]
         current_ver = current_ver.split('|')[1].strip()
         return current_ver
diff --git a/game_data_packager/packaging/rpm.py b/game_data_packager/packaging/rpm.py
index 7e8aafb..04ed96d 100644
--- a/game_data_packager/packaging/rpm.py
+++ b/game_data_packager/packaging/rpm.py
@@ -39,14 +39,19 @@ class RpmPackaging(PackagingSystem):
         self._contexts = (distro, 'rpm', 'generic')
 
     def is_installed(self, package):
-        return 0 == subprocess.call(['rpm', '-q', package],
-                                    stdout=subprocess.DEVNULL,
-                                    stderr=subprocess.DEVNULL)
+        try:
+            return 0 == subprocess.call(['rpm', '-q', package],
+                                        stdout=subprocess.DEVNULL,
+                                        stderr=subprocess.DEVNULL)
+        except FileNotFoundError:
+            return False
 
     def current_version(self, package):
         try:
             return check_output(['rpm', '-q',
               '--qf', '%{VERSION}', package], universal_newlines=True)
+        except FileNotFoundError:
+            return None
         except subprocess.CalledProcessError:
             return None
 
@@ -123,11 +128,14 @@ class DnfPackaging(RpmPackaging):
 
     def is_available(self, package):
         if self.available is None:
+            try:
+                proc = subprocess.Popen(['dnf', 'list'],
+                        universal_newlines=True,
+                        stderr=subprocess.DEVNULL,
+                        stdout=subprocess.PIPE)
+            except FileNotFoundError:
+                return False
             cache = set()
-            proc = subprocess.Popen(['dnf', 'list'],
-                    universal_newlines=True,
-                    stderr=subprocess.DEVNULL,
-                    stdout=subprocess.PIPE)
             for line in proc.stdout:
                 if '.' in line:
                     cache.add(line.split('.')[0])
@@ -136,10 +144,13 @@ class DnfPackaging(RpmPackaging):
         return package in self.available
 
     def available_version(self, package):
-        proc = subprocess.Popen(['dnf', 'list', package],
-                                 universal_newlines=True,
-                                 stderr=subprocess.DEVNULL,
-                                 stdout=subprocess.PIPE)
+        try:
+            proc = subprocess.Popen(['dnf', 'list', package],
+                                     universal_newlines=True,
+                                     stderr=subprocess.DEVNULL,
+                                     stdout=subprocess.PIPE)
+        except FileNotFoundError:
+            return None
         # keep only last line
         for line in proc.stdout:
             pass
@@ -164,20 +175,26 @@ class ZypperPackaging(RpmPackaging):
         super(ZypperPackaging, self).__init__('suse')
 
     def is_available(self, package):
-        proc = subprocess.Popen(['zypper', 'info', package],
-                universal_newlines=True,
-                stdout=subprocess.PIPE,
-                env={'LANG':'C'})
+        try:
+            proc = subprocess.Popen(['zypper', 'info', package],
+                    universal_newlines=True,
+                    stdout=subprocess.PIPE,
+                    env={'LANG':'C'})
+        except FileNotFoundError:
+            return False
         for line in proc.stdout:
             if line.startswith('Version:'):
                 return True
         return False
 
     def available_version(self, package):
-        proc = subprocess.Popen(['zypper', 'info', package],
-                universal_newlines=True,
-                stdout=subprocess.PIPE,
-                env={'LANG':'C'})
+        try:
+            proc = subprocess.Popen(['zypper', 'info', package],
+                    universal_newlines=True,
+                    stdout=subprocess.PIPE,
+                    env={'LANG':'C'})
+        except FileNotFoundError:
+            return None
         for line in proc.stdout:
             if line.startswith('Version:'):
                 return line.split(':', maxsplit=1)[1]
@@ -201,14 +218,19 @@ class UrpmiPackaging(RpmPackaging):
         super(UrpmiPackaging, self).__init__('mageia')
 
     def is_available(self, package):
-        return 0 == subprocess.call(['urpmq', package],
-                                    stdout=subprocess.DEVNULL,
-                                    stderr=subprocess.DEVNULL)
+        try:
+            return 0 == subprocess.call(['urpmq', package],
+                                        stdout=subprocess.DEVNULL,
+                                        stderr=subprocess.DEVNULL)
+        except FileNotFoundError:
+            return False
 
     def available_version(self, package):
         try:
             line = check_output(['urpmq', '-r', package]).decode('ascii')
             return line.split('-')[-2]
+        except FileNotFoundError:
+            return None
         except subprocess.CalledProcessError:
             return None
 

-- 
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