Skip to content

Commit

Permalink
fix: add argument validation for contrib/pcp.py (s3ql#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
d--j authored Nov 2, 2020
1 parent 27d28b1 commit f74bfcd
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions contrib/pcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import sys
import os
import subprocess
from argparse import ArgumentTypeError

# We are running from the S3QL source directory, make sure
# that we use modules from this directory
Expand All @@ -26,6 +27,16 @@

log = logging.getLogger(__name__)

pool = ('abcdefghijklmnopqrstuvwxyz',
'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
'0123456789')

def processes_to_int(string):
value = int(string)
if value < 2 or value > len(pool[0]) + 1:
raise ArgumentTypeError("%d needs to be between 2 and %d (inclusive)" % (value, len(pool[0]) + 1))
return value

def parse_args(args):
'''Parse command line'''

Expand All @@ -40,7 +51,7 @@ def parse_args(args):

parser.add_argument("-a", action="store_true",
help='Pass -aHAX option to rsync.')
parser.add_argument("--processes", action="store", type=int, metavar='<no>',
parser.add_argument("--processes", action="store", type=processes_to_int, metavar='<no>',
default=10,
help='Number of rsync processes to use (default: %(default)s).')

Expand All @@ -61,9 +72,6 @@ def main(args=None):
options = parse_args(args)
setup_logging(options)

pool = ('abcdefghijklmnopqrstuvwxyz',
'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
'0123456789')
steps = [ len(x) / (options.processes - 1) for x in pool ]
prefixes = list()
for i in range(options.processes - 1):
Expand Down

0 comments on commit f74bfcd

Please sign in to comment.