Skip to content

Commit e374608

Browse files
committed
reformat source with black for readability
1 parent 3657749 commit e374608

7 files changed

+1974
-2156
lines changed

get_schema.py

+51-30
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@
2828
# This is a map from type names (as returned by a 'describe'
2929
# operation) to synonymous type names.
3030

31-
type_map={
32-
'smallint(6)': 'smallint',
31+
type_map = {
32+
'smallint(6)': 'smallint',
3333
'mediumint(9)': 'mediumint',
34-
'tinyint(4)': 'tinyint',
35-
'int(11)': 'int',
36-
'bigint(20)': 'bigint',
37-
}
34+
'tinyint(4)': 'tinyint',
35+
'int(11)': 'int',
36+
'bigint(20)': 'bigint',
37+
}
3838

3939
# Given output from a 'describe table' operation, return a map from
4040
# column name to a map with the following entries:
41-
#
41+
#
4242
# 'Name': column name,
4343
# 'Default': default value (or "None"),
4444
# 'Type': type name,
@@ -48,6 +48,7 @@
4848
# Because almost all columns are "NOT NULL", that is the default, and
4949
# other columns are marked 'null' under 'Properties'.
5050

51+
5152
def reduce_columns(table, description, errors):
5253
columns = {}
5354
if table not in schema_remarks.column_remark:
@@ -73,42 +74,49 @@ def reduce_columns(table, description, errors):
7374
# More recent versions of Bugzilla show defaults for numeric types as '',
7475
# instead of (say) 0 or 0.00. This is not an actual schema change so we
7576
# normalise the default values.
76-
if (sqltype[-3:] == 'int' and default == ''):
77+
if sqltype[-3:] == 'int' and default == '':
7778
default = '0'
78-
if (sqltype == 'datetime' and default == ''):
79+
if sqltype == 'datetime' and default == '':
7980
default = '0000-00-00 00:00:00'
80-
if (sqltype[:7] == 'decimal' and (default == '' or default == None or float(default) == 0.0)):
81+
if sqltype[:7] == 'decimal' and (
82+
default == '' or default == None or float(default) == 0.0
83+
):
8184
default = "0.0"
8285
if default == '':
8386
default = "''"
8487
if default is None:
8588
default = 'None'
8689

87-
if (table in schema_remarks.column_renamed and
88-
name in schema_remarks.column_renamed[table]):
90+
if (
91+
table in schema_remarks.column_renamed
92+
and name in schema_remarks.column_renamed[table]
93+
):
8994
canonical_name = schema_remarks.column_renamed[table][name]
9095
else:
9196
canonical_name = name
9297
remark = None
9398
if canonical_name not in schema_remarks.column_remark[table]:
94-
errors.append("Table '%s' has no remark for column '%s'." % (table, canonical_name))
99+
errors.append(
100+
"Table '%s' has no remark for column '%s'." % (table, canonical_name)
101+
)
95102
else:
96103
remark = schema_remarks.column_remark[table][canonical_name]
97104
if remark is None:
98-
remarks=[]
105+
remarks = []
99106
elif type(remark) == list:
100-
remarks=remark
107+
remarks = remark
101108
else:
102-
remarks=[remark]
109+
remarks = [remark]
103110
columns[canonical_name] = {
104111
'Name': name,
105112
'Default': default,
106113
'Type': sqltype,
107114
'Properties': extra,
108115
'Remarks': remarks,
109-
}
116+
}
110117
return columns
111118

119+
112120
# Given output from "show index", return a map from index name to a
113121
# map with the following entries:
114122
#
@@ -117,7 +125,8 @@ def reduce_columns(table, description, errors):
117125
# 'Properties': A string with such properties as 'unique' and 'full text'
118126
# 'Remarks': A list of remarks.
119127

120-
foreign_key_index_re=re.compile('^fk_.*')
128+
foreign_key_index_re = re.compile('^fk_.*')
129+
121130

122131
def reduce_indexes(table, index_list, errors):
123132
indexes = {}
@@ -129,8 +138,10 @@ def reduce_indexes(table, index_list, errors):
129138
if foreign_key_index_re.match(kn):
130139
# a foreign key constraint; not really an index
131140
continue
132-
if (table in schema_remarks.index_renamed and
133-
kn in schema_remarks.index_renamed[table]):
141+
if (
142+
table in schema_remarks.index_renamed
143+
and kn in schema_remarks.index_renamed[table]
144+
):
134145
canon = schema_remarks.index_renamed[table][kn]
135146
else:
136147
canon = kn
@@ -145,30 +156,35 @@ def reduce_indexes(table, index_list, errors):
145156
props = str.join(', ', props)
146157
remark = None
147158
if canon not in schema_remarks.index_remark[table]:
148-
errors.append("Table '%s' has no remark for index '%s'." % (table, canon))
159+
errors.append(
160+
"Table '%s' has no remark for index '%s'." % (table, canon)
161+
)
149162
else:
150163
remark = schema_remarks.index_remark[table][canon]
151164
if remark:
152165
remarks = [remark]
153166
else:
154167
remarks = []
155-
indexes[canon] = {'Name': kn,
156-
'Fields': {i['Seq_in_index']: i['Column_name']},
157-
'Properties': props,
158-
'Remarks': remarks,
159-
}
168+
indexes[canon] = {
169+
'Name': kn,
170+
'Fields': {i['Seq_in_index']: i['Column_name']},
171+
'Properties': props,
172+
'Remarks': remarks,
173+
}
160174
# replace the 'Fields' map with an ordered list.
161175
for k in list(indexes.keys()):
162176
f = list(indexes[k]['Fields'].items())
163177
f.sort()
164178
indexes[k]['Fields'] = str.join(', ', list(map((lambda l: l[1]), f)))
165179
return indexes
166180

181+
167182
# Given a schema version name, get the schema for that database as a
168183
# map from table name to (columns, indexes), where columns is a map
169184
# produced by reduce_columns and indexes is a map produced by
170185
# reduce_indexes.
171186

187+
172188
def get_schema(schema_version, errors):
173189
f = None
174190
schema = {}
@@ -177,23 +193,28 @@ def get_schema(schema_version, errors):
177193
(sv, schema) = pickle.load(f)
178194
f.close()
179195
except FileNotFoundError:
180-
errors.append("Unable to locate schema data file for version %s" % (schema_version))
196+
errors.append(
197+
"Unable to locate schema data file for version %s" % (schema_version)
198+
)
181199
except Exception as e:
182200
errors.append("%s: %s" % (type(e).__name__, str(e)))
183201
tables = list(schema.keys())
184202
for table in tables:
185203
(columns, indexes) = schema[table]
186-
schema[table] = (reduce_columns(table, columns, errors),
187-
reduce_indexes(table, indexes, errors))
204+
schema[table] = (
205+
reduce_columns(table, columns, errors),
206+
reduce_indexes(table, indexes, errors),
207+
)
188208
return schema, errors
189209

210+
190211
# A. REFERENCES
191212
#
192213
#
193214
# B. DOCUMENT HISTORY
194215
#
195216
# 2004-11-11 NB Created, partly from make_schema_doc.py.
196-
#
217+
#
197218
#
198219
# C. COPYRIGHT AND LICENSE
199220
#

index.cgi

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/python3
2-
#
2+
#
33
# Ravenbrook
44
# <http://www.ravenbrook.com/>
55
#
@@ -14,8 +14,9 @@
1414
# rather than having it obscured by this CGI front-end.
1515

1616
from index import *
17+
1718
if __name__ == '__main__':
18-
show_page()
19+
show_page()
1920

2021
# A. REFERENCES
2122
#

0 commit comments

Comments
 (0)