fix: ExtentionError => ExtensionError
This commit is contained in:
parent
9b6361a5dc
commit
22730c8c2d
1 changed files with 27 additions and 11 deletions
|
|
@ -18,12 +18,13 @@ You should have received a copy of the GNU General Public License
|
||||||
along with this program; if not, write to the Free Software
|
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
|
||||||
"""
|
"""
|
||||||
|
import warnings
|
||||||
from questionary import text, select, confirm, password, Validator, ValidationError, print as qprint
|
from questionary import text, select, confirm, password, Validator, ValidationError, print as qprint
|
||||||
|
|
||||||
from rougail.tiramisu import CONVERT_OPTION
|
from rougail.tiramisu import CONVERT_OPTION
|
||||||
from rougail.config import RougailConfig
|
from rougail.config import RougailConfig
|
||||||
from rougail.error import ExtentionError
|
from rougail.error import ExtensionError
|
||||||
from tiramisu.error import ValueOptionError
|
from tiramisu.error import ValueOptionError, ValueErrorWarning, ValueWarning
|
||||||
|
|
||||||
|
|
||||||
class RougailUserDataQuestionary:
|
class RougailUserDataQuestionary:
|
||||||
|
|
@ -45,15 +46,22 @@ class RougailUserDataQuestionary:
|
||||||
rougailconfig['step.user_data'] = user_data
|
rougailconfig['step.user_data'] = user_data
|
||||||
user_data = rougailconfig['step.user_data']
|
user_data = rougailconfig['step.user_data']
|
||||||
if 'questionary' not in user_data:
|
if 'questionary' not in user_data:
|
||||||
raise ExtentionError('questionary is not set in step.user_data')
|
raise ExtensionError('questionary is not set in step.user_data')
|
||||||
self.rougailconfig = rougailconfig
|
self.rougailconfig = rougailconfig
|
||||||
self.errors = []
|
self.errors = []
|
||||||
self.warnings = []
|
self.warnings = []
|
||||||
|
warnings.simplefilter("always", ValueErrorWarning)
|
||||||
|
warnings.simplefilter("always", ValueWarning)
|
||||||
|
|
||||||
def run(
|
def run(
|
||||||
self,
|
self,
|
||||||
) -> None:
|
) -> None:
|
||||||
self.config.property.read_write()
|
# self.config.property.read_write()
|
||||||
|
if 'demoting_error_warning' not in self.config.property.get():
|
||||||
|
add_demoting = True
|
||||||
|
self.config.property.add('demoting_error_warning')
|
||||||
|
else:
|
||||||
|
add_demoting = False
|
||||||
if self.rougailconfig['questionary.mandatory']:
|
if self.rougailconfig['questionary.mandatory']:
|
||||||
current_titles = []
|
current_titles = []
|
||||||
while True:
|
while True:
|
||||||
|
|
@ -75,16 +83,14 @@ class RougailUserDataQuestionary:
|
||||||
self.display_questionary(mandatory)
|
self.display_questionary(mandatory)
|
||||||
else:
|
else:
|
||||||
self.parse(self.config)
|
self.parse(self.config)
|
||||||
self.config.property.read_only()
|
if add_demoting:
|
||||||
return {'errors': [],
|
self.config.property.remove('demoting_error_warning')
|
||||||
'warnings': [],
|
|
||||||
}
|
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
"source": 'Questionary',
|
"source": 'Questionary',
|
||||||
"errors": self.errors,
|
"errors": self.errors,
|
||||||
"warnings": self.warnings,
|
"warnings": self.warnings,
|
||||||
"values": values,
|
"values": [],
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
@ -103,7 +109,9 @@ class RougailUserDataQuestionary:
|
||||||
kwargs = {}
|
kwargs = {}
|
||||||
option_type = option.information.get('type')
|
option_type = option.information.get('type')
|
||||||
isdefault = option.owner.isdefault()
|
isdefault = option.owner.isdefault()
|
||||||
default = option.value.get()
|
with warnings.catch_warnings():
|
||||||
|
warnings.simplefilter("ignore")
|
||||||
|
default = option.value.get()
|
||||||
ismulti = option.ismulti()
|
ismulti = option.ismulti()
|
||||||
type_obj = None
|
type_obj = None
|
||||||
type_obj = CONVERT_OPTION.get(option_type, {}).get("func")
|
type_obj = CONVERT_OPTION.get(option_type, {}).get("func")
|
||||||
|
|
@ -159,7 +167,15 @@ class RougailValidator(Validator):
|
||||||
value.append(val)
|
value.append(val)
|
||||||
if validate:
|
if validate:
|
||||||
try:
|
try:
|
||||||
self.option.value.set(value)
|
with warnings.catch_warnings(record=True) as warns:
|
||||||
|
self.option.value.set(value)
|
||||||
|
for warn in warns:
|
||||||
|
if isinstance(warn.message, ValueErrorWarning):
|
||||||
|
warn.message.prefix = ''
|
||||||
|
raise ValidationError(
|
||||||
|
message=str(warn.message),
|
||||||
|
cursor_position=len(document),
|
||||||
|
)
|
||||||
except ValueOptionError as err:
|
except ValueOptionError as err:
|
||||||
err.prefix = ''
|
err.prefix = ''
|
||||||
raise ValidationError(
|
raise ValidationError(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue