You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ariatosca.apache.org by da...@apache.org on 2016/10/19 15:46:27 UTC
[2/2] incubator-ariatosca git commit: fix some
fix some
Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/38b88525
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/38b88525
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/38b88525
Branch: refs/heads/pylint-cli
Commit: 38b88525c6bc7b14df1256143613c6469b7c6929
Parents: 82aaf7c
Author: Dan Kilman <da...@gmail.com>
Authored: Wed Oct 19 18:45:59 2016 +0300
Committer: Dan Kilman <da...@gmail.com>
Committed: Wed Oct 19 18:45:59 2016 +0300
----------------------------------------------------------------------
aria/cli/args_parser.py | 23 +++++++++++++++++++++--
aria/cli/cli.py | 13 +++++++++++++
aria/cli/commands.py | 38 +++++++++++++++++++++++++++-----------
aria/cli/config.py | 9 +++++++++
4 files changed, 70 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/38b88525/aria/cli/args_parser.py
----------------------------------------------------------------------
diff --git a/aria/cli/args_parser.py b/aria/cli/args_parser.py
index 30d213f..f40919c 100644
--- a/aria/cli/args_parser.py
+++ b/aria/cli/args_parser.py
@@ -13,6 +13,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+"""
+Argument parsing configuration and functions
+"""
+
import argparse
from functools import partial
@@ -20,6 +24,9 @@ NO_VERBOSE = 0
class SmartFormatter(argparse.HelpFormatter):
+ """
+ TODO: what is this?
+ """
def _split_lines(self, text, width):
if text.startswith('R|'):
return text[2:].splitlines()
@@ -27,10 +34,13 @@ class SmartFormatter(argparse.HelpFormatter):
def sub_parser_decorator(func=None, **parser_settings):
+ """
+ Decorated for sub_parser argument definitions
+ """
if not func:
return partial(sub_parser_decorator, **parser_settings)
- def wrapper(parser):
+ def _wrapper(parser):
sub_parser = parser.add_parser(**parser_settings)
sub_parser.add_argument(
'-v', '--verbose',
@@ -44,10 +54,13 @@ def sub_parser_decorator(func=None, **parser_settings):
help='A unique ID for the deployment')
func(sub_parser)
return sub_parser
- return wrapper
+ return _wrapper
def config_parser(parser=None):
+ """
+ Top level argparse configuration
+ """
parser = parser or argparse.ArgumentParser(
prog='Aria',
description="Aria's Command Line Interface",
@@ -64,6 +77,9 @@ def config_parser(parser=None):
help='Initialize environment',
formatter_class=SmartFormatter)
def add_init_parser(init):
+ """
+ ``init`` command parser configuration
+ """
init.add_argument(
'-p', '--blueprint-path',
dest='blueprint_path',
@@ -90,6 +106,9 @@ def add_init_parser(init):
help='Execute a workflow',
formatter_class=SmartFormatter)
def add_execute_parser(execute):
+ """
+ ``execute`` command parser configuration
+ """
execute.add_argument(
'-w', '--workflow',
dest='workflow_id',
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/38b88525/aria/cli/cli.py
----------------------------------------------------------------------
diff --git a/aria/cli/cli.py b/aria/cli/cli.py
index 24573c9..a4046ac 100644
--- a/aria/cli/cli.py
+++ b/aria/cli/cli.py
@@ -13,6 +13,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+"""
+CLI Entry point
+"""
+
import logging
from aria.logger import (
@@ -31,6 +35,9 @@ __version__ = '0.1.0'
class AriaCli(LoggerMixin):
+ """
+ Context manager based class that enables proper top level error handling
+ """
def __init__(self, *args, **kwargs):
super(AriaCli, self).__init__(*args, **kwargs)
@@ -56,6 +63,9 @@ class AriaCli(LoggerMixin):
pass
def run(self):
+ """
+ Parses user arguments and run the appropriate command
+ """
parser = config_parser()
args = parser.parse_args()
@@ -66,6 +76,9 @@ class AriaCli(LoggerMixin):
def main():
+ """
+ CLI entry point
+ """
create_logger(
handlers=[
create_console_log_handler(),
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/38b88525/aria/cli/commands.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands.py b/aria/cli/commands.py
index 7442cca..12642ce 100644
--- a/aria/cli/commands.py
+++ b/aria/cli/commands.py
@@ -13,6 +13,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+"""
+CLI various commands implementation
+"""
+
import json
import os
import sys
@@ -51,6 +55,10 @@ from dsl_parser.tasks import prepare_deployment_plan
class BaseCommand(LoggerMixin):
+ """
+ Base class for CLI commands
+ """
+
def __repr__(self):
return 'AriaCli({cls.__name__})'.format(cls=self.__class__)
@@ -73,7 +81,7 @@ class BaseCommand(LoggerMixin):
parsed_dict = {}
- def format_to_dict(input_string):
+ def _format_to_dict(input_string):
self.logger.info('Processing inputs source: {0}'.format(input_string))
try:
input_string = input_string.strip()
@@ -86,7 +94,7 @@ class BaseCommand(LoggerMixin):
except Exception as exc:
raise AriaCliFormatInputsError(str(exc), inputs=input_string)
- def handle_inputs_source(input_path):
+ def _handle_inputs_source(input_path):
self.logger.info('Processing inputs source: {0}'.format(input_path))
try:
with open(input_path) as input_file:
@@ -104,26 +112,30 @@ class BaseCommand(LoggerMixin):
for input_string in inputs if isinstance(inputs, list) else [inputs]:
if os.path.isdir(input_string):
for input_file in os.listdir(input_string):
- handle_inputs_source(os.path.join(input_string, input_file))
+ _handle_inputs_source(os.path.join(input_string, input_file))
continue
input_files = glob(input_string)
if input_files:
for input_file in input_files:
- handle_inputs_source(input_file)
+ _handle_inputs_source(input_file)
continue
- format_to_dict(input_string)
+ _format_to_dict(input_string)
return parsed_dict
class InitCommand(BaseCommand):
+ """
+ ``init`` command implementation
+ """
+
_IN_VIRTUAL_ENV = hasattr(sys, 'real_prefix')
def __call__(self, args_namespace):
super(InitCommand, self).__call__(args_namespace)
- self.workspace_setup()
+ self._workspace_setup()
inputs = self.parse_inputs(args_namespace.input) if args_namespace.input else None
- plan, deployment_plan = self.parse_blueprint(args_namespace.blueprint_path, inputs)
- self.create_storage(
+ plan, deployment_plan = self._parse_blueprint(args_namespace.blueprint_path, inputs)
+ self._create_storage(
blueprint_plan=plan,
blueprint_path=args_namespace.blueprint_path,
deployment_plan=deployment_plan,
@@ -136,7 +148,7 @@ class InitCommand(BaseCommand):
'run `aria local init -p {0}` command again to apply them'.format(
args_namespace.blueprint_path))
- def workspace_setup(self):
+ def _workspace_setup(self):
try:
create_user_space()
self.logger.debug(
@@ -153,14 +165,14 @@ class InitCommand(BaseCommand):
'local storage path already exist - {0}'.format(local_storage()))
return local_storage()
- def parse_blueprint(self, blueprint_path, inputs=None):
+ def _parse_blueprint(self, blueprint_path, inputs=None):
plan = parse_from_path(blueprint_path)
self.logger.info('blueprint parsed successfully')
deployment_plan = prepare_deployment_plan(plan=plan.copy(), inputs=inputs)
return plan, deployment_plan
@staticmethod
- def create_storage(
+ def _create_storage(
blueprint_path,
blueprint_plan,
deployment_plan,
@@ -192,6 +204,10 @@ class InitCommand(BaseCommand):
class ExecuteCommand(BaseCommand):
+ """
+ ``execute`` command implementation
+ """
+
def __call__(self, args_namespace):
super(ExecuteCommand, self).__call__(args_namespace)
parameters = (self.parse_inputs(args_namespace.parameters)
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/38b88525/aria/cli/config.py
----------------------------------------------------------------------
diff --git a/aria/cli/config.py b/aria/cli/config.py
index ace79ba..7aae22a 100644
--- a/aria/cli/config.py
+++ b/aria/cli/config.py
@@ -13,6 +13,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+"""
+CLI configuration
+"""
+
import os
import logging
from getpass import getuser
@@ -33,6 +37,11 @@ import_resolver = None
def load_configurations():
+ """
+ Dynamically load attributes into the config module from the ``config.yaml`` defined in the user
+ configuration directory
+ :return:
+ """
config_path = config_file_path()
with open(config_path) as config_file:
globals().update(safe_load(config_file) or {})