From cdd372ca3b9d276cd7c00a3a093724a3e1349108 Mon Sep 17 00:00:00 2001 From: Anders Ingemann Date: Sun, 23 Feb 2014 22:54:25 +0100 Subject: [PATCH] Zerofree can be installed as a Debian package Show alternate message when package string for host_dependencies starts with http:// or https:// --- common/tasks/host.py | 12 ++++-- plugins/minimize_size/__init__.py | 9 ++--- .../manifest-schema-zerofree.json | 18 --------- plugins/minimize_size/manifest-schema.json | 8 +--- plugins/minimize_size/tasks.py | 37 +++++-------------- 5 files changed, 23 insertions(+), 61 deletions(-) delete mode 100644 plugins/minimize_size/manifest-schema-zerofree.json diff --git a/common/tasks/host.py b/common/tasks/host.py index 0522a49..5544b04 100644 --- a/common/tasks/host.py +++ b/common/tasks/host.py @@ -11,14 +11,20 @@ class CheckExternalCommands(Task): def run(cls, info): from common.tools import log_check_call from subprocess import CalledProcessError + import re missing_packages = [] for command, package in info.host_dependencies.items(): try: log_check_call(['type ' + command], shell=True) except CalledProcessError: - msg = ('The command `{command}\' is not available, ' - 'it is located in the package `{package}\'.' - .format(command=command, package=package)) + 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)) missing_packages.append(msg) if len(missing_packages) > 0: msg = '\n'.join(missing_packages) diff --git a/plugins/minimize_size/__init__.py b/plugins/minimize_size/__init__.py index d49b551..f5ab69c 100644 --- a/plugins/minimize_size/__init__.py +++ b/plugins/minimize_size/__init__.py @@ -5,9 +5,6 @@ def validate_manifest(data, validator, error): import os.path schema_path = os.path.join(os.path.dirname(__file__), 'manifest-schema.json') validator(data, schema_path) - if 'zerofree' in data['plugins']['minimize_size']: - zerofree_schema_path = os.path.join(os.path.dirname(__file__), 'manifest-schema-zerofree.json') - validator(data, zerofree_schema_path) if data['plugins']['minimize_size'].get('shrink', False) and data['volume']['backing'] != 'vmdk': error('Can only shrink vmdk images', ['plugins', 'minimize_size', 'shrink']) @@ -16,11 +13,11 @@ def resolve_tasks(taskset, manifest): taskset.update([tasks.AddFolderMounts, tasks.RemoveFolderMounts, ]) - if 'zerofree' in manifest.plugins['minimize_size']: - taskset.add(tasks.CheckZerofreePath) + if manifest.plugins['minimize_size'].get('zerofree', False): + taskset.add(tasks.AddRequiredCommands) taskset.add(tasks.Zerofree) if manifest.plugins['minimize_size'].get('shrink', False): - taskset.add(tasks.CheckVMWareDMCommand) + taskset.add(tasks.AddRequiredCommands) taskset.add(tasks.ShrinkVolume) diff --git a/plugins/minimize_size/manifest-schema-zerofree.json b/plugins/minimize_size/manifest-schema-zerofree.json deleted file mode 100644 index bd6715d..0000000 --- a/plugins/minimize_size/manifest-schema-zerofree.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-04/schema#", - "title": "Minimize size plugin manifest", - "type": "object", - "properties": { - "volume": { - "type": "object", - "properties": { - "partitions": { - "type": "object", - "properties": { - "type": { "enum": ["none"] } - } - } - } - } - } -} diff --git a/plugins/minimize_size/manifest-schema.json b/plugins/minimize_size/manifest-schema.json index 0d7942c..0181fa2 100644 --- a/plugins/minimize_size/manifest-schema.json +++ b/plugins/minimize_size/manifest-schema.json @@ -10,16 +10,10 @@ "type": "object", "properties": { "shrink": { "type": "boolean" }, - "zerofree": { "$ref": "#/definitions/absolute_path" } + "zerofree": { "type": "boolean" } } } } } - }, - "definitions": { - "absolute_path": { - "type": "string", - "pattern": "^/[^\\0]+$" - } } } diff --git a/plugins/minimize_size/tasks.py b/plugins/minimize_size/tasks.py index 37798ae..b04f301 100644 --- a/plugins/minimize_size/tasks.py +++ b/plugins/minimize_size/tasks.py @@ -3,6 +3,7 @@ from common import phases from common.tasks import apt from common.tasks import bootstrap from common.tasks import filesystem +from common.tasks import host from common.tasks import partitioning from common.tasks import volume import os @@ -46,22 +47,20 @@ class RemoveFolderMounts(Task): del info.minimize_size_folder -class CheckZerofreePath(Task): - description = 'Checking path to zerofree tool' +class AddRequiredCommands(Task): + description = 'Adding commands required for reducing volume size' phase = phases.preparation + successors = [host.CheckExternalCommands] @classmethod def run(cls, info): - from common.exceptions import TaskError - import os - zerofree = info.manifest.plugins['minimize_size']['zerofree'] - if not os.path.isfile(zerofree): - raise TaskError('The path `{path}\' does not exist or is not a file'.format(path=zerofree)) - if not os.access(zerofree, os.X_OK): - raise TaskError('The path `{path}\' is not executable'.format(path=zerofree)) + if info.manifest.plugins['minimize_size'].get('zerofree', False): + info.host_dependencies['zerofree'] = 'zerofree' + if info.manifest.plugins['minimize_size'].get('shrink', False): + link = 'https://my.vmware.com/web/vmware/info/slug/desktop_end_user_computing/vmware_workstation/10_0' + info.host_dependencies['vmware-vdiskmanager'] = link -# Get zerofree here: http://intgat.tigress.co.uk/rmy/uml/index.html class Zerofree(Task): description = 'Zeroing unused blocks on the volume' phase = phases.volume_unmounting @@ -71,23 +70,7 @@ class Zerofree(Task): @classmethod def run(cls, info): from common.tools import log_check_call - zerofree = info.manifest.plugins['minimize_size']['zerofree'] - log_check_call([zerofree, info.volume.device_path]) - - -class CheckVMWareDMCommand(Task): - description = 'Checking path to vmware-vdiskmanager tool' - phase = phases.preparation - - @classmethod - def run(cls, info): - from common.exceptions import TaskError - import os - vdiskmngr = '/usr/bin/vmware-vdiskmanager' - if not os.path.isfile(vdiskmngr): - raise TaskError('Unable to find vmware-vdiskmanager at `{path}\''.format(path=vdiskmngr)) - if not os.access(vdiskmngr, os.X_OK): - raise TaskError('vmware-vdiskmanager at `{path}\' is not executable'.format(path=vdiskmngr)) + log_check_call(['zerofree', info.volume.device_path]) class ShrinkVolume(Task):