/
selftest-server.py
executable file
·65 lines (53 loc) · 1.79 KB
/
selftest-server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python
"""
Test server, for running the cutout/sync tests
"""
import optparse
import sys
import os
import shutil
import site
here = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, here)
path = here
checks = ['vendor', 'vendor-binary']
for i in range(3):
for check in checks:
dir = os.path.join(path, check)
if os.path.exists(dir):
old_sys_path = list(sys.path)
site.addsitedir(dir)
for new_path in list(sys.path):
if new_path not in old_sys_path:
sys.path.remove(new_path)
sys.path.insert(0, new_path)
path = os.path.dirname(path)
parser = optparse.OptionParser(
usage='%prog [OPTIONS]')
parser.add_option('-H', '--host', metavar='HOST', default='localhost')
parser.add_option('-p', '--port', metavar='PORT', default='8088')
parser.add_option('--dir', metavar='DIRECTORY', default='./data')
parser.add_option('--clear', action='store_true')
from webob.dec import wsgify
@wsgify.middleware
def TestAuthMiddleware(req, app):
req.environ['REMOTE_USER'] = req.headers.get('X-Remote-User')
return app
def main():
options, args = parser.parse_args()
if options.clear:
if os.path.exists(options.dir):
print 'Deleting %s' % options.dir
shutil.rmtree(options.dir)
from cutout.sync import Application
db_app = Application(dir=options.dir, include_syncclient=True)
from webob.static import DirectoryApp
from paste.urlmap import URLMap
map = URLMap()
map['/'] = DirectoryApp(
os.path.join(here, 'cutout', 'tests', 'syncclient'))
map['/db'] = TestAuthMiddleware(db_app)
from paste.httpserver import serve
serve(map, host=options.host, port=int(options.port))
if __name__ == '__main__':
main()