main.py
2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# coding: utf-8
from flask import Flask,Blueprint
import threading
from apps.api.http_serv import tx1_box
from apps.api.ws_serv import Server
import apps.gbvar.ws_serv_global as sv_global
import apps.gbvar.database_global as database
import apps.gbvar.dict_properties as dict_p
import fdb
import sys
import os
from apps.commons.util import *
app = Flask(__name__, static_folder='apps/static')
# 获取本脚本所在的路径
pro_path = os.path.split(os.path.realpath(__file__))[0]
#配置文件路径
con_path = '/'.join((pro_path, 'special.properties'))
print con_path
dictProperties=Properties(con_path).getProperties()
# 创建路由
app.register_blueprint(tx1_box, url_prefix='/api/v1/tx1_box')
def start_ws(host,port):
try:
sv_global._init ()
__sv = Server(host,port)
sv_global.set_value(__sv)
except Exception,e:
print e.message
return
def thread_start(__sv):
__sv.listen_client ()
#系统初始化数据库
def init():
database._init()
dict_p._init()
dict_p.set_value(dictProperties)
###===================database=============================
con = fdb.connect ( host=dictProperties['tx1_host'], database=dictProperties['datasource_url'], user='sysdba',
password='masterkey',
charset='UTF8' )
cur = con.cursor ()
database.set_value(cur)
'''newLanguages = [
(1, 'Dylan')
]
cur.executemany ( "insert into tb_traffic(id,name) VALUES(?,?)",
newLanguages
)
con.commit ()
sql_select = 'select * from tb_traffic'
# 显示全部内容
cur.execute ( sql_select )
print(cur.fetchall ())
cur.close ()
con.close ()'''
####====================database===================
#启动服务
if __name__=='__main__':
#init()
_h=dictProperties['tx1_host']
_p=int(dictProperties['tx1_ws_port'])
start_ws(_h,_p)
print sv_global.get_value()
t1 = threading.Thread ( target=thread_start, name='start_ws_serv', args={sv_global.get_value (), } )
t1.start ()
print 'sv_global.get_value()=%s' % sv_global.get_value ()
# 启动http
app.run (
host=dictProperties['tx1_host'],
port=int(dictProperties['tx1_http_port'] ),debug=False,threaded=True)