From 144b820f537601a08fbbc773f4077001f8a16890 Mon Sep 17 00:00:00 2001 From: Corey Bryant Date: Wed, 15 Mar 2017 22:01:41 -0400 Subject: [PATCH] Add support for copyfiles Change-Id: If270801252d95d0a7fa1ece301516ebec216702c --- snap_openstack/base.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/snap_openstack/base.py b/snap_openstack/base.py index 1698c89..8a488c5 100644 --- a/snap_openstack/base.py +++ b/snap_openstack/base.py @@ -16,6 +16,7 @@ import logging import os +import shutil import yaml from snap_openstack.renderer import SnapFileRenderer @@ -105,18 +106,27 @@ class OpenStackSnap(object): target = setup['templates'][template] target_file = target.format(**self.snap_env) ensure_dir(target_file) - LOG.debug('Rendering {} to {}'.format(template, - target_file)) + LOG.debug('Rendering {} to {}'.format(template, target_file)) with open(target_file, 'w') as tf: os.fchmod(tf.fileno(), 0o640) - tf.write(renderer.render(template, - self.snap_env)) + tf.write(renderer.render(template, self.snap_env)) + + for source in setup['copyfiles']: + source_dir = source.format(**self.snap_env) + dest_dir = setup['copyfiles'][source].format(**self.snap_env) + for source_name in os.listdir(source_dir): + s_file = os.path.join(source_dir, source_name) + d_file = os.path.join(dest_dir, source_name) + if not os.path.isfile(s_file) or os.path.exists(d_file): + continue + LOG.debug('Copying file {} to {}'.format(s_file, d_file)) + shutil.copy2(s_file, d_file) def execute(self, argv): '''Execute snap command building out configuration and log options''' entry_point = self.configuration['entry_points'].get(argv[1]) if not entry_point: - _msg = 'Enable to find entry point for {}'.format(argv[1]) + _msg = 'Unable to find entry point for {}'.format(argv[1]) LOG.error(_msg) raise ValueError(_msg)