-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathprocessor.py
More file actions
executable file
·95 lines (71 loc) · 2.21 KB
/
processor.py
File metadata and controls
executable file
·95 lines (71 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env python3
from dataclasses import dataclass, field
from pathlib import Path
import click
from mashumaro.mixins.yaml import DataClassYAMLMixin
@dataclass
class Base(DataClassYAMLMixin):
pass
@dataclass(kw_only=True)
class Template(Base):
name: str
entries: list[str]
csl_type: str = ""
csl_vals: list[str] = field(default_factory=list)
blx_driver: str = ""
blx_vals: list[str] = field(default_factory=list)
bst_driver: str = ""
bst_vals: list[str] = field(default_factory=list)
@dataclass(kw_only=True)
class Value(Base):
val: str
raw_csl: str = ""
raw_blx: str = ""
raw_bst: str = ""
@dataclass(kw_only=True)
class Group(Base):
prefix: str | None = None
delim: str | None = None
suffix: str | None = None
do: "list[str | Choice | Group | Value]" = field(default_factory=list)
"""String values should be Macro IDs."""
@dataclass(kw_only=True)
class Filter(Base):
only: list[str] = field(default_factory=list)
"""String values should be Template names."""
do: "list[str | Choice | Group | Value]" = field(default_factory=list)
"""String values should be Macro IDs."""
@dataclass(kw_only=True)
class Choice(Base):
choose: list[Filter]
@dataclass(kw_only=True)
class Macro(Base):
id: str
id_csl: str = ""
id_blx: str = ""
id_bst: str = ""
do: list[str | Choice | Group | Value] = field(default_factory=list)
"""String values should be Macro IDs."""
@dataclass(kw_only=True)
class Model(Base):
templates: list[Template] = field(default_factory=list)
root: list[str | Choice | Group | Value] = field(default_factory=list)
"""String values should be Macro IDs."""
macros: list[Macro] = field(default_factory=list)
@click.group()
@click.pass_context
def main(ctx: click.Context):
"""Uses metamodel to generate various views suited for
CSL, biblatex and BibTeX."""
this_file = Path(__file__)
dir_src = this_file.parent
fp_model = dir_src / "metamodel.yaml"
with fp_model.open() as f:
model = Model.from_yaml(f.read())
ctx.obj = model
click.echo(f"Loaded {len(model.templates)} templates.")
@main.command()
def test():
pass
if __name__ == "__main__":
main()