Compare commits

..

No commits in common. 'master' and '0.9.8' have entirely different histories.

  1. 22
      CHANGELOG.md
  2. 1
      ez_bkup.nim
  3. 22
      shared.nim
  4. 6
      views/app_menu_button.nim
  5. 380
      views/routine_list.nim

@ -1,32 +1,12 @@
# Changelog # Changelog
## 0.9.11 - 8-8-23
### Changed
- update owlkettle to fix buggy behavior of switches.
- tweak AboutMenu text and bump version #.
## 0.9.10 - 8-6-23
### Added
- Added date and time for logged rsync errors. (ITwrx)
- Handle spaces in directory/file names. (ITwrx)
### Changed
- moved Bkup status and button out of ScrolledWindow. (ITwrx)
- fixed selected routines behavior. (ITwrx)
## 0.9.9 - 7-14-23
### Added
- Added org.itwrx.EZ-Bkup.png for window/workspace icon. (ITwrx)
### Changed
- refactored to use pkexec instead of ssh-askpass. (ITwrx)
- Updated EZ-Bkup version in app_menu_button.nim. (ITwrx)
## 0.9.8 - 7-5-23 ## 0.9.8 - 7-5-23
### Added ### Added
- Added icons and css paths that work with installed version in ez_bkup.nim. (ITwrx) - Added icons and css paths that work with installed version in ez_bkup.nim. (ITwrx)
### Changed ### Changed
- Made some file names more uniform. (ITwrx) - Made some file names more uniform. (ITwrx)
- Re-added selectedPreload proc accidentally removed from Routine.nim in last release. (ITwrx) - Re-added selectedPreload proc accidentally removed from Routine.nim in last release. (ITwrx)
- Updated EZ-Bkup version in app_menu_button.nim. (ITwrx) - Updated EZ-Bkup version in app_menu_button.nim and ez_bkup.desktop (included with installer in the funded release). (ITwrx)
## 0.9.7 - 7-1-23 ## 0.9.7 - 7-1-23
### Added ### Added

@ -18,7 +18,6 @@ method view(app: AppState): Widget =
Window: Window:
title = APP_NAME title = APP_NAME
defaultSize = (1024, 768) defaultSize = (1024, 768)
iconName = "org.itwrx.EZ-Bkup"
HeaderBar {.addTitlebar.}: HeaderBar {.addTitlebar.}:
Icon {.addLeft.}: Icon {.addLeft.}:
name = "ez_bkup" name = "ez_bkup"

@ -4,6 +4,7 @@ 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 logging, times, os import logging, times, os
#import "models/routine"
let appPath* = getHomeDir() & ".ez-bkup" let appPath* = getHomeDir() & ".ez-bkup"
let databasePath* = appPath & "/ez-bkup.sqlite" let databasePath* = appPath & "/ez-bkup.sqlite"
@ -14,6 +15,7 @@ if not dirExists(appPath):
var logger = newFileLogger(appPath & "/errors.log") var logger = newFileLogger(appPath & "/errors.log")
let dt = now() let dt = now()
let nowDT* = dt.format("M-d-YYYY h:mm:ss tt") let nowDT* = dt.format("M-d-YYYY h:mm:ss tt")
#var logMsg: string
proc writeErrorToLog*(logMsg: string) = proc writeErrorToLog*(logMsg: string) =
logger.log(lvlError, logMsg) logger.log(lvlError, logMsg)
@ -22,4 +24,22 @@ proc writeInfoToLog*(logMsg: string) =
logger.log(lvlInfo, logMsg) logger.log(lvlInfo, logMsg)
proc hasCommas*(filename: string):bool = proc hasCommas*(filename: string):bool =
',' in filename ',' in filename
proc getAskPassPath*(): string =
var askPassPath: string
if fileExists("/usr/libexec/openssh/ssh-askpass"):
askPassPath = "/usr/libexec/openssh/ssh-askpass"
elif fileExists("/usr/lib/openssh/gnome-ssh-askpass"):
askPassPath = "/usr/lib/openssh/gnome-ssh-askpass"
elif fileExists("/usr/lib/ssh/gtk-ssh-askpass"):
askPassPath = "/usr/lib/ssh/gtk-ssh-askpass"
elif fileExists("/usr/lib/ssh/ssh-askpass"):
askPassPath = "/usr/lib/ssh/ssh-askpass"
else:
askPassPath = ""
return askPassPath

@ -31,10 +31,10 @@ method view(button: AppMenuButtonState): Widget =
programName = "EZ-Bkup" programName = "EZ-Bkup"
logo = "ez_bkup" logo = "ez_bkup"
style = [StyleClass("about-dialog")] style = [StyleClass("about-dialog")]
version = "0.9.11" version = "0.9.8"
credits = @{ credits = @{
"Created:": @["https://ITwrx.org"], "Created By": @["https://ITwrx.org"],
"Src:": @["GPLv3"] "License": @["GPLv3"]
} }
Label: Label:
text = "About EZ-Bkup" text = "About EZ-Bkup"

@ -4,7 +4,7 @@ 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 osproc, os, logging, sequtils, times import std/osproc, std/os, std/logging
import edit_routine_dialog import edit_routine_dialog
import "../models/routine", "../shared" import "../models/routine", "../shared"
@ -13,9 +13,14 @@ viewable RoutineList:
runStatus: string runStatus: string
selected: seq[RoutineId] selected: seq[RoutineId]
# hey, hook.
hooks: hooks:
# yes, you, the build hook.
build: build:
state.selected = selectedPreload() # i love you. :)
state.selected = selectedPreload()
proc changed(state: bool)
var thread: Thread[RoutineListState] var thread: Thread[RoutineListState]
@ -27,8 +32,6 @@ proc rsyncThread(list: RoutineListState) {.thread.} =
createDir(appPath) createDir(appPath)
var logger = newFileLogger(appPath & "/errors.log") var logger = newFileLogger(appPath & "/errors.log")
let dt = now()
let nowDT = dt.format("M-d-YYYY h:mm:ss tt")
#i'm not sure if using threadvar here is needed, but doing it just in case. :) #i'm not sure if using threadvar here is needed, but doing it just in case. :)
var rsyncRunCmd {.threadvar.}: string var rsyncRunCmd {.threadvar.}: string
@ -47,238 +50,215 @@ proc rsyncThread(list: RoutineListState) {.thread.} =
routineRuncount += 1 routineRuncount += 1
for source in routine.sources: for source in routine.sources:
for destination in routine.destinations: for destination in routine.destinations:
#try without requiring superuser privs by default. #try without requiring superuser privs by default.
#quote sources and destinations to handle possible spaces. rsyncRunCmd = "rsync -aq " & source & " " & destination
rsyncRunCmd = "rsync -aq " & "'" & source & "'" & " " & "'" & destination & "'"
rsyncRun = execCmdEx(rsyncRunCmd) rsyncRun = execCmdEx(rsyncRunCmd)
if rsyncRun.exitCode != 0: if rsyncRun.exitCode != 0:
#handle permission denied error. #handle permission denied error.
if rsyncRun.exitCode == 23: if rsyncRun.exitCode == 23:
rsyncRun.exitCode = 0 rsyncRun.exitCode = 0
#quote sources and destinations to handle possible spaces. if getAskPassPath() == "":
rsyncRunCmd = "pkexec rsync -aq " & "'" & source & "'" & " " & "'" & destination & "'" 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."
rsyncRun = execCmdEx(rsyncRunCmd) rsyncErrors.add(err)
if rsyncRun.exitCode != 0: else:
rsyncErrors.add("(" & nowDT & ")" & "EZ-Bkup's rsync process(es) returned error (" & $rsyncRun.output & ") while attempting to back up " & source & " to " & destination) 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)
#handle non-perms related error. #handle non-perms related error.
else: else:
rsyncErrors.add("(" & nowDT & ")" & "EZ-Bkup's rsync process(es) returned error (" & $rsyncRun.output & ") while attempting to back up " & source & " to " & destination) rsyncErrors.add("EZ-Bkup's rsync process(es) returned error (" & $rsyncRun.output & ") while attempting to back up " & source & " to " & destination)
#explicitly check that sources were copied to destinations. #explicitly check that sources were copied to destinations.
#just using file names, mod times, and size (same as bkup run itself). #just using file names, mod times, and size (same as bkup run itself).
#quote sources and destinations to handle possible spaces. rsyncCheckCmd = "rsync -rn " & source & " " & destination
rsyncCheckCmd = "rsync -rn " & "'" & source & "'" & " " & "'" & destination & "'"
rsyncCheckRun = execCmdEx(rsyncCheckCmd) rsyncCheckRun = execCmdEx(rsyncCheckCmd)
if rsyncCheckRun.exitCode != 0: if rsyncCheckRun.exitCode != 0:
#handle permission denied error. #handle permission denied error.
if rsyncCheckRun.exitCode == 23: if rsyncCheckRun.exitCode == 23:
rsyncCheckRun.exitCode = 0 rsyncCheckRun.exitCode = 0
#quote sources and destinations to handle possible spaces. if getAskPassPath() == "":
rsyncCheckCmd = "pkexec rsync -rn " & "'" & source & "'" & " " & "'" & destination & "'" 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."
rsyncCheckRun = execCmdEx(rsyncCheckCmd) rsyncErrors.add(err)
if rsyncCheckRun.exitCode != 0: else:
rsyncErrors.add("(" & nowDT & ")" & "EZ-Bkup's rsync process(es) returned error (" & $rsyncRun.output & ") while attempting to verify that " & source & " got backed up to " & destination) rsyncCheckCmd = "SUDO_ASKPASS=" & getAskPassPath() & " sudo -A rsync -rn " & source & " " & destination
rsyncCheckRun = execCmdEx(rsyncCheckCmd)
if rsyncCheckRun.exitCode != 0:
rsyncErrors.add("EZ-Bkup's rsync process(es) returned error (" & $rsyncRun.output & ") while attempting to verify that " & source & " got backed up to " & destination)
#handle non-perms related error. #handle non-perms related error.
else: else:
rsyncErrors.add("(" & nowDT & ")" & "EZ-Bkup's rsync process(es) returned error (" & $rsyncRun.output & ") while attempting to verify that " & source & " got backed up to " & destination) rsyncErrors.add("EZ-Bkup's rsync process(es) returned error (" & $rsyncRun.output & ") while attempting to verify that " & source & " got backed up to " & destination)
if rsyncErrors.len > 0: if rsyncErrors.len > 0:
list.runStatus = "<span color=\"#ff6b6b\" size=\"large\">Error! Please see ~/.ez-bkup/errors.log</span>" list.runStatus = "<span color=\"#ff6b6b\" size=\"large\">Error! Please see ~/.ez-bkup/errors.log</span>"
for err in rsyncErrors: for err in rsyncErrors:
logger.log(lvlError, err) logger.log(lvlError, err)
elif routineRunCount == 0: elif routineRunCount == 0:
list.runStatus = "<span color=\"#FFA651\" size=\"large\">No Bkup Routines were enabled. None were run.</span>" list.runStatus = "<span color=\"#FFA651\" size=\"large\">Meh. No Bkup Routines were run.</span>"
else: else:
list.runStatus = "<span color=\"#6fffa3\" size=\"large\">Bkup Complete!</span>" list.runStatus = "<span color=\"#6fffa3\" size=\"large\">Bkup Complete!</span>"
list.redrawFromThread() list.redrawFromThread()
method view(list: RoutineListState): Widget = method view(list: RoutineListState): Widget =
result = gui: result = gui:
Box: ScrolledWindow:
orient = OrientY
Box: Box:
orient = OrientY orient = OrientY
ScrolledWindow: if list.routineModel.routineSeq().len() > 0:
Box: ListBox:
orient = OrientY for it, routine in list.routineModel.routineSeq():
if list.routineModel.routineSeq().len() > 0: Box:
ListBox: orient = OrientY
for it, routine in list.routineModel.routineSeq(): margin = 6
spacing = 6
Box:
orient = OrientX
margin = 6
spacing = 6
Switch {.expand: false, vAlign: AlignCenter.}:
state = routine.selByDef
tooltip = "Enable/Disable this Routine for the current Bkup run."
proc changed(state: bool) =
if state == true:
list.selected.add(routine.id)
else:
let index = list.selected.find(routine.id)
if index != -1:
list.selected.delete(index)
if not list.changed.isNil:
list.changed.callback(true)
Label:
text = "<span size=\"large\">" & routine.name & "</span>"
xAlign = 0
useMarkup = true
# Edit Button
Button {.expand: false.}:
#icon = "entity-edit"
icon = "entity-edit-dark-theme"
tooltip = "Edit this Routine."
proc clicked() =
## Opens the EditRoutineDialog for updating the existing routine
let (res, state) = list.app.open: gui:
EditRoutineDialog:
routine = routine
mode = EditRoutineUpdate
if res.kind == DialogAccept:
# The "Update" button was clicked
list.routineModel.update(EditRoutineDialogState(state).routine)
# Delete Button
Button {.expand: false.}:
icon = "user-trash-symbolic"
tooltip = "Delete this Routine. Warning: will not ask you to confirm."
proc clicked() =
list.routineModel.delete(routine.id)
if routine.id in list.selected:
Box: Box:
orient = OrientY orient = OrientY
margin = 6 margin = 6
spacing = 6 spacing = 6
Box: Label:
orient = OrientX text = "<span color=\"#6fffa3\">Sources:</span>"
margin = 6 xAlign = 0
spacing = 6 useMarkup = true
Switch {.expand: false, vAlign: AlignCenter.}: #routineSeq returns an empty string when no sources exist.
state = sequtils.any(list.selected, proc (id: RoutineId): bool = id == routine.id) if routine.sources.len != 0:
tooltip = "Enable/Disable this Routine for the current Bkup run." for it, routineSource in routine.sources:
proc changed(state: bool) = Box:
if state == true: orient = OrientX
list.selected.add(routine.id) spacing = 6
else: margin = 6
let index = list.selected.find(routine.id) Label:
if index != -1: text = routineSource
list.selected.delete(index) xAlign = 0
Label: else:
text = "<span size=\"large\">" & routine.name & "</span>"
xAlign = 0
useMarkup = true
# Edit Button
Button {.expand: false.}:
#icon = "entity-edit"
icon = "entity-edit-dark-theme"
tooltip = "Edit this Routine."
proc clicked() =
## Opens the EditRoutineDialog for updating the existing routine
let (res, state) = list.app.open: gui:
EditRoutineDialog:
routine = routine
mode = EditRoutineUpdate
if res.kind == DialogAccept:
# The "Update" button was clicked
list.routineModel.update(EditRoutineDialogState(state).routine)
list.selected = selectedPreload()
# Delete Button
Button {.expand: false.}:
icon = "user-trash-symbolic"
tooltip = "Delete this Routine. Warning: will not ask you to confirm."
proc clicked() =
list.routineModel.delete(routine.id)
list.selected = selectedPreload()
if routine.id in list.selected:
Box: Box:
orient = OrientY orient = OrientX
margin = 6
spacing = 6 spacing = 6
margin = 6
Label: Label:
text = "<span color=\"#6fffa3\">Sources:</span>" text = "<span color=\"#ff6b6b\">Routine will be ignored. Source required.</span>"
xAlign = 0 xAlign = 0
useMarkup = true useMarkup = true
#routineSeq returns an empty string when no sources exist. Label:
if routine.sources.len != 0: text = "<span color=\"#6fffa3\">Destinations:</span>"
for it, routineSource in routine.sources: xAlign = 0
Box: useMarkup = true
orient = OrientX #routineSeq returns an empty string when no destinations exist.
spacing = 6 if routine.destinations.len != 0:
margin = 6 for it, routineDestination in routine.destinations:
Label: Box:
text = routineSource orient = OrientX
xAlign = 0 spacing = 6
else: margin = 6
Box: Label:
orient = OrientX text = routineDestination
spacing = 6 xAlign = 0
margin = 6 else:
Label: Box:
text = "<span color=\"#ff6b6b\">Routine will be ignored. Source required.</span>" orient = OrientX
xAlign = 0 spacing = 6
useMarkup = true margin = 6
Label: Label:
text = "<span color=\"#6fffa3\">Destinations:</span>" text = "<span color=\"#ff6b6b\">Routine will be ignored. Destination required.</span>"
xAlign = 0 xAlign = 0
useMarkup = true useMarkup = true
#routineSeq returns an empty string when no destinations exist.
if routine.destinations.len != 0:
for it, routineDestination in routine.destinations:
Box:
orient = OrientX
spacing = 6
margin = 6
Label:
text = routineDestination
xAlign = 0
else:
Box:
orient = OrientX
spacing = 6
margin = 6
Label:
text = "<span color=\"#ff6b6b\">Routine will be ignored. Destination required.</span>"
xAlign = 0
useMarkup = true
else:
Box {.expand: false.}:
orient = OrientY
margin = 6
spacing = 12
Label:
text = "<span size=\"large\">You don't have any Bkup Routines!!! 🙂</span>"
xAlign = 0
useMarkup = true
Label:
text = "<span size=\"large\">Please click on the + Routine button above to create your first Routine.</span>"
xAlign = 0
useMarkup = true
if list.routineModel.routineSeq().len() > 0:
Box {.expand: false.}:
orient = OrientY
Box {.expand: false.}: Box {.expand: false.}:
orient = OrientY orient = OrientX
Box {.expand: false.}: spacing = 6
orient = OrientX margin = 6
spacing = 6 Label {.expand: false.}:
text = "<span size=\"large\">Status: </span>"
xAlign = 0
useMarkup = true
Label:
if list.runStatus != "":
text = list.runStatus
else:
text = "<span color=\"#6AC9FF\" size=\"large\">Waiting patiently...</span>"
xAlign = 0
margin = 6 margin = 6
Label {.expand: false.}: useMarkup = true
text = "<span size=\"large\">Status: </span>" # Run Button
xAlign = 0 Button {.expand: false.}:
useMarkup = true Box:
Label: orient = OrientX
if list.runStatus != "": spacing = 6
text = list.runStatus margin = 6
else: Icon:
text = "<span color=\"#6AC9FF\" size=\"large\">Waiting patiently...</span>" name = "media-floppy"
pixelSize = 40
margin = 4
Label {.expand: false.}:
text = "<span size=\"large\">Run Bkup!</span>"
xAlign = 0 xAlign = 0
margin = 6 useMarkup = true
useMarkup = true proc clicked() =
# Run Button #check that every source and destination exists for each routine or don't run bkup and show err status.
Button {.expand: false.}: #locations not found will be logged. see routine.nim
Box: var allLocationsExist: seq[bool]
orient = OrientX for routine in list.routineModel.routineSeq():
spacing = 6 if routine.id in list.selected:
margin = 6 if locationsExist(routine) == true:
Icon: allLocationsExist.add(true)
name = "media-floppy" else:
pixelSize = 40 allLocationsExist.add(false)
margin = 4 if false in allLocationsExist:
Label {.expand: false.}: #show error status.
text = "<span size=\"large\">Run Bkup!</span>" list.runStatus = "<span color=\"#ff6b6b\" size=\"large\">Missing Source(s)/Destination(s) in selected Routine(s).</span>"
xAlign = 0 else:
useMarkup = true createThread(thread, rsyncThread, list)
proc clicked() = else:
#check that every source and destination exists for each routine or don't run bkup and show err status. Box {.expand: false.}:
#locations not found will be logged. see routine.nim orient = OrientY
var allLocationsExist: seq[bool] margin = 6
for routine in list.routineModel.routineSeq(): spacing = 12
if routine.id in list.selected: Label:
if locationsExist(routine) == true: text = "<span size=\"large\">You don't have any Bkup Routines!!! 🙂</span>"
allLocationsExist.add(true) xAlign = 0
else: useMarkup = true
allLocationsExist.add(false) Label:
if false in allLocationsExist: text = "<span size=\"large\">Please click on the + Routine button above to create your first Routine.</span>"
#show error status. xAlign = 0
list.runStatus = "<span color=\"#ff6b6b\" size=\"large\">Missing Source(s)/Destination(s) in selected Routine(s).</span>" useMarkup = true
else:
createThread(thread, rsyncThread, list)
#[if not list.routineModel.routineSeq().len() > 0:
Box:
orient = OrientX
spacing = 6
margin = 6
Box {.expand: false.}:
orient = OrientY
margin = 6
spacing = 12
Label:
text = "<span size=\"large\">You don't have any Bkup Routines!!! 🙂</span>"
xAlign = 0
useMarkup = true
Label:
text = "<span size=\"large\">Please click on the + Routine button above to create your first Routine.</span>"
xAlign = 0
useMarkup = true]#
export RoutineList export RoutineList

Loading…
Cancel
Save