Merge branch 'async_rsync'

master
itwrx 1 year ago
commit cd2bcaeabb
  1. 31
      shared.nim
  2. 98
      views/routine_list.nim

@ -37,32 +37,7 @@ proc hasCommas*(filename: string):bool =
proc getAskPassPath*(): string =
var askPassPath: string
if detectOs(Fedora):
if fileExists("/usr/libexec/openssh/ssh-askpass"):
askPassPath = "/usr/libexec/openssh/ssh-askpass"
else:
writeErrorToLog("No ssh-askpass binary found. Please run 'dnf install openssh-askpass'")
askPassPath = ""
elif detectOs(Ubuntu):
if fileExists("/usr/lib/openssh/gnome-ssh-askpass"):
askPassPath = "/usr/lib/openssh/gnome-ssh-askpass"
else:
writeErrorToLog("No ssh-askpass binary found. Please run 'sudo apt install ssh-askpass-gnome'.")
askPassPath = ""
#save this for a musl build.
#[elif detectOs(Alpine):
if fileExists("/usr/lib/ssh/gtk-ssh-askpass"):
askPassPath = "/usr/lib/ssh/gtk-ssh-askpass"
else:
writeErrorToLog("No ssh-askpass binary found. Please run 'apk add gtk-ssh-askpass'.")
askPassPath = ""]#
elif detectOs(ArchLinux):
if fileExists("/usr/lib/ssh/ssh-askpass"):
askPassPath = "/usr/lib/ssh/ssh-askpass"
else:
writeErrorToLog("No ssh-askpass binary found. Please run 'pacman -S x11-ssh-askpass', or similar.")
askPassPath = ""
elif detectOs(Linux):
if fileExists("/usr/libexec/openssh/ssh-askpass"):
askPassPath = "/usr/libexec/openssh/ssh-askpass"
elif fileExists("/usr/lib/openssh/gnome-ssh-askpass"):
@ -72,10 +47,6 @@ proc getAskPassPath*(): string =
elif fileExists("/usr/lib/ssh/ssh-askpass"):
askPassPath = "/usr/lib/ssh/ssh-askpass"
else:
writeErrorToLog("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.")
askPassPath = ""
else:
writeErrorToLog("Your OS does not appear to be supported at this time. If you are getting this error and you are using a x86_64 gnu libc-based linux distribution please report this issue. Please include the path to your ssh-askpass binary, as well.")
askPassPath = ""
return askPassPath

@ -4,17 +4,72 @@ EZ-Bkup is released under the General Public License 3.0.
See COPYING or <https://www.gnu.org/licenses/> for details.]#
import owlkettle
import std/osproc
import std/osproc, std/os, std/logging
import edit_routine_dialog
import "../models/routine", "../shared"
viewable RoutineList:
## Displays a list of routines
routineModel: RoutineModel ## Model of all routines
routineModel: RoutineModel
runStatus: string
proc changed(state: bool)
var thread: Thread[RoutineListState]
proc rsyncThread(list: RoutineListState) {.thread.} =
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()
method view(list: RoutineListState): Widget {.locks: "unknown".} =
result = gui:
ScrolledWindow:
@ -137,41 +192,8 @@ method view(list: RoutineListState): Widget {.locks: "unknown".} =
xAlign = 0
useMarkup = true
proc clicked() =
list.runStatus = "<span color=\"#FFE97B\" size=\"large\">Running Bkup...</span>"
var rsyncRun: tuple[output: string, exitCode: int]
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)
if rsyncRun.exitCode != 0:
#handle permission denied error.
if rsyncRun.exitCode == 23:
let 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)
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 rsyncRun.exitCode == 1 or 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>"
#list.runStatus = "<span color=\"#FFE97B\" size=\"large\">Running Bkup...</span>"
createThread(thread, rsyncThread, list)
else:
Box {.expand: false.}:
orient = OrientY

Loading…
Cancel
Save