NEW: external .ini configuration file

Allows for changing the configuration without rebuilding the whole
project
This commit is contained in:
Jean-Claude 2021-07-13 16:22:10 +02:00
parent 7396f3b639
commit 5516835fb8
Signed by: jeanclaude
GPG Key ID: 8A300F57CBB9F63E
6 changed files with 49 additions and 13 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
*.o
*.hi
dist-*
mia.ini

View File

@ -25,7 +25,8 @@ runImport (ImportActivate name) = do
-- deactivate
runImport (ImportDeactivate True) = do
_ <- Git.runGit ["checkout", Conf.mainBranch]
mainBranch <- Conf.mainBranch
_ <- Git.runGit ["checkout", mainBranch]
return ()
-- list
@ -48,23 +49,27 @@ runImport (ImportImages paths@(x:xs) opts) = do
else do -- TODO get rid of else
-- Prepare branch
Git.checkoutBranch Conf.mainBranch []
mainBranch <- Conf.mainBranch
Git.checkoutBranch mainBranch []
initialCommit <- Conf.initialCommit
identifier <- stringRandomIO (pack "[0-9a-zA-Z]{10}")
Git.checkoutBranch ("TEST-" ++ (unpack identifier) ++ "-" ++ importImagesIdentifier opts) [Conf.initialCommit]
Git.checkoutBranch ("TEST-" ++ (unpack identifier) ++ "-" ++ importImagesIdentifier opts) [initialCommit]
archivePath <- Conf.archivePath
-- Copy images to right place
forM_ paths $ \path -> do
putStrLn $ "Importing " ++ path
out <- runProcess $ createProcess(proc "exiftool" ["-o", ".", "-FileName<CreateDate", "-d", "%Y/%y%m%d-" ++ importImagesIdentifier opts ++ "/%y%m%d_%H%M%S%%-c.%%le", "-r", path]){ cwd = Just Conf.archivePath }
out <- runProcess $ createProcess(proc "exiftool" ["-o", ".", "-FileName<CreateDate", "-d", "%Y/%y%m%d-" ++ importImagesIdentifier opts ++ "/%y%m%d_%H%M%S%%-c.%%le", "-r", path]){ cwd = Just archivePath }
putStrLn out
return ()
putStrLn "asdfadfs"
-- Add images to git annex
out <- runProcess $ createProcess(proc "git-annex" ["add", "."]){ cwd = Just Conf.archivePath }
out <- runProcess $ createProcess(proc "git-annex" ["add", "."]){ cwd = Just archivePath }
putStrLn out
out <- runProcess $ createProcess(proc "git" ["commit", "-m", "INITIAL IMPORT: " ++ show (length paths) ++ " images"]){ cwd = Just Conf.archivePath }
out <- runProcess $ createProcess(proc "git" ["commit", "-m", "INITIAL IMPORT: " ++ show (length paths) ++ " images"]){ cwd = Just archivePath }
putStrLn out
-- Verify and cleanup

View File

@ -1,7 +1,29 @@
module Config where
progName = "myProg"
archivePath = "/home/jeanclaude/Images/ArchiveTest"
mainBranch = "main"
importBranch = "import/"
initialCommit = "a29e769623a6b4a1ad2f9e6f73dc4bf4b6640f06"
import Data.Ini
import Data.Text
getOption :: String -> String -> IO String
getOption group option = do
config <- readIniFile "mia.ini"
case config of
Right ini -> do
let p = lookupValue (pack group) (pack option) ini
return $ case p of
Left s -> s
Right t -> unpack t
Left s -> do
putStrLn s
return ""
archivePath :: IO String
archivePath = getOption "GENERAL" "archivePath"
mainBranch :: IO String
mainBranch = getOption "GENERAL" "mainBranch"
importBranch :: IO String
importBranch = getOption "GENERAL" "importBranch"
initialCommit :: IO String
initialCommit = getOption "GENERAL" "initialCommit"

3
Git.hs
View File

@ -1,6 +1,6 @@
module Git where
import Config
import qualified Config as Conf
import qualified Helper as H
import System.Exit
@ -11,6 +11,7 @@ type Branch = String
runGit :: [String] -> IO String
runGit args = do
archivePath <- Conf.archivePath
H.runProcess $ createProcess(proc "git" args){ cwd = Just archivePath , std_out = CreatePipe }
-- r <- createProcess(proc "git" args){ cwd = Just archivePath }

View File

@ -36,6 +36,7 @@ executable mia
directory,
optparse-applicative,
string-random,
text
text,
ini
hs-source-dirs: .
default-language: Haskell2010

6
mia.ini_example Normal file
View File

@ -0,0 +1,6 @@
[GENERAL]
archivePath = /home/myuser/Images/Archive
mainBranch = main
importBranch = import/
initialCommit = a29e769623a6b4a1ad2f9e6f73dc4bf4b6640f06