feat: support auto_save variable
This commit is contained in:
parent
c5d67cfd61
commit
1b3ae40dce
4 changed files with 47 additions and 24 deletions
|
@ -19,6 +19,7 @@ along with this program; if not, write to the Free Software
|
|||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
"""
|
||||
|
||||
from typing import Optional
|
||||
from tiramisu.error import PropertiesOptionError, ConfigError
|
||||
from rougail import RougailConfig
|
||||
from .config import OutPuts
|
||||
|
@ -29,6 +30,8 @@ class RougailOutputExporter:
|
|||
def __init__(self,
|
||||
conf: 'Config',
|
||||
rougailconfig: RougailConfig=None,
|
||||
user_data_errors: Optional[list]=None,
|
||||
user_data_warnings: Optional[list]=None,
|
||||
) -> None:
|
||||
if rougailconfig is None:
|
||||
rougailconfig = RougailConfig
|
||||
|
@ -41,11 +44,13 @@ class RougailOutputExporter:
|
|||
self.read_write = self.rougailconfig['exporter.read_write']
|
||||
self.errors = []
|
||||
self.warnings = []
|
||||
self.user_data_errors = user_data_errors
|
||||
self.user_data_warnings = user_data_warnings
|
||||
self.formater = outputs[output](self.rougailconfig)
|
||||
self.root = self.formater.root()
|
||||
|
||||
def mandatory(self):
|
||||
if self.rougailconfig['exporter.no_mandatory']:
|
||||
if not self.rougailconfig['exporter.mandatory']:
|
||||
return
|
||||
title = False
|
||||
options_with_error = []
|
||||
|
@ -78,11 +83,14 @@ class RougailOutputExporter:
|
|||
self.conf.property.read_write()
|
||||
else:
|
||||
self.conf.property.read_only()
|
||||
errors = self.user_data_errors + self.errors
|
||||
if errors:
|
||||
self.formater.errors(errors)
|
||||
if self.errors:
|
||||
self.formater.errors(self.errors)
|
||||
return False
|
||||
if self.warnings:
|
||||
self.formater.warnings(self.warnings)
|
||||
warnings = self.user_data_warnings + self.warnings
|
||||
if warnings:
|
||||
self.formater.warnings(warnings)
|
||||
self.formater.header()
|
||||
self.parse_options(self.conf,
|
||||
self.root,
|
||||
|
@ -93,6 +101,10 @@ class RougailOutputExporter:
|
|||
def print(self) -> None:
|
||||
return self.formater.print()
|
||||
|
||||
def run(self) -> None:
|
||||
self.exporter()
|
||||
self.print()
|
||||
|
||||
def parse_options(self,
|
||||
conf,
|
||||
parent,
|
||||
|
@ -116,13 +128,14 @@ class RougailOutputExporter:
|
|||
parent,
|
||||
):
|
||||
leader, *followers = list(conf)
|
||||
idx = -1
|
||||
leader_values = leader.value.get()
|
||||
for follower in followers:
|
||||
if idx != follower.index():
|
||||
idx += 1
|
||||
for idx, leader_value in enumerate(leader_values):
|
||||
leader_obj = parent.add_family(leader)
|
||||
leader_obj.add_variable(leader,
|
||||
value=follower.value.get(),
|
||||
value=leader_value,
|
||||
leader_index=idx,
|
||||
)
|
||||
for follower in followers:
|
||||
if follower.index() != idx:
|
||||
continue
|
||||
leader_obj.add_variable(follower)
|
||||
|
|
|
@ -27,14 +27,18 @@ def run(rougailconfig,
|
|||
config,
|
||||
user_data,
|
||||
):
|
||||
if user_data:
|
||||
errors = user_data['errors']
|
||||
warnings = user_data['warnings']
|
||||
else:
|
||||
errors = []
|
||||
warnings = []
|
||||
export = RougailOutputExporter(config,
|
||||
rougailconfig,
|
||||
user_data_errors=errors,
|
||||
user_data_warnings=warnings,
|
||||
)
|
||||
if user_data:
|
||||
export.errors = user_data['errors']
|
||||
export.warnings = user_data['warnings']
|
||||
export.exporter()
|
||||
export.print()
|
||||
export.run()
|
||||
|
||||
|
||||
__all__ = ('run',)
|
||||
|
|
|
@ -73,17 +73,20 @@ exporter:
|
|||
disabled
|
||||
{% endif %}
|
||||
read_write:
|
||||
description: Display only variables available in read_write mode
|
||||
description: Display variables available in read_write mode
|
||||
negative_description: Display variables available in read_only mode
|
||||
alternative_name: er
|
||||
default: false
|
||||
show_secrets:
|
||||
description: Show secrets instead of obscuring them
|
||||
negative_description: Obscuring secrets instead of show them
|
||||
alternative_name: es
|
||||
default: false
|
||||
no_mandatory:
|
||||
description: Do not test mandatories variable before export
|
||||
mandatory:
|
||||
description: Test mandatories variable before export
|
||||
negative_description: Do not test mandatories variable before export
|
||||
alternative_name: em
|
||||
default: false
|
||||
default: true
|
||||
output_format:
|
||||
description: Generate document in format
|
||||
alternative_name: eo
|
||||
|
|
|
@ -20,7 +20,7 @@ along with this program; if not, write to the Free Software
|
|||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
"""
|
||||
|
||||
from typing import Any, List
|
||||
from typing import Any, List, Optional
|
||||
|
||||
from rich.tree import Tree
|
||||
from rich.console import Console
|
||||
|
@ -215,6 +215,7 @@ class OutputFamily:
|
|||
def add_variable(self,
|
||||
option,
|
||||
value: Any=undefined,
|
||||
leader_index: Optional[int]=None
|
||||
):
|
||||
properties = option.property.get()
|
||||
variable_color = None
|
||||
|
@ -232,6 +233,8 @@ class OutputFamily:
|
|||
variable_color = self.root.variable_advanced_and_modified_color
|
||||
color = None
|
||||
default_value = option.value.default()
|
||||
if leader_index is not None and len(default_value) > leader_index:
|
||||
default_value = default_value[leader_index]
|
||||
if value is undefined:
|
||||
value = option.value.get()
|
||||
key = self.colorize(None,
|
||||
|
@ -293,7 +296,7 @@ class OutputFamily:
|
|||
ret = f'[{color}]{value}[/{color}]'
|
||||
else:
|
||||
ret = value
|
||||
if default_value:
|
||||
if default_value and 'force_store_value' not in option.property.get():
|
||||
default_value_color = self.root.value_default_color
|
||||
ret += f' ([{default_value_color}]{default_value}[/{default_value_color}])'
|
||||
return ret
|
||||
|
|
Loading…
Reference in a new issue