Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
path: root/cmdline.py
blob: 4436df0e3147813d1d943d506eb5f6f90edfc632 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# cmdline.py - functions for handling command-line arguments
#
# Copyright (C) 2015 Arthur de Jong
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
#
# The files produced as output from the software do not automatically fall
# under the copyright of the software, unless explicitly stated otherwise.

import argparse


class VersionAction(argparse.Action):

    def __init__(self, option_strings, dest,
                 help='output version information and exit'):
        super(VersionAction, self).__init__(
            option_strings=option_strings,
            dest=argparse.SUPPRESS,
            default=argparse.SUPPRESS,
            nargs=0,
            help=help)

    def __call__(self, parser, namespace, values, option_string=None):
        print('''
backupscript 0.0
Written by Arthur de Jong.

Copyright (C) 2015 Arthur de Jong.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
        '''.strip())
        parser.exit()


# command-line options that are shared between all commands
global_options = argparse.ArgumentParser(add_help=False)
global_options.add_argument(
    '-V', '--version', action=VersionAction)
global_options.add_argument(
    '--cache-dir', metavar='DIR',
    help='directory containing local meta-data cache')


# set up command line parser
parser = argparse.ArgumentParser(parents=[global_options])
parser.add_argument(
    'repository', metavar='URL',
    help='the location of the backup repository')
subparsers = parser.add_subparsers(metavar='COMMAND', dest='command')


# the backup command
backup_command = subparsers.add_parser(
    'backup', parents=[global_options],
    help='backup files to the repository')
backup_command.add_argument(
    'files', metavar='PATH', nargs='*',
    help='directories and files to backup')
backup_command.add_argument(
    '--encryption', choices=('gpg', 'none'),
    help='the encryption mechanism to use')
backup_command.add_argument(
    '--compression', choices=('gzip', 'bzip2', 'xz', 'none'),
    help='the compression mechanism to use')
backup_command.add_argument(
    '--block-size', metavar='SIZE', type=int,
    help='target size of newly created archive files')
backup_command.add_argument(
    '--archive-min-perc', metavar='PERCENTAGE',
    help='ignore existing archives that have lower useful data')
backup_command.add_argument(
    '--archive-use-extractlist', metavar='PERCENTAGE',
    help='use an extractlist when use drops below percentage')

# the set-keys command
set_keys_command = subparsers.add_parser(
    'set-keys', parents=[global_options],
    help='configure keys that can decrypt the backup')
set_keys_command.add_argument(
    'keys', metavar='KEYID', nargs='+',
    help='the GnuPG key IDs used for encryption')