@ -4,28 +4,71 @@ EZ-Bkup is released under the General Public License 3.0.
See COPYING or < https : / / www . gnu . org / licenses / > for details . ] #
See COPYING or < https : / / www . gnu . org / licenses / > for details . ] #
import owlkettle
import owlkettle
import std / osproc , std / os
import std / osproc , std / os , std / logging
#import asynctools
#import threadpool
import edit_routine_dialog
import edit_routine_dialog
import " ../models/routine " , " ../shared "
import " ../models/routine " , " ../shared "
viewable RoutineList :
viewable RoutineList :
## Displays a list of routines
routineModel : RoutineModel
routineModel : RoutineModel ## Model of all routines
runStatus : string
runStatus : string
rsyncRun : tuple [ output : string , exitCode : int ]
proc changed ( state : bool )
proc changed ( state : bool )
var thread : Thread [ RoutineListState ]
var thread : Thread [ RoutineListState ]
#var rsyncRun: tuple[output: string, exitCode: int]
proc rsyncThread ( list : RoutineListState , rsyncCommand : string ) {. thread . } =
proc rsyncThread ( list : RoutineListState ) {. thread . } =
while true :
list . rsyncRun = execCmdEx ( rsyncCommand )
let appPath = getHomeDir ( ) & " .ez-bkup "
if not dirExists ( appPath ) :
createDir ( appPath )
var logger = newFileLogger ( appPath & " /errors.log " )
#i'm not sure if using threadvar here is needed, but doing it just in case. :)
var rsyncRunCmd {. threadvar . } : string
var rsyncRun {. threadvar . } : tuple [ output : string , exitCode : int ]
var rsyncErrors : seq [ string ]
var routineRunCount : int
routineRunCount = 0
for routine in list . routineModel . routineSeq ( ) :
#using this as "selected" for now.
if routine . selByDef = = true :
#skip routines that don't have at least one source and one destination.
if routine . sources . len ! = 0 and routine . destinations . len ! = 0 :
list . runStatus = " <span color= \" #FFE97B \" size= \" large \" >Horses, please to be holding...</span> "
routineRuncount + = 1
for source in routine . sources :
for destination in routine . destinations :
#per source/dest compbo msgs still don't seem to be working right.
#maybe it requires a separate thread per combo? deprioritized.
#list.runStatus = "<span color=\"#FFE97B\" size=\"large\">Bkup " & source & " to " & destination & "...</span>"
#try without requiring superuser privs by default.
rsyncRunCmd = " rsync -aq " & source & " " & destination
rsyncRun = execCmdEx ( rsyncRunCmd )
if rsyncRun . exitCode ! = 0 :
#handle permission denied error.
if rsyncRun . exitCode = = 23 :
rsyncRun . exitCode = 0
if getAskPassPath ( ) = = " " :
let err = " No ssh-askpass binary found. Please install an ssh-askpass package for your distro, and let us know if EZ-Bkup still can ' t detect it ' s location. "
rsyncErrors . add ( err )
else :
rsyncRunCmd = " SUDO_ASKPASS= " & getAskPassPath ( ) & " sudo -A rsync -aq " & source & " " & destination
rsyncRun = execCmdEx ( rsyncRunCmd )
if rsyncRun . exitCode ! = 0 :
rsyncErrors . add ( " EZ-Bkup ' s rsync process(es) returned error ( " & $ rsyncRun . output & " ) while attempting to back up " & source & " to " & destination )
if rsyncErrors . len > 0 :
list . runStatus = " <span color= \" #ff6b6b \" size= \" large \" >Error! Please see the log at ~/.ez-bkup/errors.log</span> "
for err in rsyncErrors :
logger . log ( lvlError , err )
elif routineRunCount = = 0 :
list . runStatus = " <span color= \" #FFA651 \" size= \" large \" >Meh. No Bkup Routines were run.</span> "
else :
list . runStatus = " <span color= \" #6fffa3 \" size= \" large \" >Bkup Complete!</span> "
list . redrawFromThread ( )
list . redrawFromThread ( )
sleep ( 1000 )
method view ( list : RoutineListState ) : Widget {. locks : " unknown " . } =
method view ( list : RoutineListState ) : Widget {. locks : " unknown " . } =
result = gui :
result = gui :
@ -149,52 +192,8 @@ method view(list: RoutineListState): Widget {.locks: "unknown".} =
xAlign = 0
xAlign = 0
useMarkup = true
useMarkup = true
proc clicked ( ) =
proc clicked ( ) =
list . runStatus = " <span color= \" #FFE97B \" size= \" large \" >Running Bkup...</span> "
#list.runStatus = "<span color=\"#FFE97B\" size=\"large\">Running Bkup...</span>"
#var rsyncRun: tuple[output: string, exitCode: int]
createThread ( thread , rsyncThread , list )
var rsyncErrors : seq [ string ]
var routineRunCount = 0
for routine in list . routineModel . routineSeq ( ) :
#using this as "selected" for now.
if routine . selByDef = = true :
#skip routines that don't have at least one source and one destination.
if routine . sources . len ! = 0 and routine . destinations . len ! = 0 :
routineRuncount + = 1
for source in routine . sources :
for destination in routine . destinations :
list . runStatus = " <span color= \" #FFE97B \" size= \" large \" >Bkup " & source & " to " & destination & " ...</span> "
#try without requiring superuser privs by default.
#rsyncRun = execCmdEx("rsync -aq " & source & " " & destination)
let rsyncRunCmd = " rsync -aq " & source & " " & destination
#let rsyncThreadProcCall = rsyncThread(rsyncRunCmd)
createThread ( thread , rsyncThread ( list , rsyncRunCmd ) , list )
#createThread(thread, rsyncThreadProcCall, list)
#rsyncRun = spawn execCmdEx("rsync -aq " & source & " " & destination)
#sync()
#rsyncRun = await asynctools.execProcess("rsync -aq " & source & " " & destination)
if list . rsyncRun . exitCode ! = 0 :
#handle permission denied error.
if list . rsyncRun . exitCode = = 23 :
let rsyncRunCmd = " SUDO_ASKPASS= " & getAskPassPath ( ) & " sudo -A rsync -aq " & source & " " & destination
#rsyncRun = execCmdEx(rsyncRunCmd)
#rsyncRun = spawn execCmdEx(rsyncRunCmd)
#sync()
createThread ( thread , rsyncThread ( rsyncRunCmd ) , list )
#rsyncRun = await asynctools.execProcess(rsyncRunCmd)
if list . rsyncRun . exitCode ! = 0 :
rsyncErrors . add ( " EZ-Bkup ' s rsync process(es) returned error ( " & $ rsyncRun . output & " ) while attempting to back up " & source & " to " & destination )
else :
rsyncErrors . add ( " EZ-Bkup ' s rsync process(es) returned error ( " & $ rsyncRun . output & " ) while attempting to back up " & source & " to " & destination )
#makes the "Bkup Complete" msg below wait on the rsyncRun to finish.
if list . rsyncRun . exitCode = = 1 or list . rsyncRun . exitCode = = 0 :
if rsyncErrors . len > 0 :
list . runStatus = " <span color= \" #ff6b6b \" size= \" large \" >Error! Please see the log at ~/.ez-bkup/errors.log</span> "
for err in rsyncErrors :
writeErrorToLog ( err )
echo err
elif routineRunCount = = 0 :
list . runStatus = " <span color= \" #FFA651 \" size= \" large \" >Meh. No Bkup Routines were run.</span> "
else :
list . runStatus = " <span color= \" #6fffa3 \" size= \" large \" >Bkup Complete!</span> "
else :
else :
Box {. expand : false . } :
Box {. expand : false . } :
orient = OrientY
orient = OrientY