Basic argparser
This commit is contained in:
parent
6c25628ecb
commit
fc47cd993d
|
@ -1,20 +1,18 @@
|
||||||
|
import argparse
|
||||||
|
import sys
|
||||||
|
|
||||||
from restic_volume_backup.config import Config
|
from restic_volume_backup.config import Config
|
||||||
from restic_volume_backup.containers import RunningContainers
|
from restic_volume_backup.containers import RunningContainers
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
if len(sys.argv) < 2:
|
args = parse_args()
|
||||||
raise ValueError("Missing argument: {}".format(cmds))
|
|
||||||
|
|
||||||
mode = sys.argv[1]
|
|
||||||
if mode not in cmds:
|
|
||||||
raise ValueError("Valid arguments: {}".format(cmds))
|
|
||||||
|
|
||||||
Config.check()
|
Config.check()
|
||||||
|
|
||||||
containers = RunningContainers()
|
containers = RunningContainers()
|
||||||
|
|
||||||
if mode == 'status':
|
if args.action == 'status':
|
||||||
containers.print_services()
|
containers.print_services()
|
||||||
# volumes = containers.volume_mounts()
|
# volumes = containers.volume_mounts()
|
||||||
# for vol in volumes:
|
# for vol in volumes:
|
||||||
|
@ -26,7 +24,7 @@ def main():
|
||||||
# print(binds)
|
# print(binds)
|
||||||
# print(vol.mount_string())
|
# print(vol.mount_string())
|
||||||
|
|
||||||
if mode == 'backup':
|
elif args.mode == 'backup':
|
||||||
print("Starting backup ..")
|
print("Starting backup ..")
|
||||||
# TODO: Errors when repo already exists
|
# TODO: Errors when repo already exists
|
||||||
# restic.init_repo(Config.repository)
|
# restic.init_repo(Config.repository)
|
||||||
|
@ -34,9 +32,18 @@ def main():
|
||||||
# for vol in containers.backup_volumes():
|
# for vol in containers.backup_volumes():
|
||||||
# restic.backup_volume(Config.repository, vol)
|
# restic.backup_volume(Config.repository, vol)
|
||||||
|
|
||||||
if mode == 'snapshots':
|
elif args.mode == 'snapshots':
|
||||||
restic.snapshots(Config.repository)
|
restic.snapshots(Config.repository)
|
||||||
|
|
||||||
|
|
||||||
|
def parse_args():
|
||||||
|
parser = argparse.ArgumentParser(prog='restic_volume_backup')
|
||||||
|
parser.add_argument(
|
||||||
|
'action',
|
||||||
|
choices=['status', 'backup'],
|
||||||
|
)
|
||||||
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Reference in New Issue