OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python3 | |
Nico
2017/03/02 15:47:11
same here
| |
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 Http Server handle file open request | |
8 ''' | |
9 | |
10 from bottle import Bottle, install, get, response, request, run | |
11 import logging | |
12 import sys | |
13 import sh | |
14 | |
15 logfile = "/tmp/omed.log" | |
16 # Get it a path for log | |
17 if len(sys.argv) == 2: | |
18 logfile = sys.argv[1] | |
19 | |
20 logging.basicConfig(filename=logfile, level=logging.INFO) | |
21 logger = logging.getLogger('omed') | |
22 | |
23 | |
24 def log(func): | |
25 | |
26 def wrapper(*args, **kwargs): | |
27 logger.info( | |
28 '%s %s %s %s' % | |
29 (request.remote_addr, request.method, request.url, response.status)) | |
30 | |
31 req = func(*args, **kwargs) | |
32 return req | |
33 | |
34 return wrapper | |
35 | |
36 | |
37 install(log) | |
38 | |
39 | |
40 @get('/file') | |
41 def open_file(): | |
42 filepath = request.query.f | |
43 line = request.query.l | |
44 | |
45 logger.info("open file: " + filepath + ":" + line) | |
46 | |
47 sh.myeditor("-f", filepath, "-l", line) | |
48 return | |
49 | |
50 | |
51 @get('/files') | |
52 def open_files(): | |
53 filepaths = request.query.f | |
54 | |
55 logger.info("open files: " + filepaths) | |
56 | |
57 sh.myeditor("-m", filepaths) | |
58 return | |
59 | |
60 | |
61 run(port=8989, host='127.0.0.1') | |
OLD | NEW |