2013-07-10 10:49:45 +02:00
|
|
|
from base import Task
|
|
|
|
from common import phases
|
|
|
|
from common.exceptions import TaskError
|
|
|
|
|
|
|
|
|
2013-12-29 16:09:47 +01:00
|
|
|
class HostDependencies(Task):
|
|
|
|
description = 'Determining required host dependencies'
|
|
|
|
phase = phases.preparation
|
|
|
|
|
2014-01-05 15:57:11 +01:00
|
|
|
@classmethod
|
|
|
|
def run(cls, info):
|
2013-12-29 16:09:47 +01:00
|
|
|
info.host_dependencies.add('debootstrap')
|
|
|
|
|
|
|
|
from common.fs.loopbackvolume import LoopbackVolume
|
|
|
|
if isinstance(info.volume, LoopbackVolume):
|
|
|
|
info.host_dependencies.add('qemu-utils')
|
|
|
|
|
|
|
|
if 'xfs' in (p.filesystem for p in info.volume.partition_map.partitions):
|
|
|
|
info.host_dependencies.add('xfsprogs')
|
|
|
|
|
|
|
|
from base.fs.partitionmaps.none import NoPartitions
|
|
|
|
if not isinstance(info.volume.partition_map, NoPartitions):
|
|
|
|
info.host_dependencies.update(['parted', 'kpartx'])
|
|
|
|
|
|
|
|
|
|
|
|
class CheckHostDependencies(Task):
|
2013-07-10 10:49:45 +02:00
|
|
|
description = 'Checking installed host packages'
|
|
|
|
phase = phases.preparation
|
2013-12-29 16:09:47 +01:00
|
|
|
predecessors = [HostDependencies]
|
2013-07-10 10:49:45 +02:00
|
|
|
|
2014-01-05 15:57:11 +01:00
|
|
|
@classmethod
|
|
|
|
def run(cls, info):
|
2013-07-10 10:49:45 +02:00
|
|
|
from common.tools import log_check_call
|
|
|
|
from subprocess import CalledProcessError
|
2014-01-09 17:23:25 +01:00
|
|
|
missing_packages = []
|
2013-12-29 16:09:47 +01:00
|
|
|
for package in info.host_dependencies:
|
2013-07-10 10:49:45 +02:00
|
|
|
try:
|
2014-02-07 17:42:45 +00:00
|
|
|
import os.path
|
|
|
|
if os.path.isfile('/usr/bin/dpkg-query'):
|
|
|
|
log_check_call(['/usr/bin/dpkg-query', '-s', package])
|
2013-07-10 10:49:45 +02:00
|
|
|
except CalledProcessError:
|
2014-01-09 17:23:25 +01:00
|
|
|
missing_packages.append(package)
|
|
|
|
if len(missing_packages) > 0:
|
|
|
|
pkgs = '\', `'.join(missing_packages)
|
|
|
|
if len(missing_packages) > 1:
|
|
|
|
msg = "The packages `{packages}\' are not installed".format(packages=pkgs)
|
|
|
|
else:
|
|
|
|
msg = "The package `{packages}\' is not installed".format(packages=pkgs)
|
|
|
|
raise TaskError(msg)
|