|
16 | 16 | import tempfile |
17 | 17 | import zipfile |
18 | 18 |
|
19 | | -import collections |
20 | 19 | from collections import OrderedDict |
21 | 20 |
|
22 | 21 | import botocore.client |
@@ -337,74 +336,6 @@ def cf_safe_name(name): |
337 | 336 | return "".join([uppercase_first_letter(part) for part in parts]) |
338 | 337 |
|
339 | 338 |
|
340 | | -def handle_hooks(stage, hooks, provider, context): |
341 | | - """ Used to handle pre/post_build hooks. |
342 | | -
|
343 | | - These are pieces of code that we want to run before/after the builder |
344 | | - builds the stacks. |
345 | | -
|
346 | | - Args: |
347 | | - stage (string): The current stage (pre_run, post_run, etc). |
348 | | - hooks (list): A list of :class:`stacker.config.Hook` containing the |
349 | | - hooks to execute. |
350 | | - provider (:class:`stacker.provider.base.BaseProvider`): The provider |
351 | | - the current stack is using. |
352 | | - context (:class:`stacker.context.Context`): The current stacker |
353 | | - context. |
354 | | - """ |
355 | | - if not hooks: |
356 | | - logger.debug("No %s hooks defined.", stage) |
357 | | - return |
358 | | - |
359 | | - hook_paths = [] |
360 | | - for i, h in enumerate(hooks): |
361 | | - try: |
362 | | - hook_paths.append(h.path) |
363 | | - except KeyError: |
364 | | - raise ValueError("%s hook #%d missing path." % (stage, i)) |
365 | | - |
366 | | - logger.info("Executing %s hooks: %s", stage, ", ".join(hook_paths)) |
367 | | - for hook in hooks: |
368 | | - data_key = hook.data_key |
369 | | - required = hook.required |
370 | | - kwargs = hook.args or {} |
371 | | - enabled = hook.enabled |
372 | | - if not enabled: |
373 | | - logger.debug("hook with method %s is disabled, skipping", |
374 | | - hook.path) |
375 | | - continue |
376 | | - try: |
377 | | - method = load_object_from_string(hook.path) |
378 | | - except (AttributeError, ImportError): |
379 | | - logger.exception("Unable to load method at %s:", hook.path) |
380 | | - if required: |
381 | | - raise |
382 | | - continue |
383 | | - try: |
384 | | - result = method(context=context, provider=provider, **kwargs) |
385 | | - except Exception: |
386 | | - logger.exception("Method %s threw an exception:", hook.path) |
387 | | - if required: |
388 | | - raise |
389 | | - continue |
390 | | - if not result: |
391 | | - if required: |
392 | | - logger.error("Required hook %s failed. Return value: %s", |
393 | | - hook.path, result) |
394 | | - sys.exit(1) |
395 | | - logger.warning("Non-required hook %s failed. Return value: %s", |
396 | | - hook.path, result) |
397 | | - else: |
398 | | - if isinstance(result, collections.Mapping): |
399 | | - if data_key: |
400 | | - logger.debug("Adding result for hook %s to context in " |
401 | | - "data_key %s.", hook.path, data_key) |
402 | | - context.set_hook_data(data_key, result) |
403 | | - else: |
404 | | - logger.debug("Hook %s returned result data, but no data " |
405 | | - "key set, so ignoring.", hook.path) |
406 | | - |
407 | | - |
408 | 339 | def get_config_directory(): |
409 | 340 | """Return the directory the config file is located in. |
410 | 341 |
|
|
0 commit comments