summaryrefslogtreecommitdiff
path: root/src/pyssg/configuration.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/pyssg/configuration.py')
-rw-r--r--src/pyssg/configuration.py53
1 files changed, 36 insertions, 17 deletions
diff --git a/src/pyssg/configuration.py b/src/pyssg/configuration.py
index dca43b5..e07f452 100644
--- a/src/pyssg/configuration.py
+++ b/src/pyssg/configuration.py
@@ -1,21 +1,33 @@
import os
from typing import Union
+from importlib.metadata import version
+from datetime import datetime, timezone
class Configuration:
def __init__(self, path: str):
self.path: str = path
+ # config file specific
self.src: str = None
self.dst: str = None
self.plt: str = None
- self.base_url: str = None
- self.base_static_url: str = None
+ self.url: str = None
+ self.static_url: str = None
+ self.default_image_url: str = None
self.title: str = None
self.dformat: str = None
self.l_dformat: str = None
self.lsep_dformat: str = None
self.force: bool = None
+ # other
+ self.version: str = version('pyssg')
+ self.dformat_rss: str = '%a, %d %b %Y %H:%M:%S GMT'
+ self.dformat_sitemap: str = '%Y-%m-%d'
+ self.run_date_rss = datetime.now(tz=timezone.utc).strftime(self.dformat_rss)
+ self.run_date_sitemap = \
+ datetime.now(tz=timezone.utc).strftime(self.dformat_sitemap)
+
def read(self):
try:
@@ -29,7 +41,7 @@ class Configuration:
if len(kv) != 2:
raise Exception('wrong config syntax')
- k: str = kv[0].strip()
+ k: str = kv[0].strip().lower()
v_temp: str = kv[1].strip()
# check if value should be a boolean true
v: Union[str, bool] = v_temp\
@@ -39,45 +51,49 @@ class Configuration:
opts[k] = v
try:
- self.src = opts['SRC_PATH']
+ self.src = opts['src']
except KeyError: pass
try:
- self.dst = opts['DST_PATH']
+ self.dst = opts['dst']
except KeyError: pass
try:
- self.plt = opts['PLT_PATH']
+ self.plt = opts['plt']
except KeyError: pass
try:
- self.base_url = opts['BASE_URL']
+ self.url = opts['url']
except KeyError: pass
try:
- self.base_static_url = opts['BASE_STATIC_URL']
+ self.static_url = opts['static_url']
except KeyError: pass
try:
- self.title = opts['TITLE']
+ self.default_image_url = opts['default_image_url']
except KeyError: pass
try:
- self.dformat = opts['DATE_FORMAT']
+ self.title = opts['title']
except KeyError: pass
try:
- self.l_dformat = opts['LIST_DATE_FORMAT']
+ self.dformat = opts['date_formaT']
except KeyError: pass
try:
- self.lsep_dformat = opts['LIST_SEP_DATE_FORMAT']
+ self.l_dformat = opts['list_date_FORMAT']
+ except KeyError: pass
+
+ try:
+ self.lsep_dformat = opts['list_sep_dATE_FORMAT']
except KeyError: pass
try:
# if the parser above didn't read a boolean true, then take it
# as a false anyways
- self.force = opts['FORCE'] if opts['FORCE'] is True else False
+ self.force = opts['force'] if opts['force'] is True else False
except KeyError: pass
except OSError: pass
@@ -93,11 +109,14 @@ class Configuration:
if self.plt is None:
self.plt = opts['plt']
- if self.base_url is None:
- self.base_url = opts['url']
+ if self.url is None:
+ self.url = opts['url']
+
+ if self.static_url is None:
+ self.static_url = opts['static_url']
- if self.base_static_url is None:
- self.base_static_url = opts['static_url']
+ if self.default_image_url is None:
+ self.default_image_url = opts['default_image_url']
if self.title is None:
self.title = opts['title']