summaryrefslogtreecommitdiff
path: root/src/pyssg/pyssg.py
diff options
context:
space:
mode:
authorDavid Luevano Alvarado <david@luevano.xyz>2022-04-17 19:39:38 -0600
committerDavid Luevano Alvarado <david@luevano.xyz>2022-04-17 19:39:38 -0600
commit6bec182703885761699f6d53bc9034933b03197e (patch)
tree489ceb8a2223a9e1067e0eabfd91a62d1c7ec051 /src/pyssg/pyssg.py
parentd2dfa337171fdad8ed48ce95e3b8f91e291423b7 (diff)
add initial logging capabilities
still need to add logging to rest of the program: builder, database, discovery, page, parser and rest of the pyssg (build part)
Diffstat (limited to 'src/pyssg/pyssg.py')
-rw-r--r--src/pyssg/pyssg.py26
1 files changed, 20 insertions, 6 deletions
diff --git a/src/pyssg/pyssg.py b/src/pyssg/pyssg.py
index 9b82231..958b397 100644
--- a/src/pyssg/pyssg.py
+++ b/src/pyssg/pyssg.py
@@ -1,5 +1,7 @@
import os
import sys
+import logging
+from logging import Logger, StreamHandler
from importlib.resources import path as rpath
from typing import Union
from configparser import ConfigParser
@@ -10,43 +12,53 @@ from yafg import YafgExtension
from MarkdownHighlight.highlight import HighlightExtension
from markdown_checklist.extension import ChecklistExtension
+from .per_level_formatter import PerLevelFormatter
from .utils import create_dir, copy_file, sanity_check_path
from .arg_parser import get_parsed_arguments
from .configuration import get_parsed_config, DEFAULT_CONFIG_PATH, VERSION
from .database import Database
from .builder import Builder
+log: Logger = logging.getLogger(__name__)
+
def main() -> None:
args: dict[str, Union[str, bool]] = vars(get_parsed_arguments())
+
if not len(sys.argv) > 1:
- print(f'pyssg v{VERSION} - no arguments passed, --help for more')
+ log.info('pyssg v%s - no arguments passed, --help for more', VERSION)
sys.exit(0)
if args['version']:
- print(f'pyssg v{VERSION}')
+ log.info('pyssg v%s', VERSION)
sys.exit(0)
+ log.debug('checking config file path')
config_path: str = args['config'] if args['config'] else DEFAULT_CONFIG_PATH
config_path = os.path.normpath(os.path.expandvars(config_path))
sanity_check_path(config_path)
config_dir, _ = os.path.split(config_path)
+ log.debug('checked config file path, final config path "%s"', config_path)
if args['copy_default_config']:
+ log.info('copying default config file')
create_dir(config_dir)
with rpath('pyssg.plt', 'default.ini') as p:
copy_file(p, config_path)
sys.exit(0)
if not os.path.exists(config_path):
- print(f'''config file does't exist in path "{config_path}"; make sure
- the path is correct; use --copy-default-config to if you
- haven't already''')
+ log.error('config file does\'t exist in path "%s"; make sure'
+ ' the path is correct; use --copy-default-config if it\'s the'
+ ' first time if you haven\'t already', config_path)
sys.exit(1)
+ log.debug('parsing config file')
config: ConfigParser = get_parsed_config(config_path)
+ log.debug('parsed config file')
if args['init']:
+ log.info('initializing the directory structure and copying over templates')
create_dir(config.get('path', 'src'))
create_dir(os.path.join(config.get('path', 'dst'), 'tag'), True)
create_dir(config.get('path', 'plt'))
@@ -55,12 +67,15 @@ def main() -> None:
'tag.html',
'rss.xml',
'sitemap.xml')
+ log.debug('list of files to copy over: (%s)', ', '.join(files))
for f in files:
plt_file: str = os.path.join(config.get('path', 'plt'), f)
with rpath('pyssg.plt', f) as p:
copy_file(p, plt_file)
sys.exit(0)
+ # TODO: add logging to all of the build part, that includes the builder,
+ # database, discovery, page and parser
if args['build']:
# start the db
db: Database = Database(os.path.join(config.get('path', 'src'), '.files'))
@@ -73,7 +88,6 @@ def main() -> None:
trim_blocks=True,
lstrip_blocks=True)
-
# md extensions
exts: list = ['extra',
'meta',