From 485623c4e05529e9dda374bf62c7daa40a544a52 Mon Sep 17 00:00:00 2001 From: qiaolongfei Date: Thu, 16 Nov 2017 17:32:09 +0800 Subject: [PATCH] init commit --- bin/visual_dl.py | 72 ++++++++++++++++++++++++++++++++++++++++++++++ python/__init__.py | 9 ++++++ python/log.py | 7 +++++ python/util.py | 34 ++++++++++++++++++++++ setup.py | 12 ++++++++ 5 files changed, 134 insertions(+) create mode 100644 bin/visual_dl.py create mode 100644 python/__init__.py create mode 100644 python/log.py create mode 100644 python/util.py create mode 100644 setup.py diff --git a/bin/visual_dl.py b/bin/visual_dl.py new file mode 100644 index 00000000..a43f5771 --- /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 00000000..f91720ab --- /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 00000000..5199e96e --- /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 00000000..df328d81 --- /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 00000000..837f823c --- /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', +) -- GitLab