Commit 631fe7b5 by xxlv

Add some color

parent fa0b832b
...@@ -3,8 +3,6 @@ ...@@ -3,8 +3,6 @@
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="1abc04e8-e167-42cd-98ea-074bbb2150ed" name="Default" comment=""> <list default="true" id="1abc04e8-e167-42cd-98ea-074bbb2150ed" name="Default" comment="">
<change beforePath="$PROJECT_DIR$/gen.py" beforeDir="false" afterPath="$PROJECT_DIR$/gen.py" afterDir="false" /> <change beforePath="$PROJECT_DIR$/gen.py" beforeDir="false" afterPath="$PROJECT_DIR$/gen.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/template/${PLACE}ReqDto.java" beforeDir="false" afterPath="$PROJECT_DIR$/template/${PLACE}ReqDto.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/template/${PLACE}RespDto.java" beforeDir="false" afterPath="$PROJECT_DIR$/template/${PLACE}RespDto.java" afterDir="false" />
</list> </list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" /> <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="TRACKING_ENABLED" value="true" /> <option name="TRACKING_ENABLED" value="true" />
...@@ -21,8 +19,8 @@ ...@@ -21,8 +19,8 @@
<file leaf-file-name="gen.py" pinned="false" current-in-tab="true"> <file leaf-file-name="gen.py" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/gen.py"> <entry file="file://$PROJECT_DIR$/gen.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="521"> <state relative-caret-position="281">
<caret line="426" selection-start-line="426" selection-end-line="426" /> <caret line="440" lean-forward="true" selection-start-line="440" selection-end-line="440" />
<folding> <folding>
<element signature="e#42#51#0" expanded="true" /> <element signature="e#42#51#0" expanded="true" />
</folding> </folding>
...@@ -30,33 +28,6 @@ ...@@ -30,33 +28,6 @@
</provider> </provider>
</entry> </entry>
</file> </file>
<file leaf-file-name="AbnormalOrder.java" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/tmp/AbnormalOrder.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-1479">
<caret line="4" column="28" selection-start-line="4" selection-start-column="28" selection-end-line="4" selection-end-column="28" />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="${PLACE}ReqDto.java" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/template/${PLACE}ReqDto.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="60">
<caret line="4" selection-start-line="4" selection-end-line="4" />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="${PLACE}RespDto.java" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/template/${PLACE}RespDto.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="60">
<caret line="4" column="30" selection-start-line="4" selection-start-column="30" selection-end-line="4" selection-end-column="30" />
</state>
</provider>
</entry>
</file>
</leaf> </leaf>
</component> </component>
<component name="FindInProjectRecents"> <component name="FindInProjectRecents">
...@@ -568,15 +539,13 @@ ...@@ -568,15 +539,13 @@
</entry> </entry>
<entry file="file://$PROJECT_DIR$/tmp/AbnormalOrder.java"> <entry file="file://$PROJECT_DIR$/tmp/AbnormalOrder.java">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-1479"> <state relative-caret-position="-90" />
<caret line="4" column="28" selection-start-line="4" selection-start-column="28" selection-end-line="4" selection-end-column="28" />
</state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/gen.py"> <entry file="file://$PROJECT_DIR$/gen.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="521"> <state relative-caret-position="281">
<caret line="426" selection-start-line="426" selection-end-line="426" /> <caret line="440" lean-forward="true" selection-start-line="440" selection-end-line="440" />
<folding> <folding>
<element signature="e#42#51#0" expanded="true" /> <element signature="e#42#51#0" expanded="true" />
</folding> </folding>
......
...@@ -11,7 +11,8 @@ DIR = "./template" ...@@ -11,7 +11,8 @@ DIR = "./template"
TMP = "./tmp" TMP = "./tmp"
JAR_PATH = "./jar" JAR_PATH = "./jar"
MYBATIS_GEN_JAVA_PATH = "{}/java".format(TMP) MYBATIS_GEN_JAVA_PATH = "{}/java".format(TMP)
PO="" PO = ""
def parse_ydl_project(path): def parse_ydl_project(path):
""" """
...@@ -65,6 +66,7 @@ def parse_ydl_project(path): ...@@ -65,6 +66,7 @@ def parse_ydl_project(path):
d["service_sql_xml_path"] = service_sql_xml_path d["service_sql_xml_path"] = service_sql_xml_path
d["service_dao_path"] = service_dao_path d["service_dao_path"] = service_dao_path
d["mybatis_config_path"] = service_sql_mybatis_generator_config_path d["mybatis_config_path"] = service_sql_mybatis_generator_config_path
d["base_path"] = "/".join(abs_path + [identity, project_prefix])
for id, path in d.iteritems(): for id, path in d.iteritems():
if (not os.path.exists(path)): if (not os.path.exists(path)):
...@@ -123,7 +125,7 @@ def safe_cpfile(f, target_path_map, res_name): ...@@ -123,7 +125,7 @@ def safe_cpfile(f, target_path_map, res_name):
def is_dto(path): def is_dto(path):
return path[-8:]=="Dto.java" return path[-8:] == "Dto.java"
def is_po(res_name, identity): def is_po(res_name, identity):
...@@ -229,7 +231,6 @@ def gen_po(res_name, project_target_path): ...@@ -229,7 +231,6 @@ def gen_po(res_name, project_target_path):
po = f.read() po = f.read()
return po return po
...@@ -246,7 +247,6 @@ def compile_content(res_name, compile_table, origin, tmp, project_target_path): ...@@ -246,7 +247,6 @@ def compile_content(res_name, compile_table, origin, tmp, project_target_path):
""" """
global PO global PO
res_name = get_res_name(res_name) res_name = get_res_name(res_name)
if not os.path.isdir(tmp): if not os.path.isdir(tmp):
os.mkdir(tmp) os.mkdir(tmp)
...@@ -266,7 +266,7 @@ def compile_content(res_name, compile_table, origin, tmp, project_target_path): ...@@ -266,7 +266,7 @@ def compile_content(res_name, compile_table, origin, tmp, project_target_path):
with open(identity, "w+") as f: with open(identity, "w+") as f:
po_body = gen_po(res_name, project_target_path) po_body = gen_po(res_name, project_target_path)
PO=po_body PO = po_body
f.write(po_body) f.write(po_body)
print("--------------------------------") print("--------------------------------")
...@@ -339,8 +339,16 @@ def get_table_name(res_name): ...@@ -339,8 +339,16 @@ def get_table_name(res_name):
return hump2underline(res_name) return hump2underline(res_name)
def gen(res_name, look_path): def run_tests(path):
c = """
cd {} && mvn clean test
""".format(path)
if os.path.isdir(path) and os.path.exists(os.path.join(path, "pom.xml")):
os.system(c)
def gen(res_name, look_path):
global PO global PO
""" """
核心逻辑 核心逻辑
...@@ -407,39 +415,33 @@ def gen(res_name, look_path): ...@@ -407,39 +415,33 @@ def gen(res_name, look_path):
PROJECT_TARGET_PATH) PROJECT_TARGET_PATH)
compiled_file_list.append(compiled_file) compiled_file_list.append(compiled_file)
# safe_cpfile(compiled_file, PROJECT_TARGET_PATH, res_name)
# 考虑生成dto
# PO="""
# Cats are {smarter} than dogs
#
# """
matchObj = re.match("[\s\S]+class (\w+) {([\s\S]+)}(.*?)[\s\S]+", PO) matchObj = re.match("[\s\S]+class (\w+) {([\s\S]+)}(.*?)[\s\S]+", PO)
if(matchObj is not None): if (matchObj is not None):
PO=matchObj.group(2) PO = matchObj.group(2)
print(PO) print(PO)
if PO[-1]!="}": if PO[-1] != "}":
PO+="\n }" PO += "\n }"
po_body=PO po_body = PO
for compiled_file in compiled_file_list: for compiled_file in compiled_file_list:
if is_dto(compiled_file): if is_dto(compiled_file):
with open(compiled_file,"r+") as f: with open(compiled_file, "r+") as f:
dto_body=f.read() dto_body = f.read()
dto_body=dto_body.replace("${PO}",po_body) dto_body = dto_body.replace("${PO}", po_body)
with open(compiled_file,"w+") as f: with open(compiled_file, "w+") as f:
f.write(dto_body) f.write(dto_body)
safe_cpfile(compiled_file, PROJECT_TARGET_PATH, res_name) safe_cpfile(compiled_file, PROJECT_TARGET_PATH, res_name)
# clean_tmp() clean_tmp()
run_tests(PROJECT_TARGET_PATH["base_path"])
print("---------------------------------------------") print("---------------------------------------------")
print("你已经成功的生成了代码") print("\033[27;32;40m\t恭喜~~你的工作完成了\033[0m")
print("---------------------------------------------") print("---------------------------------------------")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment