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