Ya imprime manual
This commit is contained in:
parent
fdd44d72ff
commit
adc543e608
32
README.md
32
README.md
|
@ -1,7 +1,3 @@
|
||||||
---
|
|
||||||
warn: This is just a prototype.
|
|
||||||
---
|
|
||||||
|
|
||||||
# YASD, Yet Another Schema Definition
|
# YASD, Yet Another Schema Definition
|
||||||
|
|
||||||
YASD is a YAML format for human writable XSDs (XML Schema Definition), humans
|
YASD is a YAML format for human writable XSDs (XML Schema Definition), humans
|
||||||
|
@ -36,7 +32,7 @@ To better understad what YASD does, see the inputs and outputs:
|
||||||
|
|
||||||
- Input: human workable schema in [YASD].
|
- Input: human workable schema in [YASD].
|
||||||
- Output: computer processable schema in [XSD].
|
- Output: computer processable schema in [XSD].
|
||||||
- Output: human readable documentation in [reStructuredText][RST].
|
- Output: human readable documentation in [reStructuredText].
|
||||||
|
|
||||||
## Table of Contents
|
## Table of Contents
|
||||||
|
|
||||||
|
@ -178,15 +174,17 @@ Allowed types:
|
||||||
|
|
||||||
Chart:
|
Chart:
|
||||||
|
|
||||||
| type | children elements | children text node | attributes |
|
| type | elements | text | attributes |
|
||||||
|------------|:-----------------:|:------------------:|:----------:|
|
|------------|:--------:|:----:|:----------:|
|
||||||
|simple | ✗ | ✓ | ✗ |
|
|simple | ✗ | ✓ | ✗ |
|
||||||
|empty | ✗ | ✗ | ✓ |
|
|empty | ✗ | ✗ | ✓ |
|
||||||
|no_text | ✓ | ✗ | ✓ |
|
|no_text | ✓ | ✗ | ✓ |
|
||||||
|no_elements | ✗ | ✓ | ✓ |
|
|no_elements | ✗ | ✓ | ✓ |
|
||||||
|mixed | ✓ | ✓ | ✓ |
|
|mixed | ✓ | ✓ | ✓ |
|
||||||
|
|
||||||
> **Note**: attributes are never mandatory; they could be zero or more.
|
> **Note 1**: read "elements" and "text" with "direct children…" as prefix.
|
||||||
|
|
||||||
|
> **Note 2**: attributes are never mandatory; they could be zero or more.
|
||||||
|
|
||||||
### `datatype`
|
### `datatype`
|
||||||
|
|
||||||
|
@ -396,13 +394,13 @@ Mandatory.
|
||||||
|
|
||||||
## References
|
## References
|
||||||
|
|
||||||
* “XML Schema Reference”, [W3ref]
|
- "XML Schema Reference", [W3ref]
|
||||||
* “XML Schema Tutorial”, [W3Schools].
|
- "XML Schema Tutorial", [W3Schools].
|
||||||
* “XSD Tutorial”, [Tutorials Point].
|
- "XSD Tutorial", [Tutorials Point].
|
||||||
|
|
||||||
[YASD]: https://gitlab.com/amlengua/apal/esquema/-/blob/main/apal.yaml
|
[YASD]: https://gitlab.com/amlengua/apal/esquema/-/blob/main/apal.yaml
|
||||||
[XSD]: https://gitlab.com/amlengua/apal/esquema/-/blob/main/apal.xsd
|
[XSD]: https://gitlab.com/amlengua/apal/esquema/-/blob/main/apal.xsd
|
||||||
[RST]: https://gitlab.com/amlengua/apal/esquema/-/blob/main/apal.rst
|
[reStructuredText]: https://gitlab.com/amlengua/apal/esquema/-/blob/main/apal.rst
|
||||||
[W3ref]: https://www.w3schools.com/xml/schema_elements_ref.asp
|
[W3ref]: https://www.w3schools.com/xml/schema_elements_ref.asp
|
||||||
[W3Schools]: https://www.w3schools.com/xml/schema_intro.asp
|
[W3Schools]: https://www.w3schools.com/xml/schema_intro.asp
|
||||||
[Tutorials Point]: https://www.tutorialspoint.com/xsd/
|
[Tutorials Point]: https://www.tutorialspoint.com/xsd/
|
||||||
|
|
48
yasd.py
48
yasd.py
|
@ -2,13 +2,17 @@
|
||||||
# (c) 2023 Perro Tuerto <hi@perrotuerto.blog>.
|
# (c) 2023 Perro Tuerto <hi@perrotuerto.blog>.
|
||||||
# Founded by Mexican Academy of Language <https://academia.org.mx>.
|
# Founded by Mexican Academy of Language <https://academia.org.mx>.
|
||||||
# Licensed under GPLv3 <https://www.gnu.org/licenses/gpl-3.0.en.html>.
|
# Licensed under GPLv3 <https://www.gnu.org/licenses/gpl-3.0.en.html>.
|
||||||
|
# Requirements: python > 3.10, pyyaml, lxml, bs4, rich
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import yaml
|
import yaml
|
||||||
import argparse
|
import argparse
|
||||||
|
import urllib.request
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
from bs4.formatter import XMLFormatter
|
from bs4.formatter import XMLFormatter
|
||||||
|
from rich.console import Console
|
||||||
|
from rich.markdown import Markdown
|
||||||
|
|
||||||
|
|
||||||
class YASD:
|
class YASD:
|
||||||
|
@ -72,10 +76,13 @@ class YASD:
|
||||||
:type log: True or False
|
:type log: True or False
|
||||||
"""
|
"""
|
||||||
self.msgr = YASDMessenger(quiet=quiet, log=log)
|
self.msgr = YASDMessenger(quiet=quiet, log=log)
|
||||||
self.outfile = YASDCheck.file(outfile, self.msgr)
|
|
||||||
self.yaml = YASDCheck(indata, self.msgr).yaml
|
self.yaml = YASDCheck(indata, self.msgr).yaml
|
||||||
self.formatter = XMLFormatter(indent=2)
|
self.formatter = XMLFormatter(indent=2)
|
||||||
self.stdout = stdout
|
self.stdout = stdout
|
||||||
|
if outfile is None:
|
||||||
|
self.outfile = None
|
||||||
|
else:
|
||||||
|
self.outfile = YASDCheck.file(outfile, self.msgr)
|
||||||
|
|
||||||
def convert(self):
|
def convert(self):
|
||||||
"""
|
"""
|
||||||
|
@ -483,6 +490,7 @@ class YASDMessenger:
|
||||||
"""
|
"""
|
||||||
# TODO internationalization with: https://github.com/sectasy0/pyi18n
|
# TODO internationalization with: https://github.com/sectasy0/pyi18n
|
||||||
return {
|
return {
|
||||||
|
"prog": "yasd",
|
||||||
"description": """
|
"description": """
|
||||||
YASD, Yet Another Schema Definition. YASD is a YAML format for
|
YASD, Yet Another Schema Definition. YASD is a YAML format for
|
||||||
human writable XSDs (XML Schema Definition), humans declare what is
|
human writable XSDs (XML Schema Definition), humans declare what is
|
||||||
|
@ -499,15 +507,15 @@ class YASDMessenger:
|
||||||
"help_output": "output file",
|
"help_output": "output file",
|
||||||
"help_quiet": "enable quiet mode",
|
"help_quiet": "enable quiet mode",
|
||||||
"help_log": "write log",
|
"help_log": "write log",
|
||||||
"action_convert": "Creating XSD schema",
|
"action_convert": "creating XSD schema",
|
||||||
"action_check": "Checking YASD",
|
"action_check": "checking YASD",
|
||||||
"action_sample": "Creating XML sample",
|
"action_sample": "creating XML sample",
|
||||||
"action_document": "Creating RST documentation",
|
"action_document": "creating RST documentation",
|
||||||
"invalid_level": "Invalid log level '@lvl'",
|
"invalid_level": "invalid log level '@lvl'",
|
||||||
"invalid_input": "Invalid file '@file'",
|
"invalid_input": "invalid file '@file'",
|
||||||
"invalid_yaml": "Invalid YAML structure",
|
"invalid_yaml": "invalid YAML structure",
|
||||||
"no_yaml": "YAML dict needed",
|
"no_yaml": "YAML dict needed",
|
||||||
"no_input": "Input file needed.",
|
"no_input": "input file needed",
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, quiet=False, log=False):
|
def __init__(self, quiet=False, log=False):
|
||||||
|
@ -527,8 +535,9 @@ class YASDMessenger:
|
||||||
:param str level: Log level; 'info' by default
|
:param str level: Log level; 'info' by default
|
||||||
"""
|
"""
|
||||||
self.__check_level(level)
|
self.__check_level(level)
|
||||||
|
name = YASDMessenger.keys()["prog"]
|
||||||
msg = self.__get_msg(key, **kwargs)
|
msg = self.__get_msg(key, **kwargs)
|
||||||
msg = f"[{level.upper()}] {msg}"
|
msg = f"{name}: {level}: {msg}"
|
||||||
# TODO print or save depending on self.quiet and self.log
|
# TODO print or save depending on self.quiet and self.log
|
||||||
print(msg)
|
print(msg)
|
||||||
if level in ["error", "fatal"]:
|
if level in ["error", "fatal"]:
|
||||||
|
@ -569,6 +578,20 @@ class YASDCLI:
|
||||||
YASD command-line interface.
|
YASD command-line interface.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
def print_man():
|
||||||
|
"""
|
||||||
|
Prints README as manual.
|
||||||
|
"""
|
||||||
|
# TODO if YASD becomes pip package, it should load local README
|
||||||
|
# Remove urllib import if that is the case
|
||||||
|
url = "https://gitlab.com/perrotuerto_personal/codigo/yasd/-/raw/no-masters/README.md"
|
||||||
|
raw = urllib.request.urlopen(url).read().decode("utf-8")
|
||||||
|
raw = raw.replace("## Table of Contents\n\n[TOC]\n\n", "")
|
||||||
|
md = Markdown(raw)
|
||||||
|
console = Console()
|
||||||
|
with console.pager(styles=True):
|
||||||
|
console.print(md)
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
"""
|
"""
|
||||||
Inits YASD CLI.
|
Inits YASD CLI.
|
||||||
|
@ -576,8 +599,7 @@ class YASDCLI:
|
||||||
self.__init_parser()
|
self.__init_parser()
|
||||||
args = self.parser.parse_args()
|
args = self.parser.parse_args()
|
||||||
if args.action == "man":
|
if args.action == "man":
|
||||||
# TODO print man from README
|
YASDCLI.print_man()
|
||||||
print("Manual")
|
|
||||||
else:
|
else:
|
||||||
YASD.do(
|
YASD.do(
|
||||||
args.action,
|
args.action,
|
||||||
|
@ -594,7 +616,7 @@ class YASDCLI:
|
||||||
"""
|
"""
|
||||||
msg = YASDMessenger.keys()
|
msg = YASDMessenger.keys()
|
||||||
self.parser = argparse.ArgumentParser(
|
self.parser = argparse.ArgumentParser(
|
||||||
prog="yasd",
|
prog=msg["prog"],
|
||||||
description=msg["description"],
|
description=msg["description"],
|
||||||
epilog=msg["epilog"],
|
epilog=msg["epilog"],
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue