slightly rework structure
This commit is contained in:
parent
f1321faef0
commit
7b158ac72b
@ -27,3 +27,14 @@ def read_data(filename):
|
||||
filepath = os.path.join(DATA_DIR, filename)
|
||||
with open(filepath, 'r') as fd:
|
||||
return yaml.safe_load(fd)
|
||||
|
||||
def rewrite_data(filename, data):
|
||||
"""Rewrites data formatting it
|
||||
|
||||
"""
|
||||
from ruamel.yaml import YAML
|
||||
_yaml = YAML()
|
||||
_yaml.indent(mapping=2, sequence=4, offset=2)
|
||||
filepath = os.path.join(DATA_DIR, filename)
|
||||
with open(filepath, 'w') as fd:
|
||||
_yaml.dump(data, fd)
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -32,11 +32,40 @@ class Services(object):
|
||||
def __init__(self):
|
||||
self._service_data = BUILTIN_DATA
|
||||
|
||||
def _sorted_data(self):
|
||||
self._service_data['documents'] = sorted(
|
||||
self._service_data['documents'],
|
||||
key=lambda x: f"{x.get('service_type')}{x.get('title')}"
|
||||
)
|
||||
self._service_data['services'] = sorted(
|
||||
self._service_data['services'],
|
||||
key=lambda x: f"{x.get('service_type')}{x.get('service_title')}"
|
||||
)
|
||||
|
||||
def _rewrite_data(self):
|
||||
otc_metadata.data.rewrite_data(
|
||||
"services.yaml",
|
||||
self._service_data
|
||||
)
|
||||
|
||||
@property
|
||||
def all_services(self):
|
||||
"Service Categories data listing."
|
||||
return copy.deepcopy(self._service_data['services'])
|
||||
|
||||
@property
|
||||
def all_docs(self):
|
||||
"Service Docs data listing."
|
||||
return copy.deepcopy(self._service_data['documents'])
|
||||
|
||||
@property
|
||||
def service_dict(self):
|
||||
"Service Docs data listing."
|
||||
res = dict()
|
||||
for srv in self.all_services:
|
||||
res[srv["service_type"]] = copy.deepcopy(srv)
|
||||
return res
|
||||
|
||||
def services_by_category(self, category):
|
||||
"""List services matching category
|
||||
"""
|
||||
@ -45,3 +74,24 @@ class Services(object):
|
||||
if srv['service_category'] == category:
|
||||
res.append(copy.deepcopy(srv))
|
||||
return res
|
||||
|
||||
def docs_by_service_category(self, category, env=None):
|
||||
"""List services matching category
|
||||
|
||||
:param str category: Category name
|
||||
:param str env: Optional service environment. Influeces "repository"
|
||||
field
|
||||
"""
|
||||
res = []
|
||||
services = self.service_dict
|
||||
for doc in self.all_docs:
|
||||
service = services[doc["service_type"]]
|
||||
if service["service_category"] == category:
|
||||
res_doc = copy.deepcopy(doc)
|
||||
res_doc.update(**service)
|
||||
if env:
|
||||
for srv_env in service["repositories"]:
|
||||
if srv_env.get("env") == env:
|
||||
res_doc["repository"] = srv_env["repo"]
|
||||
res.append(res_doc)
|
||||
return res
|
||||
|
Loading…
x
Reference in New Issue
Block a user