diff --git a/docs/refman/generatorpickle.py b/docs/refman/generatorpickle.py new file mode 100644 index 000000000..364a9886d --- /dev/null +++ b/docs/refman/generatorpickle.py @@ -0,0 +1,26 @@ +# Copyright 2021 The Meson development team + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import pickle +from pathlib import Path +from .generatorbase import GeneratorBase +from .model import ReferenceManual + +class GeneratorPickle(GeneratorBase): + def __init__(self, manual: ReferenceManual, outpath: Path) -> None: + self.out = outpath + super().__init__(manual) + + def generate(self) -> None: + self.out.write_bytes(pickle.dumps(self.manual)) diff --git a/docs/refman/main.py b/docs/refman/main.py index 96698ae9e..34f2a3efd 100644 --- a/docs/refman/main.py +++ b/docs/refman/main.py @@ -23,13 +23,15 @@ from .loaderyaml import LoaderYAML from .generatorbase import GeneratorBase from .generatorprint import GeneratorPrint +from .generatorpickle import GeneratorPickle meson_root = Path(__file__).absolute().parents[2] def main() -> int: parser = argparse.ArgumentParser(description='Meson reference manual generator') parser.add_argument('-l', '--loader', type=str, default='yaml', choices=['yaml'], help='Information loader backend') - parser.add_argument('-g', '--generator', type=str, choices=['print'], required=True, help='Generator backend') + parser.add_argument('-g', '--generator', type=str, choices=['print', 'pickle', 'md'], required=True, help='Generator backend') + parser.add_argument('-o', '--out', type=Path, required=True, help='Output directory for generated files') parser.add_argument('--depfile', type=Path, default=None, help='Set to generate a depfile') parser.add_argument('--force-color', action='store_true', help='Force enable colors') args = parser.parse_args() @@ -46,6 +48,7 @@ def main() -> int: generators: T.Dict[str, T.Callable[[], GeneratorBase]] = { 'print': lambda: GeneratorPrint(refMan), + 'pickle': lambda: GeneratorPickle(refMan, args.out), } generator = generators[args.generator]()