4 Commits
3.1.0 ... 3.1.2

Author SHA1 Message Date
eb8bdde1fc Rename configuration file 2023-05-02 18:07:41 +02:00
5d17aaf03a Update dependencies in PKGBUILD 2023-04-30 22:06:30 +02:00
d181d2970f Better handle missing parameters 2023-04-30 14:38:26 +02:00
84e6d58493 Handle dbus exceptions 2023-04-30 11:53:31 +02:00
4 changed files with 31 additions and 15 deletions

View File

@ -14,7 +14,8 @@ makedepends=('git')
depends=('python3' depends=('python3'
'rsync' 'rsync'
'python-dotenv' 'python-dotenv'
'python-dbus') 'python-dbus'
'python-systemd')
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')
@ -28,5 +29,5 @@ pkgver()
package() package()
{ {
install -Dm755 "${srcdir}/${pkgname}/${pkgname}.py" "${pkgdir}/usr/bin/${pkgname}" install -Dm755 "${srcdir}/${pkgname}/${pkgname}.py" "${pkgdir}/usr/bin/${pkgname}"
install -Dm644 "${srcdir}/${pkgname}/${pkgname}.config" "${pkgdir}/etc/${pkgname}/${pkgname}.config" install -Dm644 "${srcdir}/${pkgname}/${pkgname}.config" "${pkgdir}/etc/${pkgname}/${pkgname}.conf"
} }

View File

@ -1,6 +1,6 @@
post_install() { post_install() {
echo "An example configuration file is found in /etc/simple_backup/simple_backup.config." echo "An example configuration file is found in /etc/simple_backup/simple_backup.conf."
echo "Copy it to ~/config/simple_backup/simple_backup.config and modify it as needed" echo "Copy it to ~/config/simple_backup/simple_backup.conf and modify it as needed"
} }
post_upgrade() { post_upgrade() {

View File

@ -103,11 +103,18 @@ class Backup:
logger.warning(f'Input {i} is a link and cannot be read. Skipping') logger.warning(f'Input {i} is a link and cannot be read. Skipping')
self.inputs.remove(i) self.inputs.remove(i)
if self.output is None:
logger.critical('No output path specified. Use -o argument or specify output path in configuration file')
return False
if not os.path.isdir(self.output): if not os.path.isdir(self.output):
logger.critical('Output path for backup does not exist') logger.critical('Output path for backup does not exist')
return False return False
self.output = os.path.abspath(self.output)
if self.keep is None: if self.keep is None:
self.keep = -1 self.keep = -1
@ -236,11 +243,11 @@ class Backup:
def _parse_arguments(): def _parse_arguments():
parser = argparse.ArgumentParser(prog='simple_backup', parser = argparse.ArgumentParser(prog='simple_backup',
description='A simple backup script written in Python that uses rsync to copy files', description='Simple backup script written in Python that uses rsync to copy files',
epilog='Report bugs to dfucini<at>gmail<dot>com', epilog='Report bugs to dfucini<at>gmail<dot>com',
formatter_class=MyFormatter) formatter_class=MyFormatter)
parser.add_argument('-c', '--config', default=f'{homedir}/.config/simple_backup/simple_backup.config', parser.add_argument('-c', '--config', default=f'{homedir}/.config/simple_backup/simple_backup.conf',
help='Specify location of configuration file') help='Specify location of configuration file')
parser.add_argument('-i', '--input', nargs='+', help='Paths/files to backup') parser.add_argument('-i', '--input', nargs='+', help='Paths/files to backup')
parser.add_argument('-o', '--output', help='Output directory for the backup') parser.add_argument('-o', '--output', help='Output directory for the backup')
@ -294,20 +301,28 @@ def simple_backup():
else: else:
backup_options = '-arvh -H -X' backup_options = '-arvh -H -X'
output = os.path.abspath(output)
backup = Backup(inputs, output, exclude, keep, backup_options) backup = Backup(inputs, output, exclude, keep, backup_options)
if backup.check_params(): if backup.check_params():
obj = dbus.SessionBus().get_object("org.freedesktop.Notifications", "/org/freedesktop/Notifications") try:
obj = dbus.Interface(obj, "org.freedesktop.Notifications") obj = dbus.SessionBus().get_object("org.freedesktop.Notifications", "/org/freedesktop/Notifications")
obj.Notify("simple_backup", 0, "", "Starting backup...", "", [], {"urgency": 1}, 10000) obj = dbus.Interface(obj, "org.freedesktop.Notifications")
obj.Notify("simple_backup", 0, "", "Starting backup...", "", [], {"urgency": 1}, 10000)
except dbus.exceptions.DBusException:
obj = None
status = backup.run() status = backup.run()
if status == 0: if obj is not None:
obj.Notify("simple_backup", 0, "", "Backup finished.", "", [], {"urgency": 1}, 10000) if status == 0:
else: obj.Notify("simple_backup", 0, "", "Backup finished.", "", [], {"urgency": 1}, 10000)
obj.Notify("simple_backup", 0, "", "Backup finished. Some errors occurred.", "", [], {"urgency": 1}, 10000) else:
obj.Notify("simple_backup", 0, "", "Backup finished. Some errors occurred.",
"", [], {"urgency": 1}, 10000)
return 0
return 1
if __name__ == '__main__': if __name__ == '__main__':