Skip to content

Commit 3d894d5

Browse files
author
pedro
committed
feat:支持插件模板自动生成
1 parent 8f9f65c commit 3d894d5

6 files changed

Lines changed: 80 additions & 4 deletions

File tree

Pipfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ cymysql = "==0.9.1"
1111
flask-cors = "==2.1.0"
1212
requests = "==2.18.4"
1313
pipfile = "*"
14-
lin-cms = "==0.1.1a2"
14+
lin-cms = "==0.1.1a3"
1515
"oss2" = "*"
1616

1717
[dev-packages]

app/api/cms/notify.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,5 @@ def event_stream():
7878
yield sser.pop()
7979
else:
8080
yield sser.heartbeat()
81-
# 每个5秒发送一次心跳
82-
time.sleep(5)
81+
# 每个3秒发送一次心跳
82+
time.sleep(3)

app/plugins/oss/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# oss 插件
2+
3+
## 插件模板自动生成
4+
5+
## 添加requirements.txt

app/plugins/oss/requirements.txt

Whitespace-only changes.

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Flask-WTF==0.14.2
1010
idna==2.6
1111
itsdangerous==1.1.0
1212
Jinja2==2.10
13-
Lin-CMS==0.1.1a1
13+
Lin-CMS==0.1.1a3
1414
MarkupSafe==1.1.0
1515
pipfile==0.0.2
1616
PyJWT==1.7.1

vendor/plugin_generator.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
"""
2+
:copyright: © 2019 by the Lin team.
3+
:license: MIT, see LICENSE for more details.
4+
"""
5+
import argparse
6+
import os
7+
8+
banner = """
9+
\"""
10+
:copyright: © 2019 by the Lin team.
11+
:license: MIT, see LICENSE for more details.
12+
\"""
13+
"""
14+
15+
controller = """
16+
from lin.redprint import Redprint
17+
18+
{0}_api = Redprint("{0}")
19+
20+
21+
@{0}_api.route("/", methods=["GET"])
22+
def test():
23+
return "hi, guy!"
24+
"""
25+
26+
init = """
27+
from .controller import {0}_api
28+
"""
29+
30+
info = """
31+
__name__ = '{0}'
32+
__version__ = '0.1.0'
33+
__author__ = 'Team Lin'
34+
"""
35+
36+
readme = """# {0}"""
37+
38+
39+
def create_plugin(name: str):
40+
cmd = os.getcwd()
41+
plugins_path = os.path.join(cmd, "app/plugins")
42+
plugindir = os.path.join(plugins_path, name)
43+
os.mkdir(plugindir)
44+
45+
open(os.path.join(plugindir, "config.py"), mode="x", encoding="utf-8")
46+
open(os.path.join(plugindir, "requirements.txt"), mode="x", encoding="utf-8")
47+
48+
with open(os.path.join(plugindir, "info.py"), mode="x", encoding="utf-8") as f:
49+
f.write(banner + info.format(name))
50+
51+
with open(os.path.join(plugindir, "README.md"), mode="x", encoding="utf-8") as f:
52+
f.write(readme.format(name))
53+
54+
appdir = os.path.join(plugindir, "app")
55+
os.mkdir(appdir)
56+
57+
with open(os.path.join(appdir, "__init__.py"), mode="x", encoding="utf-8") as f:
58+
f.write(banner + init.format(name))
59+
60+
with open(os.path.join(appdir, "controller.py"), mode="x", encoding="utf-8") as f:
61+
f.write(banner + controller.format(name))
62+
63+
open(os.path.join(appdir, "model.py"), mode="x", encoding="utf-8")
64+
65+
66+
if __name__ == '__main__':
67+
parser = argparse.ArgumentParser(usage="it's usage tip.", description="help info.")
68+
parser.add_argument("-n", "--name", default="tpl", help="the name of plugin", dest="name")
69+
args = parser.parse_args()
70+
name = args.name
71+
create_plugin(name)

0 commit comments

Comments
 (0)