-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvertToTurboMode.py
More file actions
83 lines (68 loc) · 2.43 KB
/
convertToTurboMode.py
File metadata and controls
83 lines (68 loc) · 2.43 KB
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
__author__ = 'mmerth'
import sys
import csv
import re
def main(args):
tab_file = open(args[0])
csv_reader = csv.reader(tab_file, dialect='excel-tab')
for row in csv_reader:
# skip the line for the root name, we only want children of root.
if not str.isalnum(row[5]):
generate_turbo_mode_line(row)
def generate_turbo_mode_line(property_list):
# First 6 columns are as follows:
# Field?
# DataType
# Min
# Max
# Landmark
# Root name (don't need this, since we only want the children of root)
# Everything after are field/group names,
# and any empty string needs to be converted to '*'
isField = True
dataType = ""
minProp = ""
maxProp = ""
landmark = ""
# parse column A (Field?)
if re.match("n", str.lower(property_list[0])):
isField = False
# parse column B (DataType)
if re.match("number", str.lower(property_list[1])):
dataType = 'dataType="JDouble"'
elif re.match("date", str.lower(property_list[1])):
dataType = 'dataType="JDate"'
elif re.match("time", str.lower(property_list[1])):
dataType = 'dataType="JTime"'
# parse column C (Min)
if isField:
if str.isdigit(property_list[2]):
minProp = 'minLength="' + property_list[2] + '"'
else:
minProp = 'minLength="0"'
elif str.isdigit(property_list[2]):
minProp = 'min="' + property_list[2] + '"'
# parse column D (Max)
if isField and str.isdigit(property_list[3]):
maxProp = 'maxLength="' + property_list[3] + '"'
elif str.isdigit(property_list[3]):
maxProp = 'max="' + property_list[3] + '"'
# parse column E (Landmark)
if isField and str.isalnum(property_list[4]):
landmark = 'keyType="LANDMARK" defaultValue="' + property_list[4] + '"'
elif str.isalnum(property_list[4]):
landmark = 'isRecord="Y" type="' + property_list[4] + '"'
hierarchy = ""
# loop through all columns starting at column 7, building the hierarchy info.
# also try to clean up the names, and create repGroups
for column in property_list[6:]:
column = re.sub(r'\W', "", column)
if str.isalnum(column):
hierarchy += column
break
else:
hierarchy += "*"
turboLine = "%s %s %s %s %s" % (hierarchy, dataType, minProp, maxProp, landmark)
print(turboLine)
if __name__ == "__main__":
main(sys.argv[1:])