-
Notifications
You must be signed in to change notification settings - Fork 0
/
namegen
executable file
·55 lines (52 loc) · 1.56 KB
/
namegen
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
#!/usr/bin/env python3
# -*- mode: python-mode;
# coding: utf-8
import os
import argparse
import pprint
import readline
generators = [name.split('.')[0] for name in os.listdir(
'generators') if os.path.isfile('generators/' + name) and
not name.startswith('_')]
parser = argparse.ArgumentParser()
parser.add_argument('-l', '--list',
help='List available generators', action="store_true")
parser.add_argument('-t', '--type',
help='Type of generator', action='store')
parser.add_argument('--var', help='A variable that can be be requested by generator',
action='store')
parser.add_argument('-n', '--num',
help='Number of names', action='store')
args = parser.parse_args()
if args.list:
pprint.pprint(sorted(generators), compact=True, indent=1)
exit(0)
if args.type:
if args.type not in generators:
print('Generator {} does not exists!'.format(args.type))
exit(1)
if args.var:
var = args.var
else:
var = ''
if args.num:
try:
num = int(args.num)
if num <= 0:
raise ValueError
except ValueError as e:
print("'num' should be positive 'int'")
exit(1)
else:
num = 1
code = 'from generators.{} import {};values = list({}.nameGen({}))'.format(
args.type, args.type,
args.type, var
)
result = []
for _ in range((num - 1) // 10 + 1):
exec(code)
result += values.copy()
print(result[:num])
exit(0)
parser.print_usage()