From 8176d7a527190c628f1876234536fd9ad25caf83 Mon Sep 17 00:00:00 2001 From: Eric Torres Date: Sun, 14 Apr 2019 22:08:37 -0700 Subject: [PATCH] Move some options to library functions --- bin/backup | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/bin/backup b/bin/backup index dc84367..638c95a 100644 --- a/bin/backup +++ b/bin/backup @@ -24,23 +24,11 @@ import sys from subprocess import CalledProcessError import rbackup.config as config -from rbackup.rsync import rsync +import rbackup.rsync from rbackup.struct.repository import Repository # ========== Constants ========== LOGFORMAT = "==> %(levelname)s %(message)s" -RSYNC_DEFAULT_OPTS = [ - "--acls", - "--archive", - "--backup", - "--backup-dir=backup", - "--hard-links", - "--ignore-missing-args", - "--prune-empty-dirs", - "--suffix=.old", - "--recursive", - "--xattrs", -] EXTRA_RSYNC_OPTS = { "dry_run": "--dry-run", "delete": "--delete-after", @@ -116,9 +104,18 @@ def parse_cmdline_arguments(**kwargs): # ========== Main Script ========== if __name__ == "__main__": args = parse_cmdline_arguments() + parsed_config = config.parse_configfile() repo = Repository(args.repository) - rsync_opts = RSYNC_DEFAULT_OPTS.copy() + user_opts = config.load_list_from_option( + parsed_config, section="main", option="RsyncOptions" + ) + rsync_opts = [] + + if not user_opts: + rsync_opts = rbackup.rsync.DEFAULT_RSYNC_OPTS.copy() + else: + rsync_opts.extend(user_opts) if args.extra_rsync_opts is not None: rsync_opts.extend(args.extra_rsync_opts) @@ -138,7 +135,7 @@ if __name__ == "__main__": with config.merge_include_files() as include_file, config.merge_exclude_files() as exclude_file: try: curr_snapshot = repo.create_snapshot(args.name) - rsync( + rbackup.rsync.rsync( *rsync_opts, f"--exclude-from={exclude_file}", f"--files-from={include_file}",