Upstream version 5.34.92.0
[platform/framework/web/crosswalk.git] / src / third_party / trace-viewer / run_dev_server.py
1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5 import os
6 import sys
7 import json
8
9 import build # Brings in tvcm bindings.
10 import tvcm
11
12 toplevel_path = os.path.abspath(os.path.dirname(__file__))
13 src_path = os.path.join(toplevel_path, 'src')
14 test_data_path = os.path.join(toplevel_path, 'test_data')
15 skp_data_path = os.path.join(toplevel_path, 'skp_data')
16
17 def do_GET_json_examples(request):
18   data_files = []
19   for dirpath, dirnames, filenames in os.walk(test_data_path):
20     for f in filenames:
21       data_files.append(f)
22
23   data_files.sort()
24   files_as_json = json.dumps(data_files)
25
26   request.send_response(200)
27   request.send_header('Content-Type', 'application/json')
28   request.send_header('Content-Length', len(files_as_json))
29   request.end_headers()
30   request.wfile.write(files_as_json)
31
32 def do_GET_json_examples_skp(request):
33   data_files = []
34   for dirpath, dirnames, filenames in os.walk(skp_data_path):
35     for f in filenames:
36       data_files.append(f)
37
38   data_files.sort()
39   files_as_json = json.dumps(data_files)
40
41   request.send_response(200)
42   request.send_header('Content-Type', 'application/json')
43   request.send_header('Content-Length', len(files_as_json))
44   request.end_headers()
45   request.wfile.write(files_as_json)
46
47 def Main(port, args):
48   server = tvcm.DevServer(port=port)
49   server.AddPathHandler('/json/examples', do_GET_json_examples)
50   server.AddPathHandler('/json/examples/skp', do_GET_json_examples_skp)
51
52   server.AddSourcePathMapping('/src', src_path)
53   server.AddDataPathMapping('/third_party', os.path.join(toplevel_path, 'third_party'))
54   server.AddDataPathMapping('/examples', os.path.join(toplevel_path, 'examples'))
55   server.AddDataPathMapping('/test_data', test_data_path)
56   server.AddDataPathMapping('/skp_data', skp_data_path)
57   server.serve_forever()
58
59 if __name__ == '__main__':
60   sys.exit(Main(port=8003, args=sys.argv[1:]))