OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # |
| 3 # Copyright 2017 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. |
| 6 |
| 7 """ |
| 8 HTTP server for handling requests to open files. |
| 9 """ |
| 10 |
| 11 from bottle import Bottle, install, get, response, request, run |
| 12 import logging |
| 13 import sys |
| 14 import sh |
| 15 |
| 16 logfile = "/tmp/omed.log" |
| 17 # Get it a path for log. |
| 18 if len(sys.argv) == 2: |
| 19 logfile = sys.argv[1] |
| 20 |
| 21 logging.basicConfig(filename=logfile, level=logging.INFO) |
| 22 logger = logging.getLogger('omed') |
| 23 |
| 24 def log(func): |
| 25 def wrapper(*args, **kwargs): |
| 26 logger.info( |
| 27 '%s %s %s %s' % |
| 28 (request.remote_addr, request.method, request.url, response.status)) |
| 29 |
| 30 req = func(*args, **kwargs) |
| 31 return req |
| 32 return wrapper |
| 33 |
| 34 install(log) |
| 35 |
| 36 @get('/file') |
| 37 def open_file(): |
| 38 filepath = request.query.f |
| 39 line = request.query.l |
| 40 |
| 41 logger.info("open file: " + filepath + ":" + line) |
| 42 |
| 43 sh.myeditor("-f", filepath, "-l", line) |
| 44 return |
| 45 |
| 46 @get('/files') |
| 47 def open_files(): |
| 48 filepaths = request.query.f |
| 49 |
| 50 logger.info("open files: " + filepaths) |
| 51 |
| 52 sh.myeditor("-m", filepaths) |
| 53 return |
| 54 |
| 55 run(port=8989, host='127.0.0.1') |
OLD | NEW |