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 CheckExternalCommands(Task):
|
|
|
|
description = 'Checking availability of external commands'
|
2013-07-10 10:49:45 +02:00
|
|
|
phase = phases.preparation
|
|
|
|
|
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-02-23 22:54:25 +01:00
|
|
|
import re
|
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 22:54:25 +01:00
|
|
|
if re.match('^https?:\/\/', package):
|
|
|
|
msg = ('The command `{command}\' is not available, '
|
|
|
|
'you can download the software at `{package}\'.'
|
|
|
|
.format(command=command, package=package))
|
|
|
|
else:
|
|
|
|
msg = ('The command `{command}\' is not available, '
|
|
|
|
'it is located in the package `{package}\'.'
|
|
|
|
.format(command=command, package=package))
|
2014-02-23 21:51:28 +01:00
|
|
|
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)
|