Skip to content

Commit

Permalink
Add YAML reporter
Browse files Browse the repository at this point in the history
  • Loading branch information
ezh committed Feb 11, 2020
1 parent 46d5c7d commit 4609a19
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 8 deletions.
3 changes: 2 additions & 1 deletion cloudselect/cloud.json.dist
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
},
"report": {
"json": "cloudselect.report.json",
"json_pp": "cloudselect.report.json_pp"
"json_pp": "cloudselect.report.json_pp",
"yaml": "cloudselect.report.yaml"
}
}
}
8 changes: 4 additions & 4 deletions cloudselect/report/json.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Copyright 2019 Alexey Aksenov and individual contributors
# Copyright 2019-2020 Alexey Aksenov and individual contributors
# See the LICENSE.txt file at the top-level directory of this distribution.
#
# Licensed under the MIT license
# <LICENSE-MIT or http://opensource.org/licenses/MIT>
# This file may not be copied, modified, or distributed
# except according to those terms.
"""Module that represents list of selected instances as pretty print output."""
"""Module that represents list of selected instances as JSON output."""
import json

from cloudselect import Container
Expand All @@ -14,10 +14,10 @@


class Json(ReportService):
"""Json reporter implementation."""
"""JSON reporter implementation."""

def run(self, selected):
"""Represent instances as pretty print output."""
"""Represent instances as JSON output."""
# get first instance
# assume that all instances match the same group/pattern
instance = next(iter(selected), None)
Expand Down
6 changes: 3 additions & 3 deletions cloudselect/report/json_pp.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# <LICENSE-MIT or http://opensource.org/licenses/MIT>
# This file may not be copied, modified, or distributed
# except according to those terms.
"""Module that represents list of selected instances as pretty print output."""
"""Module that represents list of selected instances as formatted JSON output."""
import json

from cloudselect import Container
Expand All @@ -14,10 +14,10 @@


class JsonPP(ReportService):
"""Json reporter implementation."""
"""Formatted JSON reporter implementation."""

def run(self, selected):
"""Represent instances as pretty print output."""
"""Represent instances as formatted JSON output."""
# get first instance
# assume that all instances match the same group/pattern
instance = next(iter(selected), None)
Expand Down
26 changes: 26 additions & 0 deletions cloudselect/report/yaml.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2020 Alexey Aksenov and individual contributors
# See the LICENSE.txt file at the top-level directory of this distribution.
#
# Licensed under the MIT license
# <LICENSE-MIT or http://opensource.org/licenses/MIT>
# This file may not be copied, modified, or distributed
# except according to those terms.
"""Module that represents list of selected instances as JSON output."""
from yaml import safe_dump

from cloudselect import Container

from . import ReportService


class Yaml(ReportService):
"""YAML reporter implementation."""

def run(self, selected):
"""Represent instances as YAML output."""
# get first instance
# assume that all instances match the same group/pattern
instance = next(iter(selected), None)
options = Container.options("option", instance)
report = {"instances": [i.to_dict() for i in selected], "option": options}
print(safe_dump(report, indent=2))
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ appdirs==1.4.3
boto3==1.11.14
chardet==3.0.4
dependency-injector==3.15.4
pyyaml==5.2
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"boto3==1.11.14",
"chardet==3.0.4",
"dependency-injector==3.15.4",
"pyyaml==5.2",
],
include_package_data=True,
keywords=["Cloud", "CLI", "FZF", "SSH", "SCP", "AWS"],
Expand Down
1 change: 1 addition & 0 deletions test/test_cloudselect.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def test_cli_configuration_read():
"report": {
"json": "cloudselect.report.json",
"json_pp": "cloudselect.report.json_pp",
"yaml": "cloudselect.report.yaml",
},
},
}
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ deps = codecov
boto3
chardet
dependency_injector
pyyaml
commands = {posargs:py.test}
codecov: codecov -e TOXENV

0 comments on commit 4609a19

Please sign in to comment.