提交 485623c4 编写于 作者: Q qiaolongfei

init commit

上级 1ee3d79b
""" entry point of visual_dl
"""
import json
from optparse import OptionParser
from flask import Flask
from flask import request
from visual_dl.log import logger
app = Flask(__name__)
def option_parser():
"""
:return:
"""
parser = OptionParser(usage="usage: visual_dl visual_dl.py "\
"-p port [options]")
parser.add_option(
"-p",
"--port",
default=8040,
action="store",
dest="port",
help="rest api service port")
return parser.parse_args()
# return data
# status, msg, data
def gen_result(status, msg):
"""
:param status:
:param msg:
:return:
"""
result = dict()
result['status'] = status
result['msg'] = msg
result['data'] = {}
return result
@app.route('/')
def index():
"""
:return:
"""
result = gen_result(0, "Hello, this is VisualDL!")
return json.dumps(result)
@app.route('/v1/scalar/start')
def start_board():
"""
:return:
"""
app_id = request.args.get('app_id')
summary_dir = request.args.get('summary_dir')
result = gen_result(status=1, msg="please set app_id and summary_dir")
return json.dumps(result)
if __name__ == '__main__':
options, args = option_parser()
logger.info(" port=" + str(options.port))
app.run(debug=False, host="0.0.0.0", port=options.port)
import log
import tensorboard
import timer
import util
__all__ = [
'log',
'util'
]
import logging
logger = logging
logger.basicConfig(
format='[%(levelname)s %(asctime)s %(filename)s:%(lineno)s] %(message)s')
logger.getLogger().setLevel(logging.INFO)
import socket
def is_open(port):
local_ip = '127.0.0.1'
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
s.connect((local_ip, int(port)))
s.shutdown(2)
return True
except:
return False
def get_hostname():
return socket.gethostname()
def find_unused_port():
"""
get a unused port of this machine
:return: available port
"""
min_port = 7000
max_port = 7999
aval_port = None
for port in range(min_port, max_port):
if not is_open(port):
aval_port = port
break
return aval_port
if __name__ == '__main__':
print find_unused_port()
from setuptools import setup
setup(name="VisualDL",
version="0.0.1",
packages=['python'],
include_package_data=True,
install_requires=[
'flask>=0.12.1'
],
url='http://www.baidu.com/',
license='Apache 2.0',
)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册