From: Aline Manera <alinefm(a)br.ibm.com>
Instead of using platform.linux_distribution() and keep a list of possible
values to match, this patch verifies the tools in the system to identify
which repository management tool to use in Kimchi.
So try to import yum module or apt_pkg module and in last case raise an error.
Signed-off-by: Aline Manera <alinefm(a)br.ibm.com>
---
src/kimchi/repositories.py | 27 +++++++++++----------------
1 file changed, 11 insertions(+), 16 deletions(-)
diff --git a/src/kimchi/repositories.py b/src/kimchi/repositories.py
index 2e70008..2727c84 100644
--- a/src/kimchi/repositories.py
+++ b/src/kimchi/repositories.py
@@ -18,15 +18,11 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import os
-import platform
from kimchi.basemodel import Singleton
from kimchi.exception import InvalidOperation, InvalidParameter
from kimchi.exception import OperationFailed, NotFoundError, MissingParameter
-YUM_DISTROS = ['fedora', 'opensuse ', 'suse linux enterprise server
']
-APT_DISTROS = ['debian', 'ubuntu']
-
class Repositories(object):
__metaclass__ = Singleton
@@ -43,20 +39,19 @@ class Repositories(object):
# 'enabled': True/False, 'gpgcheck': True/False,
# 'gpgkey': ([<string>], None),
# 'is_mirror': True/False}
-
- self._repo_storage = {}
-
- self._distro = platform.linux_distribution()[0].lower()
- if (self._distro in YUM_DISTROS or self._distro.startswith('red hat')):
+ try:
+ __import__('yum')
self._pkg_mnger = YumRepo()
- elif (self._distro in APT_DISTROS):
- self._pkg_mnger = AptRepo()
- else:
- raise InvalidOperation("KCHREPOS0014E")
+ except ImportError:
+ try:
+ __import__('apt_pkg')
+ self._pkg_mnger = AptRepo()
+ except ImportError:
+ raise InvalidOperation('KCHREPOS0019E')
- if self._pkg_mnger:
- # update the self._repo_storage with system's repositories
- self._scanSystemRepositories()
+ self._repo_storage = {}
+ # update the self._repo_storage with system's repositories
+ self._scanSystemRepositories()
def _scanSystemRepositories(self):
"""
--
1.7.10.4