2013-07-10 10:49:45 +02:00
|
|
|
from base import Task
|
|
|
|
from common import phases
|
|
|
|
from common.exceptions import TaskError
|
|
|
|
|
|
|
|
|
2014-02-23 21:51:28 +01:00
|
|
|
class AddExternalCommands(Task):
|
|
|
|
description = 'Determining which external commands are required'
|
2013-12-29 16:09:47 +01:00
|
|
|
phase = phases.preparation
|
|
|
|
|
2014-01-05 15:57:11 +01:00
|
|
|
@classmethod
|
|
|
|
def run(cls, info):
|
2014-02-23 21:51:28 +01:00
|
|
|
info.host_dependencies['debootstrap'] = 'debootstrap'
|
2013-12-29 16:09:47 +01:00
|
|
|
|
|
|
|
from common.fs.loopbackvolume import LoopbackVolume
|
|
|
|
if isinstance(info.volume, LoopbackVolume):
|
2014-02-23 21:51:28 +01:00
|
|
|
info.host_dependencies['qemu-img'] = 'qemu-utils'
|
|
|
|
info.host_dependencies['losetup'] = 'mount'
|
|
|
|
from common.fs.qemuvolume import QEMUVolume
|
|
|
|
if isinstance(info.volume, QEMUVolume):
|
|
|
|
info.host_dependencies['losetup'] = 'qemu-nbd'
|
2013-12-29 16:09:47 +01:00
|
|
|
|
|
|
|
if 'xfs' in (p.filesystem for p in info.volume.partition_map.partitions):
|
2014-02-23 21:51:28 +01:00
|
|
|
info.host_dependencies['mkfs.xfs'] = 'xfsprogs'
|
2013-12-29 16:09:47 +01:00
|
|
|
|
|
|
|
from base.fs.partitionmaps.none import NoPartitions
|
|
|
|
if not isinstance(info.volume.partition_map, NoPartitions):
|
2014-02-23 21:51:28 +01:00
|
|
|
info.host_dependencies['parted'] = 'parted'
|
|
|
|
info.host_dependencies['kpartx'] = 'kpartx'
|
2013-12-29 16:09:47 +01:00
|
|
|
|
|
|
|
|
2014-02-23 21:51:28 +01:00
|
|
|
class CheckExternalCommands(Task):
|
|
|
|
description = 'Checking availability of external commands'
|
2013-07-10 10:49:45 +02:00
|
|
|
phase = phases.preparation
|
2014-02-23 21:51:28 +01:00
|
|
|
predecessors = [AddExternalCommands]
|
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 = []
|
2014-02-23 21:51:28 +01:00
|
|
|
for command, package in info.host_dependencies.items():
|
2013-07-10 10:49:45 +02:00
|
|
|
try:
|
2014-02-23 21:51:28 +01:00
|
|
|
log_check_call(['type ' + command], shell=True)
|
2013-07-10 10:49:45 +02:00
|
|
|
except CalledProcessError:
|
2014-02-23 21:51:28 +01:00
|
|
|
msg = ('The command `{command}\' is not available, '
|
|
|
|
'it is located in the package `{package}\'.'
|
|
|
|
.format(command=command, package=package))
|
|
|
|
missing_packages.append(msg)
|
2014-01-09 17:23:25 +01:00
|
|
|
if len(missing_packages) > 0:
|
2014-02-23 21:51:28 +01:00
|
|
|
msg = '\n'.join(missing_packages)
|
2014-01-09 17:23:25 +01:00
|
|
|
raise TaskError(msg)
|