NEW: external .ini configuration file
Allows for changing the configuration without rebuilding the whole project
This commit is contained in:
parent
7396f3b639
commit
5516835fb8
|
@ -1,3 +1,4 @@
|
|||
*.o
|
||||
*.hi
|
||||
dist-*
|
||||
mia.ini
|
||||
|
|
|
@ -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
|
||||
|
|
32
Config.hs
32
Config.hs
|
@ -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
3
Git.hs
|
@ -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 }
|
||||
|
|
|
@ -36,6 +36,7 @@ executable mia
|
|||
directory,
|
||||
optparse-applicative,
|
||||
string-random,
|
||||
text
|
||||
text,
|
||||
ini
|
||||
hs-source-dirs: .
|
||||
default-language: Haskell2010
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
[GENERAL]
|
||||
archivePath = /home/myuser/Images/Archive
|
||||
mainBranch = main
|
||||
importBranch = import/
|
||||
initialCommit = a29e769623a6b4a1ad2f9e6f73dc4bf4b6640f06
|
||||
|
Loading…
Reference in New Issue