2014-10-31 06:34:03 +01:00
|
|
|
from __future__ import print_function
|
|
|
|
from argparse import ArgumentParser
|
|
|
|
from subprocess import CalledProcessError
|
|
|
|
import sys
|
|
|
|
|
2015-02-14 18:23:40 +01:00
|
|
|
from atticmatic.attic import check_archives, create_archive, prune_archives
|
2014-10-31 06:34:03 +01:00
|
|
|
from atticmatic.config import parse_configuration
|
|
|
|
|
|
|
|
|
2014-12-20 20:37:25 +01:00
|
|
|
DEFAULT_CONFIG_FILENAME = '/etc/atticmatic/config'
|
|
|
|
DEFAULT_EXCLUDES_FILENAME = '/etc/atticmatic/excludes'
|
|
|
|
|
|
|
|
|
|
|
|
def parse_arguments(*arguments):
|
2014-12-02 07:35:25 +01:00
|
|
|
'''
|
2014-12-20 20:42:27 +01:00
|
|
|
Parse the given command-line arguments and return them as an ArgumentParser instance.
|
2014-12-02 07:35:25 +01:00
|
|
|
'''
|
2014-10-31 06:34:03 +01:00
|
|
|
parser = ArgumentParser()
|
|
|
|
parser.add_argument(
|
2014-12-02 07:47:51 +01:00
|
|
|
'-c', '--config',
|
2014-10-31 06:34:03 +01:00
|
|
|
dest='config_filename',
|
2014-12-20 20:37:25 +01:00
|
|
|
default=DEFAULT_CONFIG_FILENAME,
|
2014-10-31 06:34:03 +01:00
|
|
|
help='Configuration filename',
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
'--excludes',
|
|
|
|
dest='excludes_filename',
|
2014-12-20 20:37:25 +01:00
|
|
|
default=DEFAULT_EXCLUDES_FILENAME,
|
2014-10-31 06:34:03 +01:00
|
|
|
help='Excludes filename',
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
2014-12-02 07:47:51 +01:00
|
|
|
'-v', '--verbose',
|
2014-10-31 06:34:03 +01:00
|
|
|
action='store_true',
|
|
|
|
help='Display verbose progress information',
|
|
|
|
)
|
|
|
|
|
2014-12-20 20:37:25 +01:00
|
|
|
return parser.parse_args(arguments)
|
2014-12-02 07:35:25 +01:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2014-10-31 06:34:03 +01:00
|
|
|
try:
|
2014-12-20 20:37:25 +01:00
|
|
|
args = parse_arguments(*sys.argv[1:])
|
2014-10-31 06:34:03 +01:00
|
|
|
location_config, retention_config = parse_configuration(args.config_filename)
|
2015-02-14 18:23:40 +01:00
|
|
|
repository = location_config['repository']
|
2014-10-31 06:34:03 +01:00
|
|
|
|
2014-12-07 03:35:20 +01:00
|
|
|
create_archive(args.excludes_filename, args.verbose, **location_config)
|
2015-02-14 18:23:40 +01:00
|
|
|
prune_archives(args.verbose, repository, retention_config)
|
|
|
|
check_archives(args.verbose, repository)
|
2014-12-02 07:35:25 +01:00
|
|
|
except (ValueError, IOError, CalledProcessError) as error:
|
2014-10-31 06:34:03 +01:00
|
|
|
print(error, file=sys.stderr)
|
|
|
|
sys.exit(1)
|