shadowsocks/tests/coverage_server.py

46 lines
1.6 KiB
Python
Raw Normal View History

2014-12-24 08:47:14 +00:00
#!/usr/bin/env python
2015-02-03 06:10:36 +00:00
#
# Copyright 2015 clowwindy
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
2014-12-24 08:47:14 +00:00
2014-12-24 09:06:15 +00:00
if __name__ == '__main__':
import tornado.ioloop
import tornado.web
import urllib
2014-12-24 08:47:14 +00:00
2014-12-24 09:06:15 +00:00
class MainHandler(tornado.web.RequestHandler):
def get(self, project):
try:
with open('/tmp/%s-coverage' % project, 'rb') as f:
coverage = f.read().strip()
2014-12-28 07:06:22 +00:00
n = int(coverage.strip('%'))
2015-02-01 09:15:10 +00:00
if n >= 80:
2014-12-28 07:06:22 +00:00
color = 'brightgreen'
else:
color = 'yellow'
self.redirect(('https://img.shields.io/badge/'
2014-12-28 07:06:22 +00:00
'coverage-%s-%s.svg'
2014-12-28 04:35:17 +00:00
'?style=flat') %
2014-12-28 07:06:22 +00:00
(urllib.quote(coverage), color))
except IOError:
raise tornado.web.HTTPError(404)
2014-12-24 08:47:14 +00:00
2014-12-24 09:06:15 +00:00
application = tornado.web.Application([
2014-12-28 07:00:29 +00:00
(r"/([a-zA-Z0-9\-_]+)", MainHandler),
2014-12-24 09:06:15 +00:00
])
2014-12-24 08:47:14 +00:00
2014-12-24 09:06:15 +00:00
if __name__ == "__main__":
application.listen(8888, address='127.0.0.1')
tornado.ioloop.IOLoop.instance().start()