Skip to content

Commit cfc0cb9

Browse files
committed
11.05 小节完成~
1 parent 0eaca2e commit cfc0cb9

File tree

5 files changed

+42
-24
lines changed

5 files changed

+42
-24
lines changed

basic/maintest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
Desc :
66
"""
77
import os
8+
import re
89

910

1011
if __name__ == '__main__':

basic/samples/generate_javabean.py renamed to basic/samples/excel/generate_javabean.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
BASE_DOMAIN = """
1212
_package_location_
1313
14-
import org.apache.commons.lang.builder.ToStringBuilder;
14+
import org.apache.commons.lang3.builder.ToStringBuilder;
1515
1616
import javax.persistence.GeneratedValue;
1717
import javax.persistence.GenerationType;
@@ -154,6 +154,7 @@ def underline_to_camel(underline_format, is_field=False):
154154
result = ''.join([s.capitalize() for s in underline_format.split('_')])
155155
return result[0].lower() + result[1:] if is_field else result
156156

157+
157158
def load_schema(filename):
158159
"""先加载schema.sql文件来获取所有建表语句"""
159160
result = []
@@ -173,8 +174,8 @@ def load_schema(filename):
173174
col_null = 'NOT NULL'
174175
else:
175176
col_null = ''
176-
col_remark = col_arr[-1]
177-
cr = col_remark.replace("'", "")
177+
col_remark = line.split(' COMMENT ')
178+
cr = col_remark[-1].strip().replace("'", "")
178179
each_table.append((col_name, col_type, col_null, cr[:-1] if cr.endswith(',') else cr))
179180
elif 'ENGINE=' in line:
180181
# 单个表定义结束
@@ -276,9 +277,9 @@ def write_beans(beans_dir, package_name, schema_name):
276277
if __name__ == '__main__':
277278
# print(camel_to_underline("CompanyServiceImpl"))
278279
# print(underline_to_camel("company_service_impl", True))
279-
# beans_dir = r'D:\work\zbeans'
280-
# package_name = r'com.winhong.fastloan.domain'
281-
# schema_name = r'D:\work\fastloan\trunk\fastloan\src\main\resources\sql\schema.sql'
282-
# write_beans(beans_dir, package_name, schema_name)
283-
write_beans(sys.argv[1], sys.argv[2], sys.argv[3])
280+
beans_dir = r'D:\work\zbeans\tobacco'
281+
package_name = r'com.cmback.tobacco.domain;'
282+
schema_name = r'D:\work\projects\gitprojects\tobacco\src\main\resources\sql\schema.sql'
283+
write_beans(beans_dir, package_name, schema_name)
284+
# write_beans(sys.argv[1], sys.argv[2], sys.argv[3])
284285
pass

basic/samples/excel/generate_schema.py

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from openpyxl.comments import Comment
1414
from openpyxl.styles import Style, PatternFill, Border, Side, Alignment, Protection, Font, Color
1515
from openpyxl.styles import colors, borders, fills
16+
import re
1617

1718

1819
def load_xlsx():
@@ -80,8 +81,10 @@ def write_only():
8081
def load_schema(filename):
8182
"""先加载schema.sql文件来获取所有建表语句"""
8283
result = []
84+
pat = re.compile(r'.* DEFAULT (\S+) .*')
8385
with open(filename, encoding='utf-8') as sqlfile:
8486
each_table = [] # 每张表定义
87+
temp_comment = ''
8588
for line in sqlfile:
8689
if line.startswith('--'):
8790
temp_comment = line.split('--')[1].strip()
@@ -96,9 +99,12 @@ def load_schema(filename):
9699
col_null = 'NOT NULL'
97100
else:
98101
col_null = ''
99-
col_remark = col_arr[-1]
100-
cr = col_remark.replace("'", "")
101-
each_table.append((col_name, col_type, col_null, cr[:-1] if cr.endswith(',') else cr))
102+
col_remark = line.split(' COMMENT ')
103+
cr = col_remark[-1].strip().replace("'", "")
104+
defaultmatch = pat.match(line)
105+
default = defaultmatch.group(1) if defaultmatch else ''
106+
each_table.append((col_name, col_type, col_null,
107+
default, cr[:-1] if cr.endswith(',') else cr))
102108
elif 'ENGINE=' in line:
103109
# 单个表定义结束
104110
result.append(list(each_table))
@@ -139,15 +145,17 @@ def write_dest(xlsx_name, schema_name):
139145

140146
for table in table_data:
141147
ws = wb.create_sheet(title=table[0])
142-
ws.merge_cells('E3:H3') # 合并单元格
148+
ws.merge_cells('E3:I3') # 合并单元格
143149
ws['E3'].style = title_style
144150
ws['F2'].style = Style(border=Border(
145151
bottom=Side(border_style=borders.BORDER_THIN, color='FF000000')))
146152
ws['G2'].style = Style(border=Border(
147153
bottom=Side(border_style=borders.BORDER_THIN, color='FF000000')))
148154
ws['H2'].style = Style(border=Border(
149155
bottom=Side(border_style=borders.BORDER_THIN, color='FF000000')))
150-
ws['I3'].style = Style(border=Border(
156+
ws['I2'].style = Style(border=Border(
157+
bottom=Side(border_style=borders.BORDER_THIN, color='FF000000')))
158+
ws['J3'].style = Style(border=Border(
151159
left=Side(border_style=borders.BORDER_THIN, color='FF000000')))
152160
ws['E3'] = table[0]
153161
ws['E4'].style = header_style
@@ -157,11 +165,14 @@ def write_dest(xlsx_name, schema_name):
157165
ws['G4'].style = header_style
158166
ws['G4'] = '空值约束'
159167
ws['H4'].style = header_style
160-
ws['H4'] = '备注'
168+
ws['H4'] = '默认值'
169+
ws['I4'].style = header_style
170+
ws['I4'] = '备注'
161171
ws.column_dimensions['E'].width = 20
162172
ws.column_dimensions['F'].width = 20
163-
ws.column_dimensions['G'].width = 16
164-
ws.column_dimensions['H'].width = 45
173+
ws.column_dimensions['G'].width = 12
174+
ws.column_dimensions['H'].width = 16
175+
ws.column_dimensions['I'].width = 45
165176
for idx, each_column in enumerate(table[2:]):
166177
ws['E{}'.format(idx + 5)].style = common_style
167178
ws['E{}'.format(idx + 5)] = each_column[0]
@@ -171,6 +182,8 @@ def write_dest(xlsx_name, schema_name):
171182
ws['G{}'.format(idx + 5)] = each_column[2]
172183
ws['H{}'.format(idx + 5)].style = common_style
173184
ws['H{}'.format(idx + 5)] = each_column[3]
185+
ws['I{}'.format(idx + 5)].style = common_style
186+
ws['I{}'.format(idx + 5)] = each_column[4]
174187
ws = wb['首页列表']
175188
ws.merge_cells('D3:F3')
176189
ws['D3'].style = title_style
@@ -180,7 +193,7 @@ def write_dest(xlsx_name, schema_name):
180193
bottom=Side(border_style=borders.BORDER_THIN, color='FF000000')))
181194
ws['G3'].style = Style(border=Border(
182195
left=Side(border_style=borders.BORDER_THIN, color='FF000000')))
183-
ws['D3'] = '贷快发数据库系统表'
196+
ws['D3'] = 'MySQL数据库系统表'
184197
ws['D4'].style = header_style
185198
ws['D4'] = '编号'
186199
ws['E4'].style = header_style
@@ -206,7 +219,8 @@ def write_dest(xlsx_name, schema_name):
206219
# write_xlsx()
207220
# write_only()
208221
import sys
209-
# dest_file = r'D:\work\fastloan\trunk\01文档\03系统设计\03数据库设计\贷快发MySQL数据库设计.xlsx'
210-
# sql_file = r'D:\work\fastloan\trunk\fastloan\src\main\resources\sql\schema.sql'
211-
write_dest(sys.argv[1], sys.argv[2])
222+
dest_file = r'D:\work\MySQL数据库设计.xlsx'
223+
schema_file = r'D:\work\projects\gitprojects\tobacco\src\main\resources\sql\schema.sql'
224+
write_dest(dest_file, schema_file)
225+
# write_dest(sys.argv[1], sys.argv[2])
212226
pass

basic/samples/excel/mysql_merge_table.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import datetime
1313
import mysql.connector
1414
from mysql.connector import errorcode
15+
import traceback
1516

1617
# 查询航信CRM表
1718
sql_select_taxcode_name = """
@@ -77,8 +78,8 @@ def _connect():
7778
config = {
7879
'user': 'root',
7980
'password': 'mysql',
80-
'host': '192.168.203.95',
81-
'database': 'fastloan_test',
81+
'host': '183.232.56.59',
82+
'database': 'fastloan3',
8283
'raise_on_warnings': True,
8384
}
8485
cnx = None
@@ -90,7 +91,7 @@ def _connect():
9091
elif err.errno == errorcode.ER_BAD_DB_ERROR:
9192
print("Database does not exist")
9293
else:
93-
print(err)
94+
traceback.print_exc()
9495
if cnx:
9596
cnx.close()
9697
return cnx
@@ -116,6 +117,7 @@ def merge_table():
116117
cursor.execute(sql_update_crm.format(*u_list))
117118
except:
118119
_log.error('--合并企业资料Exception,taxcode={},name={}--'.format(d2[0], d2[1]))
120+
traceback.print_exc()
119121
cursor.close()
120122
conn_.rollback()
121123
conn_.close()

source/c11/p05_creating_simple_rest_based_interface.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,4 +243,4 @@ WSGI被标准库支持,同时也被绝大部分第三方web框架支持。
243243
最后,当你准备进一步扩展你的程序的时候,你可以修改这个代码,让它可以为特定服务器工作。
244244

245245
WSGI本身是一个很小的标准。因此它并没有提供一些高级的特性比如认证、cookies、重定向等。
246-
这些你自己实现起来也不难。不过如果你想要更多的支持,可以考虑第三方库,比如 ``WebOb`` 或者 ``Paste``
246+
这些你自己实现起来也不难。不过如果你想要更多的支持,可以考虑第三方库,比如 ``WebOb`` 或者 ``Paste``

0 commit comments

Comments
 (0)