diff --git a/bin/visual_dl.py b/bin/visual_dl.py new file mode 100644 index 0000000000000000000000000000000000000000..a43f577194cb13fbc5f62f0f01b31bbe25840ed0 --- /dev/null +++ b/bin/visual_dl.py @@ -0,0 +1,72 @@ +""" 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) diff --git a/python/__init__.py b/python/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..f91720ab47353c1f2c760297d915963310326c2d --- /dev/null +++ b/python/__init__.py @@ -0,0 +1,9 @@ +import log +import tensorboard +import timer +import util + +__all__ = [ + 'log', + 'util' +] diff --git a/python/log.py b/python/log.py new file mode 100644 index 0000000000000000000000000000000000000000..5199e96e2dc3b8315e0ada1e424873f01260bd26 --- /dev/null +++ b/python/log.py @@ -0,0 +1,7 @@ +import logging + +logger = logging + +logger.basicConfig( + format='[%(levelname)s %(asctime)s %(filename)s:%(lineno)s] %(message)s') +logger.getLogger().setLevel(logging.INFO) diff --git a/python/util.py b/python/util.py new file mode 100644 index 0000000000000000000000000000000000000000..df328d81b229a614de3ac45d3da5c57370e0b2b2 --- /dev/null +++ b/python/util.py @@ -0,0 +1,34 @@ +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() diff --git a/setup.py b/setup.py new file mode 100644 index 0000000000000000000000000000000000000000..837f823c64ba6b73f764b9db943975260806435d --- /dev/null +++ b/setup.py @@ -0,0 +1,12 @@ +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', +)