mirror of
https://github.com/kevingruesser/bootstrap-vz.git
synced 2025-08-22 09:50:37 +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):
|
||||
import os.path
|
||||
|
||||
schema_path = os.path.normpath(os.path.join(os.path.dirname(__file__), 'manifest-schema.yml'))
|
||||
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):
|
||||
taskset.add(tasks.ValidateSourcePaths)
|
||||
|
||||
if ('mkdirs' in manifest.plugins['file_copy']):
|
||||
taskset.add(tasks.MkdirCommand)
|
||||
if ('files' in manifest.plugins['file_copy']):
|
||||
|
|
|
@ -5,20 +5,6 @@ import os
|
|||
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):
|
||||
from bootstrapvz.common.tools import log_check_call
|
||||
if 'permissions' in entry:
|
||||
|
|
Loading…
Add table
Reference in a new issue