bootstrap-vz/bootstrapvz/common/tasks/host.py

36 lines
1.4 KiB
Python
Raw Normal View History

from bootstrapvz.base import Task
from .. import phases
from ..exceptions import TaskError
2013-07-10 10:49:45 +02:00
class CheckExternalCommands(Task):
description = 'Checking availability of external commands'
phase = phases.validation
2013-07-10 10:49:45 +02:00
@classmethod
def run(cls, info):
import re
import os
import logging
# https://github.com/PyCQA/pylint/issues/73
# pylint: disable=no-name-in-module,import-error,useless-suppression
from distutils.spawn import find_executable
missing_packages = []
log = logging.getLogger(__name__)
for command, package in info.host_dependencies.items():
log.debug('Checking availability of ' + command)
path = find_executable(command)
if path is None or not os.access(path, os.X_OK):
if re.match(r'^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))
missing_packages.append(msg)
2018-02-18 20:41:40 -08:00
if missing_packages:
msg = '\n'.join(missing_packages)
raise TaskError(msg)