Zerofree can be installed as a Debian package

Show alternate message when package string for host_dependencies starts with http:// or https://
This commit is contained in:
Anders Ingemann 2014-02-23 22:54:25 +01:00
parent 210d3261c0
commit cdd372ca3b
5 changed files with 23 additions and 61 deletions

View file

@ -11,14 +11,20 @@ class CheckExternalCommands(Task):
def run(cls, info): def run(cls, info):
from common.tools import log_check_call from common.tools import log_check_call
from subprocess import CalledProcessError from subprocess import CalledProcessError
import re
missing_packages = [] missing_packages = []
for command, package in info.host_dependencies.items(): for command, package in info.host_dependencies.items():
try: try:
log_check_call(['type ' + command], shell=True) log_check_call(['type ' + command], shell=True)
except CalledProcessError: except CalledProcessError:
msg = ('The command `{command}\' is not available, ' if re.match('^https?:\/\/', package):
'it is located in the package `{package}\'.' msg = ('The command `{command}\' is not available, '
.format(command=command, package=package)) '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) missing_packages.append(msg)
if len(missing_packages) > 0: if len(missing_packages) > 0:
msg = '\n'.join(missing_packages) msg = '\n'.join(missing_packages)

View file

@ -5,9 +5,6 @@ def validate_manifest(data, validator, error):
import os.path import os.path
schema_path = os.path.join(os.path.dirname(__file__), 'manifest-schema.json') schema_path = os.path.join(os.path.dirname(__file__), 'manifest-schema.json')
validator(data, schema_path) 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': if data['plugins']['minimize_size'].get('shrink', False) and data['volume']['backing'] != 'vmdk':
error('Can only shrink vmdk images', ['plugins', 'minimize_size', 'shrink']) error('Can only shrink vmdk images', ['plugins', 'minimize_size', 'shrink'])
@ -16,11 +13,11 @@ def resolve_tasks(taskset, manifest):
taskset.update([tasks.AddFolderMounts, taskset.update([tasks.AddFolderMounts,
tasks.RemoveFolderMounts, tasks.RemoveFolderMounts,
]) ])
if 'zerofree' in manifest.plugins['minimize_size']: if manifest.plugins['minimize_size'].get('zerofree', False):
taskset.add(tasks.CheckZerofreePath) taskset.add(tasks.AddRequiredCommands)
taskset.add(tasks.Zerofree) taskset.add(tasks.Zerofree)
if manifest.plugins['minimize_size'].get('shrink', False): if manifest.plugins['minimize_size'].get('shrink', False):
taskset.add(tasks.CheckVMWareDMCommand) taskset.add(tasks.AddRequiredCommands)
taskset.add(tasks.ShrinkVolume) taskset.add(tasks.ShrinkVolume)

View file

@ -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"] }
}
}
}
}
}
}

View file

@ -10,16 +10,10 @@
"type": "object", "type": "object",
"properties": { "properties": {
"shrink": { "type": "boolean" }, "shrink": { "type": "boolean" },
"zerofree": { "$ref": "#/definitions/absolute_path" } "zerofree": { "type": "boolean" }
} }
} }
} }
} }
},
"definitions": {
"absolute_path": {
"type": "string",
"pattern": "^/[^\\0]+$"
}
} }
} }

View file

@ -3,6 +3,7 @@ from common import phases
from common.tasks import apt from common.tasks import apt
from common.tasks import bootstrap from common.tasks import bootstrap
from common.tasks import filesystem from common.tasks import filesystem
from common.tasks import host
from common.tasks import partitioning from common.tasks import partitioning
from common.tasks import volume from common.tasks import volume
import os import os
@ -46,22 +47,20 @@ class RemoveFolderMounts(Task):
del info.minimize_size_folder del info.minimize_size_folder
class CheckZerofreePath(Task): class AddRequiredCommands(Task):
description = 'Checking path to zerofree tool' description = 'Adding commands required for reducing volume size'
phase = phases.preparation phase = phases.preparation
successors = [host.CheckExternalCommands]
@classmethod @classmethod
def run(cls, info): def run(cls, info):
from common.exceptions import TaskError if info.manifest.plugins['minimize_size'].get('zerofree', False):
import os info.host_dependencies['zerofree'] = 'zerofree'
zerofree = info.manifest.plugins['minimize_size']['zerofree'] if info.manifest.plugins['minimize_size'].get('shrink', False):
if not os.path.isfile(zerofree): link = 'https://my.vmware.com/web/vmware/info/slug/desktop_end_user_computing/vmware_workstation/10_0'
raise TaskError('The path `{path}\' does not exist or is not a file'.format(path=zerofree)) info.host_dependencies['vmware-vdiskmanager'] = link
if not os.access(zerofree, os.X_OK):
raise TaskError('The path `{path}\' is not executable'.format(path=zerofree))
# Get zerofree here: http://intgat.tigress.co.uk/rmy/uml/index.html
class Zerofree(Task): class Zerofree(Task):
description = 'Zeroing unused blocks on the volume' description = 'Zeroing unused blocks on the volume'
phase = phases.volume_unmounting phase = phases.volume_unmounting
@ -71,23 +70,7 @@ class Zerofree(Task):
@classmethod @classmethod
def run(cls, info): def run(cls, info):
from common.tools import log_check_call from common.tools import log_check_call
zerofree = info.manifest.plugins['minimize_size']['zerofree'] log_check_call(['zerofree', info.volume.device_path])
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))
class ShrinkVolume(Task): class ShrinkVolume(Task):