added ability to set binary locations for restic or borg
This commit is contained in:
parent
a57127fcff
commit
e5ad7ed1d4
6 changed files with 40 additions and 4 deletions
|
@ -5,6 +5,7 @@ import ../model/command_type
|
|||
import ../utils/run
|
||||
export run
|
||||
|
||||
|
||||
proc genCommand*(cmd: string, repo: string, further_args: seq[string]): string =
|
||||
let args = further_args.join(" ")
|
||||
let cmd = fmt"{BORG_BIN} {cmd} {repo} {args}"
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
import parsetoml
|
||||
|
||||
import ../model/config_type
|
||||
import ../model/command_type
|
||||
import ../model/encryption_type
|
||||
import notifier_config
|
||||
import actions_config
|
||||
import maintenance_config
|
||||
|
||||
export config_type
|
||||
|
||||
proc parseSourceDirectories*(in_conf: TomlValueRef): seq[string] =
|
||||
|
@ -34,6 +36,16 @@ proc parseEncryption*(enc_conf: TomlValueRef) =
|
|||
setEncryptionPassphraseFile(enc_conf{"encryption_passphrase_file"}.getStr(""))
|
||||
setEncryptionPassCommand(enc_conf{"encryption_passcommand"}.getStr(""))
|
||||
|
||||
proc addConfigBinaries*(current: var Binaries, bin_conf: TomlValueRef) =
|
||||
let
|
||||
borg = bin_conf{"borg_bin"}.getStr()
|
||||
restic = bin_conf{"restic_bin"}.getStr()
|
||||
if borg != "":
|
||||
current.borg.insert(borg,0)
|
||||
if restic != "":
|
||||
current.restic.insert(restic,0)
|
||||
|
||||
|
||||
proc parseConfigFile*(file: string): NorgConfig =
|
||||
let in_conf = parsetoml.parseFile(file)
|
||||
norg_config.source_directories = parseSourceDirectories(in_conf)
|
||||
|
@ -45,6 +57,8 @@ proc parseConfigFile*(file: string): NorgConfig =
|
|||
norg_config.notifiers = parseNotifiers(in_conf)
|
||||
norg_config.actions = parseActions(in_conf{"actions"})
|
||||
norg_config.maintenance = parseMaintenance(in_conf{"maintenance"})
|
||||
norg_config.bins.addConfigBinaries(in_conf{"binaries"})
|
||||
norg_config.bins.setBinaryLocations()
|
||||
return norg_config
|
||||
|
||||
|
||||
|
|
11
norg/model/binary_type.nim
Normal file
11
norg/model/binary_type.nim
Normal file
|
@ -0,0 +1,11 @@
|
|||
|
||||
type
|
||||
Binaries* = object
|
||||
borg*: seq[string]
|
||||
restic*: seq[string]
|
||||
|
||||
proc newBinaries*(): Binaries =
|
||||
var
|
||||
borgs: seq[string] = @["borg","/usr/local/bin/borg","/usr/bin/borg","borg.exe"]
|
||||
restics: seq[string] = @["restic","/usr/local/bin/restic","/usr/bin/restic","restic.exe"]
|
||||
return Binaries(borg: borgs, restic: restics)
|
|
@ -1,5 +1,5 @@
|
|||
const BORG_BIN* = "borg"
|
||||
const RESTIC_BIN* = "restic"
|
||||
import ../model/binary_type
|
||||
import os
|
||||
|
||||
type
|
||||
Command* = enum
|
||||
|
@ -14,6 +14,14 @@ type
|
|||
CHECK = "check",
|
||||
COMPACT = "compact"
|
||||
|
||||
var BORG_BIN* = "borg"
|
||||
var RESTIC_BIN* = "restic"
|
||||
|
||||
proc setBinaryLocations*(b: Binaries) =
|
||||
for borg in b.borg:
|
||||
if fileExists(borg): BORG_BIN = borg
|
||||
for restic in b.restic:
|
||||
if fileExists(restic): RESTIC_BIN = restic
|
||||
proc toCommand*(str: string): Command =
|
||||
for cmd in Command.items:
|
||||
if str == $cmd: return cmd
|
||||
|
|
|
@ -2,12 +2,14 @@ import repository_type
|
|||
import notifier_types
|
||||
import actions_type
|
||||
import maintenance_type
|
||||
import binary_type
|
||||
import ../config/args
|
||||
|
||||
export repository_type
|
||||
export notifier_types
|
||||
export actions_type
|
||||
export maintenance_type
|
||||
export binary_type
|
||||
|
||||
|
||||
type
|
||||
|
@ -20,11 +22,12 @@ type
|
|||
notifiers*: Notifiers
|
||||
actions*: Actions
|
||||
args*: NorgArgs
|
||||
|
||||
bins*: Binaries
|
||||
|
||||
proc newNorgConfig*(): NorgConfig =
|
||||
var nc = NorgConfig()
|
||||
nc.maintenance = newMaintenance()
|
||||
nc.bins = newBinaries()
|
||||
return nc
|
||||
|
||||
var norg_config*: NorgConfig = newNorgConfig()
|
||||
|
|
|
@ -3,7 +3,6 @@ import osproc
|
|||
|
||||
import ../model/maintenance_type
|
||||
|
||||
|
||||
proc run*(cmd: string): int =
|
||||
echo fmt"Trying to run : {cmd}"
|
||||
try:
|
||||
|
|
Loading…
Reference in a new issue