Commit cc1c2b35 by 熊付

【任务相关接口】

1 parent c42238a6
......@@ -22,12 +22,14 @@ def dataRecv():
send_all_data(sv_global.get_value(),data)
return data
@tx1_box.route('/test', methods=["GET"])
def test():
return "test"
# 给所有用户发送信息
def send_all_data(sv, data):
if sv.users is not None and len ( sv.users ) > 0:
for addr in sv.users:
print 'addr=%s' % addr
print ('addr=%s' % addr)
sv.send_data (data, addr )
......@@ -71,4 +73,12 @@ def creat_mtasks():
return mtasks
#读取任务信息参数
def readerXml(file_path):
return editXml.readerXml ( file_path )
\ No newline at end of file
return editXml.readerXml ( file_path )
@tx1_box.route('/pic_cut', methods=["POST"])
def post_test():
data_1 = request.get_data ()
print data_1
data = {}
data.setdefault('pic_base64','123123123123123123123123')
return json.dumps ( data, ensure_ascii=False )
\ No newline at end of file
#!/usr/bin/evn python
# coding=utf-8
from flask import Blueprint, request
import flask
import json,re,time,io
import os
from apps.commons.util import *
import apps.gbvar.ws_serv_global as sv_global
import apps.gbvar.dict_properties as dict_p
import apps.commons.editXml as editXml
import requests
import re
task = Blueprint('task', __name__)
'''
初始化系统任务
'''
@task.route('',methods=['GET'])
def init_task():
tasks = []
list_data = {}
data1 = make_task_info('task_1');
tasks.append(data1)
data2 = make_task_info ( 'task_2' );
tasks.append ( data2 )
data3 = make_task_info ( 'task_3' );
tasks.append ( data3 )
data4 = make_task_info ( 'task_4' );
tasks.append ( data4 )
list_data.setdefault('list_data',tasks)
res = flask.make_response ( json.dumps(list_data,encoding="UTF-8", ensure_ascii=False, sort_keys=False, indent=4).encode('utf-8') )
res.headers['Access-Control-Allow-Origin'] = '*'
res.headers['Access-Control-Allow-Methods'] = 'POST,GET,OPTIONS'
res.headers['Access-Control-Allow-Headers'] = 'x-requested-with,content-type'
return res
'''
编辑任务
'''
@task.route('/edit/<path:task_index>', methods=["POST","OPTIONS"])
def edit_task_inf(task_index):
data = request.get_data ()
print type ( data )
task_data = json.loads ( data )
task = dict_p.get_value ()['task_%s' % task_index]
if task is None or task == '':
return None
tasks = re.split ( '[@]', task )
if len ( tasks ) < 4:
return None
mtask_path = tasks[2]
scen = task_data['mtasks'][0]['scenes'][0]
'''
===========================更改task_name start===============
'''
if task_data.has_key('task_name'):
task_name = task_data['task_name']
if task_name is not None:
task_name_doc = editXml.parseXmlStr ( tasks[0] )
if task_name_doc:
root = task_name_doc.documentElement
Name = root.getElementsByTagName ( "Name" )[0].childNodes[0]
Name.data = task_name
xml = task_name_doc.toxml ()
xml = xml.replace ( '<?xml version="1.0" ?>', '<?xml version="1.0" encoding="GBK"?>' )
editXml.writeXml ( tasks[0], task_name_doc.toxml () )
'''
======================更改play_url start====================
'''
if scen.has_key('play_urls'):
play_urls = scen['play_urls']
play_url = play_urls['rtsp']
if play_url is not None:
scenes = editXml.parseXmlStr ( os.path.join(tasks[1],'scene.xml') )
root = scenes.documentElement
scen_play_url = root.getElementsByTagName ( "scene1" )[0].getElementsByTagName ( "play_urls" )[0].getElementsByTagName ( "rtsp" )[0].childNodes[0]
print scen_play_url.data
scen_play_url.data = play_url
xml = scenes.toxml ()
xml = xml.replace( '&quot;', '"' )
xml = xml.replace( '<?xml version="1.0" ?>', '<?xml version="1.0" encoding="GBK"?>' )
editXml.writeXml ( os.path.join(tasks[1],'scene.xml'), xml )
'''
==================更改标定 start====================
'''
if scen.has_key('calibration'):
calibration = scen['calibration']
if calibration.has_key('calibration'):
cal = calibration['calibration']
if cal is not None and cal != '':
editXml.writeXml ( os.path.join(mtask_path,'calibration.xml'), cal )
'''
==================更改参数 start====================
'''
if scen.has_key('config'):
config = scen['config']
if config is not None and config !='' and config.has_key('xml'):
xml = config['xml']
editXml.writeXml ( os.path.join ( mtask_path, 'config.xml' ), xml )
'''
==================更改roi start=====================
'''
if scen.has_key('rois'):
rois = scen['rois']
if rois is not None and rois != '':
roi = rois[0]['roi']
if roi is not None and roi != '':
editXml.writeXml ( os.path.join ( mtask_path, 'roi_1.xml' ), roi )
'''
启动任务开始
'''
os.system('pkill VAServer')
result_data = {"ecode": "200", "enote": "OK"}
res = flask.make_response (
json.dumps ( result_data, encoding="UTF-8", ensure_ascii=False, sort_keys=False, indent=4 ).encode ( 'utf-8' ) )
res.headers['Access-Control-Allow-Origin'] = '*'
res.headers['Access-Control-Allow-Methods'] = 'POST,GET,OPTIONS,HEAD'
res.headers['Access-Control-Allow-Headers'] = 'x-requested-with,content-type'
return res
'''
截图
'''
@task.route('/pic_cut/<path:task_id>', methods=["GET"])
def cut_pic(task_id):
cut_inf = {}
cut_inf.setdefault('taskid',task_id)
result = {'ecode':400,'enote':"截图失败!"}
try:
r = requests.post ( dict_p.get_value()['cut_pic_url'], json.dumps ( cut_inf ) )
result = r.json ()
except Exception as e:
print e
res = flask.make_response (json.dumps ( result, ensure_ascii=False ) )
res.headers['Access-Control-Allow-Origin'] = '*'
res.headers['Access-Control-Allow-Methods'] = 'POST,GET,OPTIONS,HEAD'
res.headers['Access-Control-Allow-Headers'] = 'x-requested-with,content-type'
return res
'''
创建任务详情信息
'''
def make_task_info(task_index):
print dict_p
task = dict_p.get_value()[task_index]
if task is None or task == '':
return {}
tasks = re.split ( '[@]', task )
if len(tasks) < 4:
return {}
task = {}
task_n = tasks[0]
task.setdefault('subtask_name',read_task_name(task_n))
taski = tasks[1]
task.setdefault ( 'subtask_id', read_task_id ( os.path.join(taski +'task.xml' )))
mtask_path = tasks[2]
rtsp = read_rtsp ( os.path.join ( taski, 'scene.xml' ) )
if rtsp =='' or rtsp is None:
task.setdefault ( 'is_active', False)
else:
task.setdefault ( 'is_active', True )
task.setdefault('mtasks',make_mtasks(os.path.join(mtask_path,'calibration.xml'),os.path.join(mtask_path,'roi_1.xml'),tasks[3],os.path.join(mtask_path,'config.xml'), rtsp))
return task
def read_task_name(xmlPath):
task_name_doc = editXml.parseXmlStr( xmlPath )
if task_name_doc:
root = task_name_doc.documentElement
name = root.getElementsByTagName ( "Name" )[0].childNodes[0]
print 'name =%s' % name.data
return name.data
return ''
def read_task_id(xmlPath):
task_id_doc = editXml.parseXmlStr ( xmlPath )
if task_id_doc:
root = task_id_doc.documentElement
task_id = root.getElementsByTagName ( "task_unid" )[0].childNodes[0]
print 'task_id =%s' % task_id.data
return task_id.data
return ''
def read_rtsp(xmlPath):
scenes = editXml.parseXmlStr ( xmlPath )
if scenes:
root = scenes.documentElement
scen_play_url = \
root.getElementsByTagName ( "scene1" )[0].getElementsByTagName ( "play_urls" )[0].getElementsByTagName (
"rtsp" )[0].childNodes[0]
return scen_play_url.data
return ''
def make_mtasks(cal_path,roi_path,basconpath,conpath,rtsp):
mtasks = []
scenes = []
cal = editXml.openXml( cal_path )
cal = cal.replace('\n','')
calibration = {}
calibration.setdefault('calibration',cal)
con = editXml.openXml( conpath )
con = con.replace ( '\n', '' )
config = {}
config.setdefault('xml',con)
play_urls = {}
play_urls.setdefault('rtsp',rtsp)
bascon = editXml.openXml( basconpath )
bascon = bascon.replace( '\n', '' )
basConfig = {}
basConfig.setdefault('xml',bascon)
rois = []
roi = editXml.openXml( roi_path )
ro = {}
ro.setdefault('roi',roi)
rois.append(ro);
sce = {}
sce.setdefault('calibration',calibration)
sce.setdefault('rois',rois)
sce.setdefault ( 'config', config )
sce.setdefault ( 'basicConfig', basConfig )
sce.setdefault ( 'play_urls', play_urls )
sce.setdefault('algo_type',0)
scenes.append(sce)
mtask = {}
mtask.setdefault('scenes',scenes)
mtasks.append(mtask)
return mtasks
No preview for this file type
......@@ -2,8 +2,23 @@
# coding=utf-8
import sys, io
import re
import xml.parsers.expat
import xml.etree.ElementTree as Etree
from urllib import unquote
import types
import httplib
import urllib2
import urllib
import json
from xml.dom import minidom
#读取xml文件
def readerXml(filePath):
def openXml(filePath):
# 打开xml文档
return io.open(filePath, 'r', encoding='GBK').read ().encode ( 'utf-8' )
......@@ -13,4 +28,17 @@ def writeXml(filePath,data):
# 打开xml文档
f = io.open ( filePath, 'w', encoding='GBK' )
f.write(data)
f.close ()
\ No newline at end of file
f.close ()
# <![CDATA[ http://j.xywy.com/il_sii_27.htm ]]>
def parseXmlStr(url):
_str = openXml(url)
if _str is None or _str == '':
return None
_str = _str.replace('GBK','UTF-8')
_str = _str.replace ( 'gbk', 'UTF-8' )
print _str
# 修改xml文件的编码方式
return minidom.parseString(_str)
\ No newline at end of file
# coding: utf-8
#!/usr/bin/python
# -- coding: utf-8 --
from flask import Flask,Blueprint
import flask
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
from api.http_serv import tx1_box
from api.task import task
from api.ws_serv import Server
import gbvar.ws_serv_global as sv_global
import gbvar.database_global as database
import gbvar.dict_properties as dict_p
import fdb
import sys
import os
from apps.commons.util import *
app = Flask(__name__, static_folder='apps/static')
from commons.util import *
app = Flask(__name__, static_folder='dist')
# 获取本脚本所在的路径
pro_path = os.path.split(os.path.realpath(__file__))[0]
#配置文件路径
con_path = '/'.join((pro_path, 'special.properties'))
print con_path
print con_path
dictProperties=Properties(con_path).getProperties()
# 创建路由
app.register_blueprint(tx1_box, url_prefix='/api/v1/tx1_box')
#注册task路由
app.register_blueprint(task, url_prefix='/api/v1/tx1_box/task')
@app.route('/', methods=["GET"])
def index():
return flask.send_file ( "dist/index.html" )
def start_ws(host,port):
try:
......@@ -67,6 +73,8 @@ def init():
#启动服务
if __name__=='__main__':
dict_p._init ()
dict_p.set_value ( dictProperties )
#init()
_h=dictProperties['tx1_host']
_p=int(dictProperties['tx1_ws_port'])
......
from setuptools import setup
setup(
name='tx1_box_serv',
version='1.0.0',
description='tx1_box_serv',
author='xf',
classifiers=[
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
'Topic :: Software Development :: Build Tools',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
],
packages=['api','commons','gbvar']
)
\ No newline at end of file
#系统参数
tx1_host=192.168.9.61
tx1_http_port=20090
tx1_ws_port=20070
tx1_ws_port=20080
#firebird数据库
datasource_url=F:/firebird/database/EVENT.FDB
#初始化任务列表(说明:路径@任务名称
task_0=E:/项目/pyWeb/static/xml/ServerConfig_2.xml@运维服务@./start.sh
task_1=/root/UserApp/vioncfg/Ops/ServerConfig.xml@运维服务@./start.sh
task_2=E:/项目/pyWeb/static/xml/ServerConfig_2.xml@运维服务@./start.sh
task_3=/root/UserApp/vioncfg/Ops/ServerConfig.xml@运维服务@./start.sh
task_1=F:\TASK1\tasks.xml@F:\TASK1\TASK1\@F:\TASK1\TASK1\TASK1\@F:\TrafficConfig.xml
task_2=
task_3=
task_4=/root/UserApp/vioncfg/Ops/ServerConfig.xml@运维服务@./start.sh
#截图接口地址
cut_pic_url=http://192.168.88.109:10088/apiv1/capture
#重启任务指令
start_task=./task_start.sh
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!