mirror of
https://github.com/kevingruesser/bootstrap-vz.git
synced 2025-08-24 15:36:27 +00:00
file_copy: Validate early
This validates the source file presence when the manifest is validated, rather than failing later.
This commit is contained in:
parent
de888c1b3c
commit
e5f32ba441
2 changed files with 7 additions and 16 deletions
|
@ -3,13 +3,18 @@ import tasks
|
||||||
|
|
||||||
def validate_manifest(data, validator, error):
|
def validate_manifest(data, validator, error):
|
||||||
import os.path
|
import os.path
|
||||||
|
|
||||||
schema_path = os.path.normpath(os.path.join(os.path.dirname(__file__), 'manifest-schema.yml'))
|
schema_path = os.path.normpath(os.path.join(os.path.dirname(__file__), 'manifest-schema.yml'))
|
||||||
validator(data, schema_path)
|
validator(data, schema_path)
|
||||||
|
|
||||||
|
for i, file_entry in enumerate(data['plugins']['file_copy']['files']):
|
||||||
|
srcfile = file_entry['src']
|
||||||
|
if not os.path.isfile(srcfile):
|
||||||
|
msg = 'The source file %s does not exist.' % srcfile
|
||||||
|
error(msg, ['plugins', 'file_copy', 'files', i])
|
||||||
|
|
||||||
|
|
||||||
def resolve_tasks(taskset, manifest):
|
def resolve_tasks(taskset, manifest):
|
||||||
taskset.add(tasks.ValidateSourcePaths)
|
|
||||||
|
|
||||||
if ('mkdirs' in manifest.plugins['file_copy']):
|
if ('mkdirs' in manifest.plugins['file_copy']):
|
||||||
taskset.add(tasks.MkdirCommand)
|
taskset.add(tasks.MkdirCommand)
|
||||||
if ('files' in manifest.plugins['file_copy']):
|
if ('files' in manifest.plugins['file_copy']):
|
||||||
|
|
|
@ -5,20 +5,6 @@ import os
|
||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
|
|
||||||
class ValidateSourcePaths(Task):
|
|
||||||
description = 'Check whether the files to be copied exist'
|
|
||||||
phase = phases.preparation
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def run(cls, info):
|
|
||||||
from bootstrapvz.common.exceptions import TaskError
|
|
||||||
for file_entry in info.manifest.plugins['file_copy']['files']:
|
|
||||||
srcfile = file_entry['src']
|
|
||||||
if not os.path.isfile(srcfile):
|
|
||||||
msg = 'The source file %s does not exist.' % srcfile
|
|
||||||
raise TaskError(msg)
|
|
||||||
|
|
||||||
|
|
||||||
def modify_path(info, path, entry):
|
def modify_path(info, path, entry):
|
||||||
from bootstrapvz.common.tools import log_check_call
|
from bootstrapvz.common.tools import log_check_call
|
||||||
if 'permissions' in entry:
|
if 'permissions' in entry:
|
||||||
|
|
Loading…
Add table
Reference in a new issue