Add desktop notifications
This commit is contained in:
parent
a07fce1b6c
commit
7684bc43b0
3
PKGBUILD
3
PKGBUILD
@ -17,7 +17,8 @@ makedepends=('git'
|
|||||||
depends=('python'
|
depends=('python'
|
||||||
'rsync'
|
'rsync'
|
||||||
'python-dotenv')
|
'python-dotenv')
|
||||||
optdepends=('python-systemd: use systemd log')
|
optdepends=('python-systemd: use systemd log'
|
||||||
|
'python-dbus: for desktop notifications')
|
||||||
install=${pkgname}.install
|
install=${pkgname}.install
|
||||||
source=(git+https://github.com/Fuxino/${pkgname}.git)
|
source=(git+https://github.com/Fuxino/${pkgname}.git)
|
||||||
sha256sums=('SKIP')
|
sha256sums=('SKIP')
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
"""Init."""
|
"""Init."""
|
||||||
|
|
||||||
__version__ = '3.2.4'
|
__version__ = '3.2.5'
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
#Example config file for simple_backup
|
|
||||||
|
|
||||||
[default]
|
|
||||||
#Input directories. Use a comma to separate items
|
|
||||||
inputs=/home/my_home,/etc
|
|
||||||
|
|
||||||
#Output directory
|
|
||||||
backup_dir=/media/Backup
|
|
||||||
|
|
||||||
#Exclude patterns. Use a comma to separate items
|
|
||||||
exclude=.gvfs,.local/share/gvfs-metadata,.cache,.dbus,.Trash,.local/share/Trash,.macromedia,.adobe,.recently-used,.recently-used.xbel,.thumbnails
|
|
||||||
|
|
||||||
#Number of snapshots to keep (use -1 to keep all)
|
|
||||||
keep=-1
|
|
@ -19,12 +19,17 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
journal = None
|
journal = None
|
||||||
|
|
||||||
|
try:
|
||||||
|
import dbus
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
euid = os.geteuid()
|
euid = os.geteuid()
|
||||||
|
|
||||||
if euid == 0:
|
if euid == 0:
|
||||||
user = os.getenv("SUDO_USER")
|
user = os.getenv('SUDO_USER')
|
||||||
homedir = os.path.expanduser(f'~{user}')
|
homedir = os.path.expanduser(f'~{user}')
|
||||||
else:
|
else:
|
||||||
homedir = os.getenv('HOME')
|
homedir = os.getenv('HOME')
|
||||||
@ -160,6 +165,11 @@ class Backup:
|
|||||||
def run(self):
|
def run(self):
|
||||||
logger.info('Starting backup...')
|
logger.info('Starting backup...')
|
||||||
|
|
||||||
|
try:
|
||||||
|
notify('Starting backup...')
|
||||||
|
except NameError:
|
||||||
|
pass
|
||||||
|
|
||||||
self.create_backup_dir()
|
self.create_backup_dir()
|
||||||
self.find_last_backup()
|
self.find_last_backup()
|
||||||
|
|
||||||
@ -234,6 +244,13 @@ class Backup:
|
|||||||
if self._err_flag:
|
if self._err_flag:
|
||||||
logger.warning('Some errors occurred (check log for details)')
|
logger.warning('Some errors occurred (check log for details)')
|
||||||
|
|
||||||
|
try:
|
||||||
|
notify('Backup finished with errors (check log for details)')
|
||||||
|
except NameError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
notify('Backup finished')
|
||||||
|
|
||||||
|
|
||||||
def _parse_arguments():
|
def _parse_arguments():
|
||||||
parser = argparse.ArgumentParser(prog='simple_backup',
|
parser = argparse.ArgumentParser(prog='simple_backup',
|
||||||
@ -276,6 +293,24 @@ def _read_config(config_file):
|
|||||||
return inputs, output, exclude, keep
|
return inputs, output, exclude, keep
|
||||||
|
|
||||||
|
|
||||||
|
def notify(text):
|
||||||
|
euid = os.geteuid()
|
||||||
|
|
||||||
|
if euid == 0:
|
||||||
|
uid = os.getenv('SUDO_UID')
|
||||||
|
else:
|
||||||
|
uid = os.geteuid()
|
||||||
|
|
||||||
|
os.seteuid(int(uid))
|
||||||
|
os.environ['DBUS_SESSION_BUS_ADDRESS'] = f'unix:path=/run/user/{uid}/bus'
|
||||||
|
|
||||||
|
obj = dbus.SessionBus().get_object('org.freedesktop.Notifications', '/org/freedesktop/Notifications')
|
||||||
|
obj = dbus.Interface(obj, 'org.freedesktop.Notifications')
|
||||||
|
obj.Notify('', 0, '', 'simple_backup', text, [], {'urgency': 1}, 10000)
|
||||||
|
|
||||||
|
os.seteuid(int(euid))
|
||||||
|
|
||||||
|
|
||||||
def simple_backup():
|
def simple_backup():
|
||||||
args = _parse_arguments()
|
args = _parse_arguments()
|
||||||
inputs, output, exclude, keep = _read_config(args.config)
|
inputs, output, exclude, keep = _read_config(args.config)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user