Improve error handling for project root dir, add ENV support for project root

This commit is contained in:
Stefan Reimer 2019-12-06 14:46:41 +00:00
parent 7a13e11426
commit 6cadc18397
5 changed files with 18 additions and 4 deletions

View File

@ -2,7 +2,7 @@ import logging
__author__ = "Stefan Reimer" __author__ = "Stefan Reimer"
__email__ = "stefan@zero-downtimet.net" __email__ = "stefan@zero-downtimet.net"
__version__ = "0.7.6" __version__ = "0.7.7"
# Set up logging to ``/dev/null`` like a library is supposed to. # Set up logging to ``/dev/null`` like a library is supposed to.

View File

@ -1,4 +1,5 @@
import os import os
import sys
import click import click
import functools import functools
@ -7,6 +8,7 @@ from concurrent.futures import ThreadPoolExecutor, as_completed
from . import __version__ from . import __version__
from .core import CloudBender from .core import CloudBender
from .utils import setup_logging from .utils import setup_logging
from .exceptions import InvalidProjectDir
import logging import logging
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -24,11 +26,18 @@ def cli(ctx, debug, directory):
if directory: if directory:
if not os.path.isabs(directory): if not os.path.isabs(directory):
directory = os.path.normpath(os.path.join(os.getcwd(), directory)) directory = os.path.normpath(os.path.join(os.getcwd(), directory))
elif os.getenv('CLOUDBENDER_PROJECT_ROOT'):
directory = os.getenv('CLOUDBENDER_PROJECT_ROOT')
else: else:
directory = os.getcwd() directory = os.getcwd()
# Read global config # Read global config
try:
cb = CloudBender(directory) cb = CloudBender(directory)
except InvalidProjectDir as e:
print(e)
sys.exit(1)
cb.read_config() cb.read_config()
cb.dump_config() cb.dump_config()

View File

@ -4,6 +4,7 @@ import logging
from .utils import ensure_dir from .utils import ensure_dir
from .stackgroup import StackGroup from .stackgroup import StackGroup
from .jinja import read_config_file from .jinja import read_config_file
from .exceptions import InvalidProjectDir
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -22,7 +23,7 @@ class CloudBender(object):
} }
if not os.path.isdir(self.ctx['config_path']): if not os.path.isdir(self.ctx['config_path']):
raise "Check '{0}' exists and is a valid project folder.".format(root_path) raise InvalidProjectDir("Check '{0}' exists and is a valid CloudBender project folder.".format(root_path))
def read_config(self): def read_config(self):
"""Load the <path>/config.yaml, <path>/*.yaml as stacks, sub-folders are sub-groups """ """Load the <path>/config.yaml, <path>/*.yaml as stacks, sub-folders are sub-groups """

View File

@ -4,3 +4,7 @@ class ParameterNotFound(Exception):
class ParameterIllegalValue(Exception): class ParameterIllegalValue(Exception):
"""My documentation""" """My documentation"""
class InvalidProjectDir(BaseException):
"""My documentation"""

View File

@ -270,7 +270,7 @@ class Stack(object):
# Ignore checks regarding overloaded properties # Ignore checks regarding overloaded properties
if self.mode == "CloudBender": if self.mode == "CloudBender":
ignore_checks = ignore_checks + ['E3035', 'E3002', 'E3012', 'W2001', 'E3001'] ignore_checks = ignore_checks + ['E3035', 'E3002', 'E3012', 'W2001', 'E3001', 'E0002', 'E1012']
filename = os.path.join(self.ctx['template_path'], self.rel_path, self.stackname + ".yaml") filename = os.path.join(self.ctx['template_path'], self.rel_path, self.stackname + ".yaml")
logger.info('Validating {0}'.format(filename)) logger.info('Validating {0}'.format(filename))