aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoruser <user@node5.net>2024-01-24 18:11:01 +0100
committeruser <user@node5.net>2024-01-24 18:11:01 +0100
commit1808d04bfa723f8aa28c1197281ffca7387d6ea4 (patch)
treef5a216bb65412e29a9b4cdbe0afb3bc802225f92
parent920784f1107ad5770f6525a1e39315238581bb1f (diff)
Revert "fix source directory not found handling"
This reverts commit 920784f1107ad5770f6525a1e39315238581bb1f.
-rwxr-xr-xblog_generator.py43
1 files changed, 20 insertions, 23 deletions
diff --git a/blog_generator.py b/blog_generator.py
index ab65429..b1ffb86 100755
--- a/blog_generator.py
+++ b/blog_generator.py
@@ -8,10 +8,10 @@ import dataclasses # Shorthand data classes
import datetime # Created, modified date
import jinja2 # HTML Templates
import shutil # Copy files and directories
+import time # Sleep
import livereload # Generate on content source file change and reload browser
import datetime # Read article dates metadata
import argparse # Command line arguments
-import logger # Custom format
logging.basicConfig()
logger = logging.getLogger('blog_generator')
@@ -185,36 +185,33 @@ def main():
help='the directory containing the site source files, defaults to current working directory')
# Parse arguments
args = parser.parse_args()
-
- try:
- paths['source_content_root'] = args.directory
- if not os.path.exists(paths['source_content_root']):
- raise SourceDirectoryNotFoundException(f'Source directory not found: {paths["source_content_root"]}')
- if os.path.isdir(paths['source_content_root']):
- for directory in ['articles', 'templates', 'static']:
- path = os.path.join(paths['source_content_root'], directory)
- if not os.path.exists(path):
- raise SourceDirectoryNotFoundException(f'Source directory not found: {path}')
- paths[directory] = path
- paths['output'] = os.path.join(paths['source_content_root'], 'output')
+ paths['source_content_root'] = args.directory
+ if not os.path.exists(paths['source_content_root']):
+ raise SourceDirectoryNotFoundException(f'Source directory not found: {paths["source_content_root"]}')
+
+ if os.path.isdir(paths['source_content_root']):
+ for directory in ['articles', 'templates', 'static']:
+ path = os.path.join(paths['source_content_root'], directory)
+ if not os.path.exists(path):
+ raise SourceDirectoryNotFoundException(f'Source directory not found: {path}')
+ paths[directory] = path
+ paths['output'] = os.path.join(paths['source_content_root'], 'output')
- # Setup jinja enviroment
- # Dict values globally accesible in templates e.g. root title
- # Get name of directory, in case it's relative
- jinja_global = {'title': os.path.basename(os.path.realpath(args.directory))}
- jinja_env = jinja2.Environment(loader=jinja2.FileSystemLoader(paths['templates']))
- jinja_env.globals.update(jinja_global)
-
+ # Setup jinja enviroment
+ # Dict values globally accesible in templates e.g. root title
+ # Get name of directory, in case it's relative
+ jinja_global = {'title': os.path.basename(os.path.realpath(args.directory))}
+ jinja_env = jinja2.Environment(loader=jinja2.FileSystemLoader(paths['templates']))
+ jinja_env.globals.update(jinja_global)
+
+ try:
match args.action: # Switch statement
case 'generate':
generate_all(jinja_env, paths)
case 'live_reload':
live_reload(jinja_env, paths)
# Known custom error, avoid stack trace, merely print the pretty exception message
- except SourceDirectoryNotFoundException as exception:
- logger.error(f'{exception}\n')
- parser.print_help()
except BlogGeneratorException as exception:
logger.error(exception)
exit(1) # Exit code 1: Code for generic errors