Skip to content

Commit

Permalink
Display warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Psychokiller1888 committed Apr 10, 2021
1 parent ebdff96 commit 5c36ab1
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 5 deletions.
9 changes: 5 additions & 4 deletions ProjectAliceSK/validate/src/TalkValidation.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ def jsonFiles(self) -> Generator[Path, None, None]:
def validateTypes(self):
# check whether the same slots appear in all files
for file in self.jsonFiles:
errors = [talkType for talkType in self._files['en'] if talkType not in self._files[file.stem]]
if errors:
self.saveIndentedError(2, f'missing types in {file.parent.name}/{file.name}:')
self.printErrorList(errors, 4)
warnings = [talkType for talkType in self._files['en'] if talkType not in self._files[file.stem]]
if warnings:
self.saveIndentedWarning(2, f'Missing translations in {file.parent.name}/{file.name}:')
self.printWarningList(warnings, 4)
self._warning = True


def loadFiles(self):
Expand Down
20 changes: 20 additions & 0 deletions ProjectAliceSK/validate/src/Validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,38 @@ def __init__(self):
self._dirPath = Path(__file__).resolve().parent
self._basePath = self._dirPath.parent.parent.parent
self._error = False
self._warning = False
self._files = dict()
self.errors = ''
self.warnings = ''


def reset(self, skillPath: Path):
self._skillPath = skillPath
self._error = False
self._warning = False
self.errors = ''
self.warnings = ''


@property
def errorCode(self) -> bool:
return self._error


@property
def warning(self) -> bool:
return self._warning


def saveIndentedError(self, indent: int, *args):
self.errors += ' ' * indent + ' '.join(map(str, args)) + '\n'


def saveIndentedWarning(self, indent: int, *args):
self.warnings += ' ' * indent + ' '.join(map(str, args)) + '\n'


@property
@abstractmethod
def jsonSchema(self) -> dict:
Expand Down Expand Up @@ -66,6 +79,13 @@ def printErrorList(self, errorList: list, indent: int = 0):
self.saveIndentedError(0)


def printWarningList(self, warningList: list, indent: int = 0):
if warningList:
for warning in warningList:
self.saveIndentedWarning(indent, '-', warning)
self.saveIndentedWarning(0)


def validateJsonSchema(self, file: Path):
schema = self.jsonSchema
data = self.validateSyntax(file)
Expand Down
16 changes: 16 additions & 0 deletions ProjectAliceSK/validate/src/Validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ def validate(self):
self.printErrors('Config file', config)
self.printErrors('Sample files', samples)
self.indentPrint(0)
elif dialog.warning or installer.warning or talk.warning or samples.warning:
self.indentPrint(0, click.style(f'{skill.name}', fg='yellow', bold=True), 'warning')
self.printWarnings('Installer', installer)
self.printWarnings('Dialog files', dialog)
self.printWarnings('Talk files', talk)
self.printWarnings('Config file', config)
self.printWarnings('Sample files', samples)
self.indentPrint(0)
else:
self.indentPrint(0, click.style(f'{skill.name}', fg='green', bold=True), 'valid')

Expand All @@ -79,3 +87,11 @@ def printErrors(self, name: str, validation: Validation):
click.echo(validation.errors)
else:
self.indentPrint(2, click.style(name, bold=True), 'valid')


def printWarnings(self, name: str, validation: Validation):
if validation.warning:
self.indentPrint(2, click.style(f'{name}:', bold=True))
click.echo(validation.warnings)
else:
self.indentPrint(2, click.style(name, bold=True), 'valid')
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
setup(
name='projectalice-sk',
author='ProjectAlice',
version='2.0.2',
version='2.0.3',
maintainer='Psychokiller1888',
maintainer_email='[email protected]',
description='Project Alice skill kit',
Expand Down

0 comments on commit 5c36ab1

Please sign in to comment.