Ya imprime manual
This commit is contained in:
parent
fdd44d72ff
commit
adc543e608
22
README.md
22
README.md
|
@ -1,7 +1,3 @@
|
|||
---
|
||||
warn: This is just a prototype.
|
||||
---
|
||||
|
||||
# YASD, Yet Another Schema Definition
|
||||
|
||||
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].
|
||||
- Output: computer processable schema in [XSD].
|
||||
- Output: human readable documentation in [reStructuredText][RST].
|
||||
- Output: human readable documentation in [reStructuredText].
|
||||
|
||||
## Table of Contents
|
||||
|
||||
|
@ -178,15 +174,17 @@ Allowed types:
|
|||
|
||||
Chart:
|
||||
|
||||
| type | children elements | children text node | attributes |
|
||||
|------------|:-----------------:|:------------------:|:----------:|
|
||||
| type | elements | text | attributes |
|
||||
|------------|:--------:|:----:|:----------:|
|
||||
|simple | ✗ | ✓ | ✗ |
|
||||
|empty | ✗ | ✗ | ✓ |
|
||||
|no_text | ✓ | ✗ | ✓ |
|
||||
|no_elements | ✗ | ✓ | ✓ |
|
||||
|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`
|
||||
|
||||
|
@ -396,13 +394,13 @@ Mandatory.
|
|||
|
||||
## References
|
||||
|
||||
* “XML Schema Reference”, [W3ref]
|
||||
* “XML Schema Tutorial”, [W3Schools].
|
||||
* “XSD Tutorial”, [Tutorials Point].
|
||||
- "XML Schema Reference", [W3ref]
|
||||
- "XML Schema Tutorial", [W3Schools].
|
||||
- "XSD Tutorial", [Tutorials Point].
|
||||
|
||||
[YASD]: https://gitlab.com/amlengua/apal/esquema/-/blob/main/apal.yaml
|
||||
[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
|
||||
[W3Schools]: https://www.w3schools.com/xml/schema_intro.asp
|
||||
[Tutorials Point]: https://www.tutorialspoint.com/xsd/
|
||||
|
|
48
yasd.py
48
yasd.py
|
@ -2,13 +2,17 @@
|
|||
# (c) 2023 Perro Tuerto <hi@perrotuerto.blog>.
|
||||
# Founded by Mexican Academy of Language <https://academia.org.mx>.
|
||||
# Licensed under GPLv3 <https://www.gnu.org/licenses/gpl-3.0.en.html>.
|
||||
# Requirements: python > 3.10, pyyaml, lxml, bs4, rich
|
||||
|
||||
import sys
|
||||
import yaml
|
||||
import argparse
|
||||
import urllib.request
|
||||
from pathlib import Path
|
||||
from bs4 import BeautifulSoup
|
||||
from bs4.formatter import XMLFormatter
|
||||
from rich.console import Console
|
||||
from rich.markdown import Markdown
|
||||
|
||||
|
||||
class YASD:
|
||||
|
@ -72,10 +76,13 @@ class YASD:
|
|||
:type log: True or False
|
||||
"""
|
||||
self.msgr = YASDMessenger(quiet=quiet, log=log)
|
||||
self.outfile = YASDCheck.file(outfile, self.msgr)
|
||||
self.yaml = YASDCheck(indata, self.msgr).yaml
|
||||
self.formatter = XMLFormatter(indent=2)
|
||||
self.stdout = stdout
|
||||
if outfile is None:
|
||||
self.outfile = None
|
||||
else:
|
||||
self.outfile = YASDCheck.file(outfile, self.msgr)
|
||||
|
||||
def convert(self):
|
||||
"""
|
||||
|
@ -483,6 +490,7 @@ class YASDMessenger:
|
|||
"""
|
||||
# TODO internationalization with: https://github.com/sectasy0/pyi18n
|
||||
return {
|
||||
"prog": "yasd",
|
||||
"description": """
|
||||
YASD, Yet Another Schema Definition. YASD is a YAML format for
|
||||
human writable XSDs (XML Schema Definition), humans declare what is
|
||||
|
@ -499,15 +507,15 @@ class YASDMessenger:
|
|||
"help_output": "output file",
|
||||
"help_quiet": "enable quiet mode",
|
||||
"help_log": "write log",
|
||||
"action_convert": "Creating XSD schema",
|
||||
"action_check": "Checking YASD",
|
||||
"action_sample": "Creating XML sample",
|
||||
"action_document": "Creating RST documentation",
|
||||
"invalid_level": "Invalid log level '@lvl'",
|
||||
"invalid_input": "Invalid file '@file'",
|
||||
"invalid_yaml": "Invalid YAML structure",
|
||||
"action_convert": "creating XSD schema",
|
||||
"action_check": "checking YASD",
|
||||
"action_sample": "creating XML sample",
|
||||
"action_document": "creating RST documentation",
|
||||
"invalid_level": "invalid log level '@lvl'",
|
||||
"invalid_input": "invalid file '@file'",
|
||||
"invalid_yaml": "invalid YAML structure",
|
||||
"no_yaml": "YAML dict needed",
|
||||
"no_input": "Input file needed.",
|
||||
"no_input": "input file needed",
|
||||
}
|
||||
|
||||
def __init__(self, quiet=False, log=False):
|
||||
|
@ -527,8 +535,9 @@ class YASDMessenger:
|
|||
:param str level: Log level; 'info' by default
|
||||
"""
|
||||
self.__check_level(level)
|
||||
name = YASDMessenger.keys()["prog"]
|
||||
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
|
||||
print(msg)
|
||||
if level in ["error", "fatal"]:
|
||||
|
@ -569,6 +578,20 @@ class YASDCLI:
|
|||
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):
|
||||
"""
|
||||
Inits YASD CLI.
|
||||
|
@ -576,8 +599,7 @@ class YASDCLI:
|
|||
self.__init_parser()
|
||||
args = self.parser.parse_args()
|
||||
if args.action == "man":
|
||||
# TODO print man from README
|
||||
print("Manual")
|
||||
YASDCLI.print_man()
|
||||
else:
|
||||
YASD.do(
|
||||
args.action,
|
||||
|
@ -594,7 +616,7 @@ class YASDCLI:
|
|||
"""
|
||||
msg = YASDMessenger.keys()
|
||||
self.parser = argparse.ArgumentParser(
|
||||
prog="yasd",
|
||||
prog=msg["prog"],
|
||||
description=msg["description"],
|
||||
epilog=msg["epilog"],
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue