Move some options to library functions

This commit is contained in:
Eric Torres 2019-04-14 22:08:37 -07:00
parent 83217f6205
commit 8176d7a527

View File

@ -24,23 +24,11 @@ import sys
from subprocess import CalledProcessError from subprocess import CalledProcessError
import rbackup.config as config import rbackup.config as config
from rbackup.rsync import rsync import rbackup.rsync
from rbackup.struct.repository import Repository from rbackup.struct.repository import Repository
# ========== Constants ========== # ========== Constants ==========
LOGFORMAT = "==> %(levelname)s %(message)s" 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 = { EXTRA_RSYNC_OPTS = {
"dry_run": "--dry-run", "dry_run": "--dry-run",
"delete": "--delete-after", "delete": "--delete-after",
@ -116,9 +104,18 @@ def parse_cmdline_arguments(**kwargs):
# ========== Main Script ========== # ========== Main Script ==========
if __name__ == "__main__": if __name__ == "__main__":
args = parse_cmdline_arguments() args = parse_cmdline_arguments()
parsed_config = config.parse_configfile()
repo = Repository(args.repository) 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: if args.extra_rsync_opts is not None:
rsync_opts.extend(args.extra_rsync_opts) 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: with config.merge_include_files() as include_file, config.merge_exclude_files() as exclude_file:
try: try:
curr_snapshot = repo.create_snapshot(args.name) curr_snapshot = repo.create_snapshot(args.name)
rsync( rbackup.rsync.rsync(
*rsync_opts, *rsync_opts,
f"--exclude-from={exclude_file}", f"--exclude-from={exclude_file}",
f"--files-from={include_file}", f"--files-from={include_file}",