-
Notifications
You must be signed in to change notification settings - Fork 0
/
pgsql-generator.py
61 lines (54 loc) · 1.57 KB
/
pgsql-generator.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#===================================================
# Created by Ramesh Sivaraman, Percona LLC #
#===================================================
import getopt
import sys
import os
import random
import createsql
def usage():
print("Usage: [ options ]")
print (" pgsql-generator.py --lines=1000 --outfile=pgsql.sql")
print ("")
print("Options:")
print(" -l, --lines=<number> Specify number of lines to generate")
print(" -o, --outfile=<filename> Specify SQL output file name")
print(" -v, --version print version number")
print(" -h, --help print usage info")
try:
opts, args = getopt.getopt(sys.argv[1:],"l:o:vh",["lines=","outfile=","version","help"])
except getopt.GetoptError as err:
print('ERROR:', err)
print("")
usage()
sys.exit(2)
lines = ""
outfile = ""
if len(sys.argv) == 1:
usage()
sys.exit()
for opt, arg in opts:
if opt in ("-v","--version"):
print ('1.0')
sys.exit()
elif opt in ("-h","--help"):
usage()
sys.exit()
elif opt in ("-l", "--lines"):
lines = int(arg)
elif opt in ("-o", "--outfile"):
outfile = arg
if lines == "":
LINE_COUNT = 100
else:
LINE_COUNT = lines
OUTFILE = "/tmp/" + outfile
#for num in range(LINE_COUNT):
# print(num)
columncount = int(15*LINE_COUNT/100)
tblcount = int(15*LINE_COUNT/100)
createsql.OutFile(OUTFILE)
createsql.CreateTable(tblcount, columncount)
createsql.DropTable(tblcount)
sys.stdout = sys.__stdout__
print("DONE! Generated " + OUTFILE)