command.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. from __future__ import print_function
  2. from argparse import ArgumentParser
  3. from subprocess import CalledProcessError
  4. import sys
  5. from atticmatic.attic import create_archive, prune_archives
  6. from atticmatic.config import parse_configuration
  7. def parse_arguments():
  8. '''
  9. Parse the command-line arguments from sys.argv and return them as an ArgumentParser instance.
  10. '''
  11. parser = ArgumentParser()
  12. parser.add_argument(
  13. '-c', '--config',
  14. dest='config_filename',
  15. default='/etc/atticmatic/config',
  16. help='Configuration filename',
  17. )
  18. parser.add_argument(
  19. '--excludes',
  20. dest='excludes_filename',
  21. default='/etc/atticmatic/excludes',
  22. help='Excludes filename',
  23. )
  24. parser.add_argument(
  25. '-v', '--verbose',
  26. action='store_true',
  27. help='Display verbose progress information',
  28. )
  29. return parser.parse_args()
  30. def main():
  31. try:
  32. args = parse_arguments()
  33. location_config, retention_config = parse_configuration(args.config_filename)
  34. create_archive(args.excludes_filename, args.verbose, *location_config)
  35. prune_archives(location_config.repository, args.verbose, *retention_config)
  36. except (ValueError, IOError, CalledProcessError) as error:
  37. print(error, file=sys.stderr)
  38. sys.exit(1)