diff --git a/plugins/image_commands/__init__.py b/plugins/image_commands/__init__.py index 5353b48..8a9f189 100644 --- a/plugins/image_commands/__init__.py +++ b/plugins/image_commands/__init__.py @@ -1,11 +1,11 @@ +def validate_manifest(data, schema_validate): + from os import path + schema_path = path.normpath(path.join(path.dirname(__file__), 'manifest-schema.json')) + schema_validate(data, schema_path) + + def tasks(tasklist, manifest): - from image_commands import ImageExecuteCommand - tasklist.add(ImageExecuteCommand()) - -def validate_manifest(data, schema_validate): - from os import path - schema_path = path.normpath(path.join(path.dirname(__file__), 'manifest-schema.json')) - schema_validate(data, schema_path) - + from image_commands import ImageExecuteCommand + tasklist.add(ImageExecuteCommand) diff --git a/plugins/image_commands/image_commands.py b/plugins/image_commands/image_commands.py index f79f835..71781aa 100644 --- a/plugins/image_commands/image_commands.py +++ b/plugins/image_commands/image_commands.py @@ -3,20 +3,17 @@ from common import phases class ImageExecuteCommand(Task): - description = 'Execute command in the image' - phase = phases.system_modification - - def run(self, info): - from common.tools import log_check_call - - for user_cmd in info.manifest.plugins['image_commands']['commands']: - command = [] - for elt in user_cmd: - fragment = elt.format( - root=info.root, - image=info.loopback_file, - filesystem=info.manifest.volume['filesystem']) - command.append(fragment) - log_check_call(command) + description = 'Execute command in the image' + phase = phases.system_modification + def run(self, info): + from common.tools import log_check_call + for user_cmd in info.manifest.plugins['image_commands']['commands']: + command = [] + for elt in user_cmd: + fragment = elt.format(root=info.root, + image=info.loopback_file, + filesystem=info.manifest.volume['filesystem']) + command.append(fragment) + log_check_call(command) diff --git a/plugins/image_commands/manifest-schema.json b/plugins/image_commands/manifest-schema.json index f57b2e8..9785c90 100644 --- a/plugins/image_commands/manifest-schema.json +++ b/plugins/image_commands/manifest-schema.json @@ -13,10 +13,10 @@ "type": "array", "items": { "type": "array", - "items": { - "type": "string" - } - } + "items": {"type": "string"}, + "minItems": 1 + }, + "minItems": 1 } }, "required": ["commands"] diff --git a/plugins/user_packages/__init__.py b/plugins/user_packages/__init__.py index 218975c..3596486 100644 --- a/plugins/user_packages/__init__.py +++ b/plugins/user_packages/__init__.py @@ -1,6 +1,14 @@ +def validate_manifest(data, schema_validate): + from os import path + schema_path = path.normpath(path.join(path.dirname(__file__), 'manifest-schema.json')) + schema_validate(data, schema_path) + + def tasks(tasklist, manifest): from user_packages import AddUserPackages, AddLocalUserPackages - tasklist.add(AddUserPackages, - AddLocalUserPackages) + if 'repo' in manifest.plugins['user_packages']: + tasklist.add(AddUserPackages) + if 'local' in manifest.plugins['user_packages']: + tasklist.add(AddLocalUserPackages) diff --git a/plugins/user_packages/manifest-schema.json b/plugins/user_packages/manifest-schema.json new file mode 100644 index 0000000..865701c --- /dev/null +++ b/plugins/user_packages/manifest-schema.json @@ -0,0 +1,33 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "title": "Image commands plugin manifest", + "type": "object", + "properties": { + "plugins": { + "type": "object", + "properties": { + "user_packages": { + "type": "object", + "properties": { + "repo": { + "type": "array", + "items": {"type": "string"}, + "minItems": 1 + }, + "local": { + "type": "array", + "items": {"type": "string"}, + "minItems": 1 + } + }, + "anyOf": [ + {"required": ["repo"]}, + {"required": ["local"]} + ] + } + }, + "required": ["user_packages"] + } + }, + "required": ["plugins"] +} diff --git a/plugins/user_packages/user_packages.py b/plugins/user_packages/user_packages.py index 7739358..6ab39a8 100644 --- a/plugins/user_packages/user_packages.py +++ b/plugins/user_packages/user_packages.py @@ -13,8 +13,6 @@ class AddUserPackages(Task): successors = [CheckPackages] def run(self, info): - if 'repo' not in info.manifest.plugins['user_packages']: - return for pkg in info.manifest.plugins['user_packages']['repo']: info.img_packages[0].add(pkg) @@ -25,9 +23,6 @@ class AddLocalUserPackages(Task): predecessors = [MountRoot] def run(self, info): - if 'local' not in info.manifest.plugins['user_packages']: - return - import stat rwxr_xr_x = (stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP | stat.S_IXGRP |