Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Q
quick_generator
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Lv xiang
quick_generator
Commits
631fe7b5
Commit
631fe7b5
authored
Jun 14, 2018
by
xxlv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add some color
parent
fa0b832b
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
63 deletions
+34
-63
workspace.xml
.idea/workspace.xml
+5
-36
gen.py
gen.py
+29
-27
No files found.
.idea/workspace.xml
View file @
631fe7b5
...
...
@@ -3,8 +3,6 @@
<component
name=
"ChangeListManager"
>
<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$/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>
<option
name=
"EXCLUDED_CONVERTED_TO_IGNORED"
value=
"true"
/>
<option
name=
"TRACKING_ENABLED"
value=
"true"
/>
...
...
@@ -21,8 +19,8 @@
<file
leaf-file-name=
"gen.py"
pinned=
"false"
current-in-tab=
"true"
>
<entry
file=
"file://$PROJECT_DIR$/gen.py"
>
<provider
selected=
"true"
editor-type-id=
"text-editor"
>
<state
relative-caret-position=
"
52
1"
>
<caret
line=
"4
26"
selection-start-line=
"426"
selection-end-line=
"426
"
/>
<state
relative-caret-position=
"
28
1"
>
<caret
line=
"4
40"
lean-forward=
"true"
selection-start-line=
"440"
selection-end-line=
"440
"
/>
<folding>
<element
signature=
"e#42#51#0"
expanded=
"true"
/>
</folding>
...
...
@@ -30,33 +28,6 @@
</provider>
</entry>
</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>
</component>
<component
name=
"FindInProjectRecents"
>
...
...
@@ -568,15 +539,13 @@
</entry>
<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>
<state
relative-caret-position=
"-90"
/>
</provider>
</entry>
<entry
file=
"file://$PROJECT_DIR$/gen.py"
>
<provider
selected=
"true"
editor-type-id=
"text-editor"
>
<state
relative-caret-position=
"
52
1"
>
<caret
line=
"4
26"
selection-start-line=
"426"
selection-end-line=
"426
"
/>
<state
relative-caret-position=
"
28
1"
>
<caret
line=
"4
40"
lean-forward=
"true"
selection-start-line=
"440"
selection-end-line=
"440
"
/>
<folding>
<element
signature=
"e#42#51#0"
expanded=
"true"
/>
</folding>
...
...
gen.py
View file @
631fe7b5
...
...
@@ -11,7 +11,8 @@ DIR = "./template"
TMP
=
"./tmp"
JAR_PATH
=
"./jar"
MYBATIS_GEN_JAVA_PATH
=
"{}/java"
.
format
(
TMP
)
PO
=
""
PO
=
""
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_dao_path"
]
=
service_dao_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
():
if
(
not
os
.
path
.
exists
(
path
)):
...
...
@@ -123,7 +125,7 @@ def safe_cpfile(f, target_path_map, res_name):
def
is_dto
(
path
):
return
path
[
-
8
:]
==
"Dto.java"
return
path
[
-
8
:]
==
"Dto.java"
def
is_po
(
res_name
,
identity
):
...
...
@@ -229,7 +231,6 @@ def gen_po(res_name, project_target_path):
po
=
f
.
read
()
return
po
...
...
@@ -246,7 +247,6 @@ def compile_content(res_name, compile_table, origin, tmp, project_target_path):
"""
global
PO
res_name
=
get_res_name
(
res_name
)
if
not
os
.
path
.
isdir
(
tmp
):
os
.
mkdir
(
tmp
)
...
...
@@ -266,7 +266,7 @@ def compile_content(res_name, compile_table, origin, tmp, project_target_path):
with
open
(
identity
,
"w+"
)
as
f
:
po_body
=
gen_po
(
res_name
,
project_target_path
)
PO
=
po_body
PO
=
po_body
f
.
write
(
po_body
)
print
(
"--------------------------------"
)
...
...
@@ -339,8 +339,16 @@ def get_table_name(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
"""
核心逻辑
...
...
@@ -407,39 +415,33 @@ def gen(res_name, look_path):
PROJECT_TARGET_PATH
)
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
)
if
(
matchObj
is
not
None
):
PO
=
matchObj
.
group
(
2
)
if
(
matchObj
is
not
None
):
PO
=
matchObj
.
group
(
2
)
print
(
PO
)
if
PO
[
-
1
]
!=
"}"
:
PO
+=
"
\n
}"
if
PO
[
-
1
]
!=
"}"
:
PO
+=
"
\n
}"
po_body
=
PO
po_body
=
PO
for
compiled_file
in
compiled_file_list
:
if
is_dto
(
compiled_file
):
with
open
(
compiled_file
,
"r+"
)
as
f
:
dto_body
=
f
.
read
()
dto_body
=
dto_body
.
replace
(
"${PO}"
,
po_body
)
with
open
(
compiled_file
,
"r+"
)
as
f
:
dto_body
=
f
.
read
()
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
)
safe_cpfile
(
compiled_file
,
PROJECT_TARGET_PATH
,
res_name
)
# clean_tmp()
clean_tmp
()
run_tests
(
PROJECT_TARGET_PATH
[
"base_path"
])
print
(
"---------------------------------------------"
)
print
(
"你已经成功的生成了代码"
)
print
(
"
\033
[27;32;40m
\t
恭喜~~你的工作完成了
\033
[0m"
)
print
(
"---------------------------------------------"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment