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:])
|
2015-05-11 07:00:31 +02:00
|
|
|
config = parse_configuration(args.config_filename)
|
|
|
|
repository = config.location['repository']
|
2014-10-31 06:34:03 +01:00
|
|
|
|
2015-05-11 07:00:31 +02:00
|
|
|
create_archive(args.excludes_filename, args.verbose, **config.location)
|
|
|
|
prune_archives(args.verbose, repository, config.retention)
|
|
|
|
check_archives(args.verbose, repository, config.consistency)
|
2015-03-15 18:44:18 +01:00
|
|
|
except (ValueError, IOError, CalledProcessError) as error:
|
2014-10-31 06:34:03 +01:00
|
|
|
print(error, file=sys.stderr)
|
|
|
|
sys.exit(1)
|