Skip to content

Commit

Permalink
避免 master/slave 等术语
Browse files Browse the repository at this point in the history
  • Loading branch information
leeyisoft committed Jul 17, 2020
1 parent 6e804d7 commit e052741
Show file tree
Hide file tree
Showing 7 changed files with 317 additions and 172 deletions.
299 changes: 213 additions & 86 deletions README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,119 +2,246 @@
* T = Tornado
* Rest = Restful

#### Description
Web MVC framework based on Tornado combined with asyncio
#### 介绍
基于Tornado结合asyncio的web mvc框架

#### Software Architecture
Software architecture description
依赖 Tornado SQLAlchemy pycryptodome pytz 等

#### Installation
* 开发约定 [https://gitee.com/leeyi/trest/blob/main/promise.md](https://gitee.com/leeyi/trest/blob/main/promise.md)
* 其他约定遵从[Python风格规范](http://zh-google-styleguide.readthedocs.io/en/latest/google-python-styleguide/python_language_rules/)[Python 编码规范](http://liyangliang.me/posts/2015/08/simple-python-style-guide/)

Put the following line of code into the Pipfile file [packages]
> trest = {editable = true,git = "https://gitee.com/leeyi/trest.git",ref = "master"}
#### 软件架构
```
tree -I '*svn|*node_module*|*git|py3|*.pyc|__pycache__|statics'
.
├── LICENSE
├── Pipfile
├── README.md
├── applications
│   ├── common
│   │   ├── const.py
│   │   ├── models
│   │   │   └── *.py
│   │   ├── assemblers
│   │   │   └── *.py
│   │   ├── services
│   │   │   └── *.py
│   │   └── utils.py
│   ├── app1
│   │   ├── handlers
│   │   │   └── *.py
│   │   ├── models
│   │   │   └── *.py
│   │   ├── modules.py
│   │   ├── services
│   │   │   └── *.py
│   │   ├── assemblers
│   │   │   └── *.py
│   │   ├── templates
│   │   │   └── */*.html
│   │   └── utils.py
│   └── app2
│   └── app3
├── configs
│   ├── dev.yaml
│   └── local.yaml
├── datas
│   ├── locales
│   │   ├── en_US.csv
│   │   └── zh_CN.csv
│   ├── menu
│   │   └── menu0.json
│   ├── mysql
│   │   └── *.sql
│   ├── nginx_vhost.conf
│   ├── production_deploy.md
│   ├── supervisor_tornado.conf
│   └── supervisord.conf
├── logs
│   └── *.log
├── server.py
└── tests
└── *_test.py
```
软件架构说明

* .env 环境配置文件,只有一个section [sys],一个变量 RUNTIME_ENV
* configs 应用配置文件
* configs/local.yaml 本地开发环境相关配置
* configs/dev.yaml 开发环境相关配置
* configs/test.yaml 测试环境相关配置
* configs/product.yaml 生产环境相关配置
* applications 应用rest api相关代码
* applications/common/models 公共应用数据模型层
* applications/common/services 公共应用服务层
* applications/common/assemblers 公共组装器层
* applications/common/const.py 公共应用常量
* applications/common/utils.py 公共应用助手函数
* applications/app1 独立应用
* applications/app1/handlers app1用控制器层,有路由器调用,负责接收并且校验参数
* applications/app1/services app1应用服务层,在控制器里面调用,负责一个业务逻辑
* applications/app1/models app1用数据模型层,在服务层调用,负责对一个数据库表CURD操作
* applications/app1/assemblers app1组装器层,在控制器里面调用,负责把服务层数据响应给API
* applications/app1/templates app1应用视图层,渲染service数据
* datas 数据
* datas/locales 多语言数据
* datas/json JSON数据文件
* datas/sql SQL数据文件
* \*\.* 其他数据文件
* logs 日志文件
* statics Web静态资源
* tests 测试脚本
* server.py 项目入口文件
* README.md 项目说明文件
* Pipfile pipenv配置文件
* LICENSE 开源许可证
* .gitignore Git忽略文件

#### 安装教程

把下面一行代码放入Pipfile文件 [packages]下面
> trest = {editable = true,git = "https://gitee.com/leeyi/trest.git",ref = "main"}
或者直接
> pipenv install -e git+https://gitee.com/leeyi/trest.git@main#egg=trest
或者
> pip install git+https://gitee.com/leeyi/trest.git
#### 使用说明
参考 下面Demo项目,

在项目根目录( ROOT_PATH )下面创建 server.py 文件
```
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
import resource
resource.setrlimit(resource.RLIMIT_NOFILE, (10240, 9223372036854775807))
from tornado.options import define
abs_file = os.path.abspath(sys.argv[0])
ROOT_PATH = abs_file[:abs_file.rfind('/')]
define('ROOT_PATH', ROOT_PATH)
# 把当前目录添加到 sys.path 开头
sys.path.insert(0, ROOT_PATH)
or
> pipenv install -e git+https://gitee.com/leeyi/trest.git@master#egg=trest
from trest.webserver import run
or
> pip install git+https://gitee.com/leeyi/trest.git#egg=trest
#### Instructions
After pipenv install under the root directory, add server.py
if __name__ == "__main__":
try:
server = run()
except KeyboardInterrupt:
sys.exit(0)
```

在 项目根目录( ROOT_PATH ) 下面创建 [.env 文件](https://gitee.com/leeyi/trest/blob/main/demo_dot.env)
```
# RUNTIME_ENV is not one of the local, dev, test, or product
# the colon must have Spaces around it
RUNTIME_ENV : local
```

run
```
pipenv install --skip-lock
pipenv shell
python server.py --port 8080
python server.py --port=5080
python tests/app_demo/server.py --port=5081
```

##### The API response
Use the raise JsonError wherever
```
from trest.exception import JsonError
f'{ROOT_PATH}/configs/{env}.yaml' demo

raise JsonError('msg')
raise JsonError('msg', 0)
raise JsonError('msg', 1, [])
raise JsonError('msg', 1, [1,2,3])
```
like this [./tests/app_demo/configs/dev.yaml](https://gitee.com/leeyi/trest/blob/main/tests/app_demo/configs/dev.yaml)

# [开发约定](https://gitee.com/leeyi/trest/blob/main/promise.md)

* 开发约定 [https://gitee.com/leeyi/trest/blob/main/promise.md](https://gitee.com/leeyi/trest/blob/main/promise.md)
* 其他约定遵从[Python风格规范](http://zh-google-styleguide.readthedocs.io/en/latest/google-python-styleguide/python_language_rules/)[Python 编码规范](http://liyangliang.me/posts/2015/08/simple-python-style-guide/)

#### Demo
* [https://gitee.com/leeyi/py_admin](https://gitee.com/leeyi/py_admin/tree/dev/)
```
from trest.exception import JsonError
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
[description]
"""
from trest.router import put
from trest.router import get
from trest.router import delete
from trest.router import post
from trest.router import put
from trest.router import delete
from trest.handler import Handler
from trest.exception import JsonError
"""
in applications/admin/handlers/abcd.py
# file name not start with _ and method name is unique
url like this,
/admin/welcome
/admin/welcome2
/welcome3
/admin/welcome4
"""
class WelcomeHandler(CommonHandler):
@get('welcome')
@required_permissions()
@tornado.web.authenticated
def welcome_get(self, *args, **kwargs):
"""后台首页
"""
# menu = AdminMenu.main_menu()
# print('menu ', menu)
# self.show('abc')
params = {
}
self.render('dashboard/welcome.html', **params)
@get('welcome2')
@required_permissions()
@tornado.web.authenticated
def welcome_get2(self, *args, **kwargs):
"""后台首页
"""
self.success(data=['welcome2'])
@get('/welcome3')
@required_permissions()
@tornado.web.authenticated
def welcome_get(self, *args, **kwargs):
"""后台首页
"""
self.success(data=['welcome3'])
@post('welcome4')
@required_permissions()
@tornado.web.authenticated
def welcome_post(self, *args, **kwargs):
"""后台首页
"""
self.success(data=['welcome3'])
class DemoHandler(Handler):
@post('demo0')
def add(self):
return self.success(data = ['post', 'demo0'])
class Demo1Handler(Handler):
@post('demo1')
def add(self):
return self.success(data = ['post', 'demo1'])
class Demo2Handler(Handler):
@get('demo2')
def get_demo2(self):
return self.success(data = ['get', 'demo2', ])
@get('demo2')
def get_demo2(self):
return self.success(data = ['get', 'demo23', ])
@delete('demo3/(?P<id>\d*)')
def del_demo3(self, id):
return self.success(data = ['delete', 'demo3', id])
@delete('demo2/(?P<id>\d*)')
def del_demo2(self, id):
return self.success(data = ['delete', 'demo2', id])
```

#### Test
##### API响应
在任意的地方使用 raise JsonError
```
pipenv install --skip-lock
from trest.exception import JsonError
raise JsonError('msg')
raise JsonError('msg', 0)
raise JsonError('msg', 1, [])
raise JsonError('msg', 1, [1,2,3])
```

#### Contribution
#### 避免 master/slave 等术语

Old | New | 说明
---|---|---
master | main | 主要的
slave | subordinate | 从属的
blacklist | denylist | 拒绝名单
whitelist | allowlist | 允许名单

#### 参与贡献

1. Fork the repository
2. Create Feat_xxx branch
3. Commit your code
4. Create Pull Request
1. Fork 本仓库
2. 新建 Feat_xxx 分支
3. 提交代码
4. 新建 Pull Request


#### Gitee Feature
#### 码云特技

1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md
2. Gitee blog [blog.gitee.com](https://blog.gitee.com)
3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore)
4. The most valuable open source project [GVP](https://gitee.com/gvp)
5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help)
6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md
2. 码云官方博客 [blog.gitee.com](https://blog.gitee.com)
3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解码云上的优秀开源项目
4. [GVP](https://gitee.com/gvp) 全称是码云最有价值开源项目,是码云综合评定出的优秀开源项目
5. 码云官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help)
6. 码云封面人物是一档用来展示码云会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
23 changes: 16 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

依赖 Tornado SQLAlchemy pycryptodome pytz 等

* 开发约定 [https://gitee.com/leeyi/trest/blob/master/promise.md](https://gitee.com/leeyi/trest/blob/master/promise.md)
* 开发约定 [https://gitee.com/leeyi/trest/blob/main/promise.md](https://gitee.com/leeyi/trest/blob/main/promise.md)
* 其他约定遵从[Python风格规范](http://zh-google-styleguide.readthedocs.io/en/latest/google-python-styleguide/python_language_rules/)[Python 编码规范](http://liyangliang.me/posts/2015/08/simple-python-style-guide/)

#### 软件架构
Expand Down Expand Up @@ -100,10 +100,10 @@ tree -I '*svn|*node_module*|*git|py3|*.pyc|__pycache__|statics'
#### 安装教程

把下面一行代码放入Pipfile文件 [packages]下面
> trest = {editable = true,git = "https://gitee.com/leeyi/trest.git",ref = "master"}
> trest = {editable = true,git = "https://gitee.com/leeyi/trest.git",ref = "main"}
或者直接
> pipenv install -e git+https://gitee.com/leeyi/trest.git@master#egg=trest
> pipenv install -e git+https://gitee.com/leeyi/trest.git@main#egg=trest
或者
> pip install git+https://gitee.com/leeyi/trest.git
Expand Down Expand Up @@ -140,7 +140,7 @@ if __name__ == "__main__":
```

在 项目根目录( ROOT_PATH ) 下面创建 [.env 文件](https://gitee.com/leeyi/trest/blob/master/demo_dot.env)
在 项目根目录( ROOT_PATH ) 下面创建 [.env 文件](https://gitee.com/leeyi/trest/blob/main/demo_dot.env)
```
# RUNTIME_ENV is not one of the local, dev, test, or product
# the colon must have Spaces around it
Expand All @@ -157,11 +157,11 @@ python tests/app_demo/server.py --port=5081

f'{ROOT_PATH}/configs/{env}.yaml' demo

like this [./tests/app_demo/configs/dev.yaml](https://gitee.com/leeyi/trest/blob/master/tests/app_demo/configs/dev.yaml)
like this [./tests/app_demo/configs/dev.yaml](https://gitee.com/leeyi/trest/blob/main/tests/app_demo/configs/dev.yaml)

# [开发约定](https://gitee.com/leeyi/trest/blob/master/promise.md)
# [开发约定](https://gitee.com/leeyi/trest/blob/main/promise.md)

* 开发约定 [https://gitee.com/leeyi/trest/blob/master/promise.md](https://gitee.com/leeyi/trest/blob/master/promise.md)
* 开发约定 [https://gitee.com/leeyi/trest/blob/main/promise.md](https://gitee.com/leeyi/trest/blob/main/promise.md)
* 其他约定遵从[Python风格规范](http://zh-google-styleguide.readthedocs.io/en/latest/google-python-styleguide/python_language_rules/)[Python 编码规范](http://liyangliang.me/posts/2015/08/simple-python-style-guide/)

#### Demo
Expand Down Expand Up @@ -220,6 +220,15 @@ raise JsonError('msg', 1, [])
raise JsonError('msg', 1, [1,2,3])
```

#### 避免 master/slave 等术语

Old | New | 说明
---|---|---
master | main | 主要的
slave | subordinate | 从属的
blacklist | denylist | 拒绝名单
whitelist | allowlist | 允许名单

#### 参与贡献

1. Fork 本仓库
Expand Down
Loading

0 comments on commit e052741

Please sign in to comment.