-
Notifications
You must be signed in to change notification settings - Fork 11
/
pattern_create.py
executable file
·39 lines (31 loc) · 1.12 KB
/
pattern_create.py
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
#!/usr/bin/python3
import sys
import argparse
from itertools import islice, cycle
from pattern import *
def main(argv=None):
argparser = argparse.ArgumentParser()
argparser.add_argument('length', type=int,
help='the length of the pattern')
argparser.add_argument('sets', nargs='*', default=DEFAULT_PATTERN_SETS,
help=('the character sets from which to create the '
'pattern'))
argparser.add_argument('-f', '--allow-repeats', action='store_true',
help='allow repeats in the pattern')
if argv is None:
args = argparser.parse_args()
else:
args = argparser.parse_args(argv)
try:
print(''.join(pattern_create(args.length, args.sets,
args.allow_repeats)))
except NotEnoughPermutationsError as e:
print(e, file=sys.stderr)
print('(use -f to ignore)', file=sys.stderr)
return 2
except ValueError as e:
print(e, file=sys.stderr)
return 1
return 0
if __name__ == '__main__':
sys.exit(main())