diff options
author | xengineering <me@xengineering.eu> | 2021-10-08 08:27:54 +0200 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2021-10-08 08:27:54 +0200 |
commit | 73e70e50aa71147566614a6d36064f1af1dd97db (patch) | |
tree | d956ef8593129a4e3dc4607e26763ff4003a6feb | |
parent | 6811d4b3db7967b0e0da22ae966de509a46b5550 (diff) | |
download | xbackup-73e70e50aa71147566614a6d36064f1af1dd97db.tar xbackup-73e70e50aa71147566614a6d36064f1af1dd97db.tar.zst xbackup-73e70e50aa71147566614a6d36064f1af1dd97db.zip |
Some Improvements based on pylint
-rw-r--r-- | src/debug.py | 1 | ||||
-rw-r--r-- | src/setup.py | 6 | ||||
-rw-r--r-- | src/xbackup/backup.py | 49 | ||||
-rw-r--r-- | src/xbackup/script.py | 13 |
4 files changed, 42 insertions, 27 deletions
diff --git a/src/debug.py b/src/debug.py index 6daa264..1deaf45 100644 --- a/src/debug.py +++ b/src/debug.py @@ -16,4 +16,3 @@ def main(): if __name__ == "__main__": main() - diff --git a/src/setup.py b/src/setup.py index e73eef0..b47026d 100644 --- a/src/setup.py +++ b/src/setup.py @@ -2,6 +2,12 @@ # vim: shiftwidth=4 softtabstop=4 tabstop=4 expandtab +"""setup.py + +Configuration file for setuptools. +""" + + from distutils.core import setup diff --git a/src/xbackup/backup.py b/src/xbackup/backup.py index b56e0cc..b3b5a0b 100644 --- a/src/xbackup/backup.py +++ b/src/xbackup/backup.py @@ -1,5 +1,6 @@ #!/usr/bin/python3 # vim: shiftwidth=4 softtabstop=4 tabstop=4 expandtab +# pylint: disable=too-few-public-methods """Backup Functionality of xbackup""" @@ -18,24 +19,13 @@ def backup(config): print(paths) # init borg repository (accepting failure on already existing repo) - shell("borg init -e none {}".format(paths.borg_repo), panic=False) + shell(f"borg init -e none {paths.borg_repo}", panic=False) # run backup - command = "borg create -v --stats --compression zstd \\" - command += """ - {repo}::'{{hostname}}-{{user}}-{{now:%Y-%m-%d_%H:%M:%S}}' \\""".format( - repo=paths.borg_repo - ) - command += "\n {} \\".format(paths.backup_source) - for key,value in enumerate(paths.blacklist): - command += "\n --exclude '{}'".format(value) - if key != len(paths.blacklist) -1: - command += " \\" + run_backup(paths) - shell(command) - -class Filepaths(object): +class Filepaths(): """A Container Class to hold Filepaths for the Borg Backup Tool""" def __init__(self, config): @@ -44,7 +34,7 @@ class Filepaths(object): # parse backup source (usually / for system backups) self.backup_source = config["backup_source"] - # + # parse folder for borg repositories self.borg_repos_folder = config["borg_repos_folder"] # path to the borg repository @@ -89,12 +79,31 @@ def shell(command, panic=True): # handle non-zero return code if return_code != 0 and panic: - print("Command '{}'\nfailed with return code {}".format( - command, - str(return_code) - )) + print(f"Command '{command}'\nfailed with return code {return_code}") sys.exit(return_code) # final message and return print("... done!") - return + + +def run_backup(paths): + """Execute the Borg Backup""" + + # base command + command = "borg create -v --stats --compression zstd \\" + + # set repository path + command += \ + f"{paths.borg_repo}::'{{hostname}}-{{user}}-{{now:%Y-%m-%d_%H:%M:%S}}' \\" + + # set backup source + command += f"\n {paths.backup_source} \\" + + # append blacklist elements + for key,value in enumerate(paths.blacklist): + command += f"\n --exclude '{value}'" + if key != len(paths.blacklist) -1: + command += " \\" + + # run command + shell(command) diff --git a/src/xbackup/script.py b/src/xbackup/script.py index c8e619b..272894f 100644 --- a/src/xbackup/script.py +++ b/src/xbackup/script.py @@ -6,7 +6,6 @@ import argparse -import time import sys from xbackup import config @@ -24,7 +23,7 @@ def run(): if args.command == "backup": backup.backup(cfg["backup"]) else: - print("Unknown command '{}'".format(args.command)) + print(f"Unknown command '{args.command}'") sys.exit(1) bye() @@ -35,8 +34,10 @@ def parse_arguments(): # parser creation parser = argparse.ArgumentParser( prog="xbackup", - description="xbackup CLI Script to make a File-based full System Backup", - epilog="Project page: https://gitea.xengineering.eu/xengineering/xbackup", + description= \ + "xbackup CLI Script to make a File-based full System Backup", + epilog= \ + "Project page: https://gitea.xengineering.eu/xengineering/xbackup", ) # positional arguments @@ -60,13 +61,13 @@ def parse_arguments(): def welcome(): """Print Welcome Text""" - print(""" + print(r""" ################################################################################ _ _ __ _| |__ __ _ ___| | ___ _ _ __ \ \/ / '_ \ / _` |/ __| |/ / | | | '_ \ > <| |_) | (_| | (__| <| |_| | |_) | - /_/\_\_.__/ \__,_|\___|_|\_\\\\__,_| .__/ + /_/\_\_.__/ \__,_|\___|_|\_\\__,_| .__/ |_| ################################################################################ |