Skip to content

Commit

Permalink
使用 configparser,代码做相应调整
Browse files Browse the repository at this point in the history
  • Loading branch information
leeyisoft committed Sep 8, 2019
1 parent dde162f commit 0db8e86
Show file tree
Hide file tree
Showing 24 changed files with 395 additions and 349 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ settings.json
tests/*/logs/*
tests/*/logs/*.log
tests/*/logs/*/*.log
.env
98 changes: 98 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,108 @@
参考 下面Demo项目
run
```
pipenv install --skip-lock
pipenv shell
export ENV=local
python server.py --port=8080
```

f'{ROOT_PATH}/configs/{env}.ini' demo
```
# f'{ROOT_PATH}/configs/{env}.ini'
# 注意配置解析出来都是字符串,请不要带单引号或者双引号
# 例如 '0.0.0.0' "0.0.0.0" 都会报错
[sys]
arbitrary_ip = 0.0.0.0
port = 5080
local_ip = 127.0.0.1
translation = true
time_zone = Asia/Shanghai
language_code = zh-hans
login_pwd_rsa_encrypt = True
default_aes_secret = 883d65f06fd447f3a1e69a36e73f58e0
admin_session_key = de0b3fb0c2f44563944a8cccca7f225a
front_session_key = 171630947de24c969c28b2d178c4e0fe
valid_code_key = ab1195c6f0084b4f8b007d3aa7628a38
token_key = f30a2331813f46d0adc2bcf26fcbbbf4
rabbitmq_config =
sentry_url =
config_cache_prefix = conf:
user_cache_prefix = user:
admin_cache_prefix = admin:
# 超级管理员角色ID
super_role_id = 1
default_role_id = 2
[tornado]
debug = true
xsrf_cookies = true
xheaders = true
cookie_secret = e921bfcd-ace4-4124-8657-c57a162365f6
[session]
cache_alias = default_redis
name = nkzpg9NKBpKS2iaK
cookie_domain =
cookie_path = /
expires = 86400
secret = fLjUfxqXtfNoIldA0A0J
version = v0.1.0
[sqlalchemy]
# (s秒)
ping_db = 300
# 每次取出ping多少个连接
ping_conn_count = 5
connect_timeout = 3
echo = true
echo_pool = true
max_overflow = 10
pool_timeout = 5
encoding = utf8
pool_size = 5
pool_recycle = 3600
poolclass = QueuePool
[default_redis]
location = 127.0.0.1:6379
db = 0
password = abc123456
ping_interval = 120
parser_class = redis.connection.DefaultParser
socket_timeout = 2
socket_connect_timeout = 2
[redis]
host = 127.0.0.1
port = 6379
password = abc123456
charset = utf8
db = 3
[db_master]
driver = mysql+mysqldb
user = root
password = 123456
host = 127.0.0.1
port = 3306
database = db_py_admin
charset = utf8mb4
[db_slave]
driver = mysql+mysqldb
user = root
password = 123456
host = 127.0.0.1
port = 3306
database = db_py_admin
charset = utf8mb4
```

#### Demo
* [https://gitee.com/leeyi/py_admin](https://gitee.com/leeyi/py_admin/tree/dev/)
```
Expand Down
3 changes: 3 additions & 0 deletions demo.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# TREST_ENV is not one of the local, dev, test, or product
[sys]
TREST_ENV = dev
8 changes: 3 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,12 @@
'sqlalchemy',
'sqlalchemy-utils',
'redis==2.10.6',
'requests',
'PyJWT',
'python-dateutil',
'pytz',
'rsa',
'pycryptodome',
'pytz',
'python-dateutil',
'requests',
'raven',
'pika',
'pillow',
],
)
98 changes: 98 additions & 0 deletions tests/app_demo/configs/dev.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# f'{ROOT_PATH}/configs/{env}.ini'
# 注意配置解析出来都是字符串,请不要带单引号或者双引号
# 例如 '0.0.0.0' "0.0.0.0" 都会报错

[sys]
arbitrary_ip = 0.0.0.0
port = 5080
local_ip = 127.0.0.1
translation = true
time_zone = Asia/Shanghai
language_code = zh-hans
installed_app = app1
login_pwd_rsa_encrypt = True
default_aes_secret = 883d65f06fd447f3a1e69a36e73f58e0
admin_session_key = de0b3fb0c2f44563944a8cccca7f225a
front_session_key = 171630947de24c969c28b2d178c4e0fe
valid_code_key = ab1195c6f0084b4f8b007d3aa7628a38
token_key = f30a2331813f46d0adc2bcf26fcbbbf4
rabbitmq_config =
sentry_url =
config_cache_prefix = conf:
user_cache_prefix = user:
admin_cache_prefix = admin:

# 超级管理员角色ID
super_role_id = 1
default_role_id = 2

[tornado]
debug = true
xsrf_cookies = true
xheaders = true
cookie_secret = e921bfcd-ace4-4124-8657-c57a162365f6

[session]
cache_alias = default_redis
name = nkzpg9NKBpKS2iaK
cookie_domain =
cookie_path = /
expires = 86400
secret = fLjUfxqXtfNoIldA0A0J
version = v0.1.0

[sqlalchemy]
# (s秒)
ping_db = 300
# 每次取出ping多少个连接
ping_conn_count = 5
connect_timeout = 3
echo = true
echo_pool = true
max_overflow = 10
pool_timeout = 5
encoding = utf8
pool_size = 5
pool_recycle = 3600
poolclass = QueuePool

[default_redis]
location = 127.0.0.1:6379
db = 0
password = abc123456
ping_interval = 120
parser_class = redis.connection.DefaultParser
socket_timeout = 2
socket_connect_timeout = 2

[redis]
host = 127.0.0.1
port = 6379
password = abc123456
charset = utf8
db = 3

[db_master]
driver = mysql+mysqldb
user = root
password = 123456
host = 127.0.0.1
port = 3306
database = db_py_admin
charset = utf8mb4

[db_slave]
driver = mysql+mysqldb
user = root
password = 123456
host = 127.0.0.1
port = 3306
database = db_py_admin
charset = utf8mb4

[email]
from_name =
from_addr =
smtp_sever =
smtp_port =
auth_code =
8 changes: 0 additions & 8 deletions tests/app_demo/configs/dev.py

This file was deleted.

5 changes: 3 additions & 2 deletions trest/amqp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
# -*- coding: utf-8 -*-
import json

from trest.config import settings

from .publisher import Publisher
from ..utils import func
from ..settings_manager import settings


def push_message(msg, msg_type='transfer_websocket'):
Expand Down Expand Up @@ -53,7 +54,7 @@ def push_to_mq(param, option):
msg['msg_type'] = option.get('msg_type', '')
msg['msg_md5'] = func.md5(json.dumps(param))
msg['msg'] = param
pusher = Publisher(settings.rabbitmq_config)
pusher = Publisher(settings.sys.rabbitmq_config)
option['exchange_type'] = option.get('exchange_type', 'topic')
res = pusher.push(msg, option)
# print(res)
Expand Down
4 changes: 2 additions & 2 deletions trest/cache/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
from tornado.util import import_object
from tornado.ioloop import PeriodicCallback

from ..exception import ConfigError
from ..settings_manager import settings
from trest.config import settings

from ..exception import ConfigError
from .backends.base import InvalidCacheBackendError
from .backends.base import CacheKeyWarning
from .backends.base import BaseCache
Expand Down
Loading

0 comments on commit 0db8e86

Please sign in to comment.