diff --git a/PKGBUILD b/PKGBUILD index 8b74176..cdbc19a 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -17,7 +17,8 @@ makedepends=('git' depends=('python' 'rsync' 'python-dotenv') -optdepends=('python-systemd: use systemd log') +optdepends=('python-systemd: use systemd log' + 'python-dbus: for desktop notifications') install=${pkgname}.install source=(git+https://github.com/Fuxino/${pkgname}.git) sha256sums=('SKIP') diff --git a/simple_backup/__init__.py b/simple_backup/__init__.py index 96fcba4..3b5a160 100644 --- a/simple_backup/__init__.py +++ b/simple_backup/__init__.py @@ -1,3 +1,3 @@ """Init.""" -__version__ = '3.2.4' +__version__ = '3.2.5' diff --git a/simple_backup/simple_backup.conf b/simple_backup/simple_backup.conf deleted file mode 100644 index 6adc9a4..0000000 --- a/simple_backup/simple_backup.conf +++ /dev/null @@ -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 \ No newline at end of file diff --git a/simple_backup/simple_backup.py b/simple_backup/simple_backup.py index 0dfbc6b..b349f19 100755 --- a/simple_backup/simple_backup.py +++ b/simple_backup/simple_backup.py @@ -19,12 +19,17 @@ try: except ImportError: journal = None +try: + import dbus +except ImportError: + pass + load_dotenv() euid = os.geteuid() if euid == 0: - user = os.getenv("SUDO_USER") + user = os.getenv('SUDO_USER') homedir = os.path.expanduser(f'~{user}') else: homedir = os.getenv('HOME') @@ -160,6 +165,11 @@ class Backup: def run(self): logger.info('Starting backup...') + try: + notify('Starting backup...') + except NameError: + pass + self.create_backup_dir() self.find_last_backup() @@ -234,6 +244,13 @@ class Backup: if self._err_flag: 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(): parser = argparse.ArgumentParser(prog='simple_backup', @@ -276,6 +293,24 @@ def _read_config(config_file): 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(): args = _parse_arguments() inputs, output, exclude, keep = _read_config(args.config)