ctucx.git: gallery

static-site-generator for image-galleries [used @ photos.ctu.cx]

commit 923a2ebde3a0af5786e83568b85e79c6a78a382d
parent fe4bd7633a2a98789d0adcc864c4bad67541acc9
Author: Leah (ctucx) <leah@ctu.cx>
Date: Wed, 10 Mar 2021 20:25:52 +0100

src/galery.nim: improve config parsing; set sensible config-defaults
1 file changed, 26 insertions(+), 18 deletions(-)
M
src/gallery.nim
|
44
++++++++++++++++++++++++++------------------
diff --git a/src/gallery.nim b/src/gallery.nim
@@ -268,41 +268,49 @@ proc main =
     try:
         let configFile = loadConfig(paramStr(1))
         config     = %* {
-            "SourceDir":             normalizedPath(configFile.getSectionValue("", "SourceDir")),
-            "TargetDir":             normalizedPath(configFile.getSectionValue("", "TargetDir")),
-            "SiteName":              configFile.getSectionValue("Site",       "Name"),
-            "SiteAuthor":            configFile.getSectionValue("Site",       "Author"),
-            "SiteDescription":       configFile.getSectionValue("Site",       "Description"),
-            "SiteTags":              configFile.getSectionValue("Site",       "Tags"),
-            "SiteShowOrigBtn":       configFile.getSectionValue("Site",       "ShowOriginalsButton").parseBool,
-            "SiteSymlinkOrig":       configFile.getSectionValue("Site",       "SymlinkOriginals").parseBool,
-            "SiteEnableJS":          configFile.getSectionValue("Site",       "EnableJS").parseBool,
-            "ThumbMediumMaxWidth":   configFile.getSectionValue("Thumbnails", "MediumMaxWidth").parseInt,
-            "ThumbMediumMaxHeight":  configFile.getSectionValue("Thumbnails", "MediumMaxHeight").parseInt,
-            "ThumbThumbMaxWidth":    configFile.getSectionValue("Thumbnails", "ThumbMaxWidth").parseInt,
-            "ThumbThumbMaxHeight":   configFile.getSectionValue("Thumbnails", "ThumbMaxHeight").parseInt,
-            "ThumbThumbQuality":     configFile.getSectionValue("Thumbnails", "ThumbQuality").parseInt
+            "SourceDir":            normalizedPath(configFile.getSectionValue("", "SourceDir",           "")),
+            "TargetDir":            normalizedPath(configFile.getSectionValue("", "TargetDir",           "")),
+            "SiteName":             configFile.getSectionValue("Site",            "Name",                "default title - change me plese"),
+            "SiteAuthor":           configFile.getSectionValue("Site",            "Author",              "Max Mustermann"),
+            "SiteTags":             configFile.getSectionValue("Site",            "Tags",                ""),
+            "SiteDescription":      configFile.getSectionValue("Site",            "Description",         ""),
+            "SiteShowOrigBtn":      configFile.getSectionValue("Site",            "ShowOriginalsButton", "true").parseBool,
+            "SiteSymlinkOrig":      configFile.getSectionValue("Site",            "SymlinkOriginals",    "true").parseBool,
+            "SiteEnableJS":         configFile.getSectionValue("Site",            "EnableJS",            "true").parseBool,
+            "ThumbMediumMaxWidth":  configFile.getSectionValue("Thumbnails",      "MediumMaxWidth",      "1920").parseInt,
+            "ThumbMediumMaxHeight": configFile.getSectionValue("Thumbnails",      "MediumMaxHeight",     "1080").parseInt,
+            "ThumbThumbMaxWidth":   configFile.getSectionValue("Thumbnails",      "ThumbMaxWidth",       "200").parseInt,
+            "ThumbThumbMaxHeight":  configFile.getSectionValue("Thumbnails",      "ThumbMaxHeight",      "200").parseInt,
+            "ThumbThumbQuality":    configFile.getSectionValue("Thumbnails",      "ThumbQuality",        "90").parseInt
         }
 
+        if config["SourceDir"].getStr == "":
+            echo "Config-value 'SourceDir' has to be set!"
+            quit(QuitFailure)
+
+        if config["TargetDir"].getStr == "":
+            echo "Config-value 'TargetDir' has to be set!"
+            quit(QuitFailure)
+
     except ValueError:
         let
          e = getCurrentException()
          msg = getCurrentExceptionMsg()
 
         echo "Got exception while parsing config: ", repr(e), " with message ", msg        
-        quit()
+        quit(QuitFailure)
 
     except:
         echo "Unknown exception while parsing of configuration!"
-        quit()
+        quit(QuitFailure)
 
     if not dirExists(config["SourceDir"].getStr):
         echo "The source directory does not exist!\nBye!"
-        quit()
+        quit(QuitFailure)
 
     if not dirExists(config["TargetDir"].getStr):
         echo "The target directory does not exist!\nBye!"
-        quit()
+        quit(QuitFailure)
 
   
     let mainAlbum = createAlbum(config["SourceDir"].getStr, true)