forked from kimchi-project/kimchi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
distroloader.py
66 lines (55 loc) · 2.24 KB
/
distroloader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#
# Project Kimchi
#
# Copyright IBM Corp, 2015-2016
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
import glob
import json
import os
from wok.exception import NotFoundError, OperationFailed
from wok.utils import wok_log
from wok.plugins.kimchi import config
ARCHS = {'x86_64': ['x86_64', 'amd64', 'i686', 'x86', 'i386'],
'amd64': ['x86_64', 'amd64', 'i686', 'x86', 'i386'],
'ppc64': ['ppc', 'ppc64'],
'ppc64le': ['ppc64', 'ppc64le']}
class DistroLoader(object):
def __init__(self, location=None):
self.location = location or config.get_distros_store()
def _get_json_info(self, fname):
msg_args = {'filename': fname}
if not os.path.isfile(fname):
msg = "DistroLoader: failed to find distro file: %s" % fname
wok_log.error(msg)
raise NotFoundError("KCHDL0001E", msg_args)
try:
with open(fname) as f:
data = json.load(f)
return data
except ValueError:
msg = "DistroLoader: failed to parse distro file: %s" % fname
wok_log.error(msg)
raise OperationFailed("KCHDL0002E", msg_args)
def get(self):
arch_list = ARCHS.get(os.uname()[4])
all_json_files = glob.glob("%s/%s" % (self.location, "*.json"))
distros = []
for f in all_json_files:
distros.extend(self._get_json_info(f))
# Return all remote ISOs arch not found
return dict([(distro['name'], distro) for distro in distros if
(arch_list is None or distro['os_arch'] in arch_list)])