Skip to content
Snippets Groups Projects
Commit 8e6e230a authored by Hugo Hörnquist's avatar Hugo Hörnquist
Browse files

Set up logging.

parent b1494d78
Branches
No related tags found
No related merge requests found
......@@ -3,12 +3,26 @@
import argparse
import pathlib
import os
import logging
import colorlog
from .cache import Cache
from .gather import get_module, get_modules, ModuleEntry
from .output import setup_index, setup_module
logger = logging.getLogger('muppet')
logger.setLevel(logging.DEBUG)
ch = colorlog.StreamHandler()
ch.setLevel(logging.INFO)
# formatter = logging.Formatter('%(name)s - %(levelname)s - %(message)s')
formatter = colorlog.ColoredFormatter('%(log_color)s%(name)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)
logger.addHandler(ch)
def __main() -> None:
parser = argparse.ArgumentParser(
prog='puppet-doc configure',
......@@ -45,6 +59,7 @@ def __main() -> None:
for module in modules:
# print(module)
logger.info('Handling %s', module.name)
setup_module('output', module, path_base=args.path_base)
os.system('make -C static-src --silent install-full PREFIX=$PWD/output')
......
......@@ -33,6 +33,7 @@ from .puppet.strings import (
DataTypeAlias,
PuppetClass,
)
import logging
from .breadcrumbs import breadcrumbs
from .syntax_highlight import highlight
......@@ -40,6 +41,9 @@ from dataclasses import dataclass, field
from . import templates
logger = logging.getLogger(__name__)
# TODO replace 'output' with base, or put this somewhere else
pathlib.Path('output').mkdir(exist_ok=True)
jinja = Environment(
......@@ -496,6 +500,7 @@ def setup_module(base: str, module: ModuleEntry, *, path_base: str) -> None:
data = module.strings_output
for puppet_class in data.puppet_classes + data.defined_types:
logger.debug('Formamting %s', puppet_class.name)
# localpath = puppet_class['name'].split('::')
localpath, _ = os.path.splitext(puppet_class.file)
dir = os.path.join(path, localpath)
......@@ -552,6 +557,8 @@ def setup_module(base: str, module: ModuleEntry, *, path_base: str) -> None:
# puppet_class['line']
for type_alias in data.data_type_aliases:
logger.debug('Formamting %s', type_alias.name)
localpath, _ = os.path.splitext(type_alias.file)
dir = os.path.join(path, localpath)
pathlib.Path(dir).mkdir(parents=True, exist_ok=True)
......@@ -576,6 +583,8 @@ def setup_module(base: str, module: ModuleEntry, *, path_base: str) -> None:
files: dict[str, str] = {}
for file in module.doc_files:
logger.debug('Formamting %s', file)
basename = os.path.basename(file)
if basename == 'REFERENCE.md':
with open(file) as f:
......@@ -588,6 +597,8 @@ def setup_module(base: str, module: ModuleEntry, *, path_base: str) -> None:
doc_files: dict[str, str] = {}
for filename, filepath in files.items():
logger.debug('Formamting %s', filename)
name, _ = os.path.splitext(filename)
with open(filepath) as f:
raw_content = f.read()
......
......@@ -11,6 +11,10 @@ import json
from typing import Any, TypeAlias, Union
from ..cache import Cache
import logging
logger = logging.getLogger(__name__)
# TODO cache path
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment