Klaus Demo ~jonashaag/klaus / c6a8020
Moved tools into subfolder Jonas Haag 10 years ago
8 changed file(s) with 158 addition(s) and 158 deletion(s). Raw diff Collapse all Expand all
5050 ..................................
5151 ::
5252
53 ./quickstart --help
54 ./quickstart.py <host> <port> /path/to/repo1 [../path/to/repo2 [...]]
53 tools/quickstart --help
54 tools/quickstart.py <host> <port> /path/to/repo1 [../path/to/repo2 [...]]
5555
5656 Example::
5757
00 definitely
11 ----------
2 * branch selector
2 * tag selector
33
44 maybe
55 -----
+0
-43
devserver.py less more
0 #!/usr/bin/env python2
1 import sys, os
2 import inspect
3
4 sys.path.append(os.path.join(os.path.dirname(__file__), 'nano'))
5
6 class ReloadApplicationMiddleware(object):
7 def __init__(self, import_func):
8 self.import_func = import_func
9 self.app = import_func()
10 self.files = self.get_module_mtimes()
11
12 def get_module_mtimes(self):
13 files = {}
14 for module in sys.modules.itervalues():
15 try:
16 file = inspect.getsourcefile(module)
17 files[file] = os.stat(file).st_mtime
18 except TypeError:
19 continue
20 return files
21
22 def shall_reload(self):
23 for file, mtime in self.get_module_mtimes().iteritems():
24 if not file in self.files or self.files[file] < mtime:
25 self.files = self.get_module_mtimes()
26 return True
27 return False
28
29 def __call__(self, *args, **kwargs):
30 if self.shall_reload():
31 print 'Reloading...'
32 self.app = self.import_func()
33 return self.app(*args, **kwargs)
34
35 def import_app():
36 sys.modules.pop('klaus', None)
37 sys.modules.pop('repo', None)
38 from klaus import app
39 return app
40
41 import bjoern
42 bjoern.run(ReloadApplicationMiddleware(import_app), '127.0.0.1', 8080)
+0
-64
dumbtest.py less more
0 """ Very dumb testing tool: Ensures all sites respond with HTTP 2xx/3xx """
1 import sys
2 import re
3 import time
4 import httplib
5 from collections import defaultdict
6 import atexit
7
8 def view_from_url(url):
9 try:
10 return url.split('/')[2]
11 except IndexError:
12 return url
13
14 AHREF_RE = re.compile('href="([\w/][^"]+)"')
15
16 BASE_URL = 'http://localhost:8080'
17
18 seen = set()
19 errors = defaultdict(set)
20 durations = defaultdict(list)
21
22 def main():
23 urls = {'/'}
24 while urls:
25 try:
26 http_conn.close()
27 except NameError:
28 pass
29 http_conn = httplib.HTTPConnection('localhost', 8080)
30 url = urls.pop()
31 if url in seen:
32 continue
33 seen.add(url)
34 if url.startswith('http'):
35 continue
36 if '-v' in sys.argv:
37 print 'Requesting %r...' % url
38 start = time.time()
39 http_conn.request('GET', BASE_URL + url)
40 response = http_conn.getresponse()
41 durations[view_from_url(url)].append(time.time() - start)
42 status = str(response.status)
43 if status[0] == '3':
44 urls.add(response.getheader('Location'))
45 elif status[0] == '2':
46 if not '/raw/' in url:
47 html = response.read()
48 html = re.sub('<pre>.*?</pre>', '', html)
49 urls.update(AHREF_RE.findall(html))
50 else:
51 if '--failfast' in sys.argv:
52 print url, status
53 exit(1)
54 errors[status].add(url)
55
56 def print_stats():
57 import pprint
58 print len(seen)
59 pprint.pprint(dict(errors))
60 print {url: sum(times)/len(times) for url, times in durations.iteritems()}
61 atexit.register(print_stats)
62
63 main()
+0
-48
quickstart.py less more
0 #!/usr/bin/env python2
1 # coding: utf-8
2 import sys, os
3 import argparse
4
5 try:
6 import nano
7 except ImportError:
8 sys.path.append(os.path.join(os.path.dirname(__file__), 'nano'))
9 try:
10 import nano
11 except ImportError:
12 raise ImportError(
13 "Could not find a copy of nano (https://github.com/jonashaag/nano). "
14 "Use 'git submodule update --init' to initialize the nano submodule "
15 "or copy the 'nano.py' into the klaus root directory by hand."
16 )
17
18 try:
19 from bjoern import run
20 except ImportError:
21 from wsgiref.simple_server import make_server
22 def run(app, host, port):
23 make_server(host, port, app).serve_forever()
24
25 def valid_directory(path):
26 if not os.path.exists(path):
27 raise argparse.ArgumentTypeError('%r: No such directory' % path)
28 return path
29
30 def main():
31 parser = argparse.ArgumentParser(epilog='Gemüse kaufen!')
32 parser.add_argument('host', help='(without http://)')
33 parser.add_argument('port', type=int)
34 parser.add_argument('--display-host', dest='custom_host')
35 parser.add_argument('repo', nargs='+', type=valid_directory,
36 help='repository directories to serve')
37 args = parser.parse_args()
38 sys.argv = ['this is a hack'] + args.repo
39
40 from klaus import app
41 if args.custom_host:
42 app.custom_host = args.custom_host
43
44 run(app, args.host, args.port)
45
46 if __name__ == '__main__':
47 main()
0 #!/usr/bin/env python2
1 import sys, os
2 import inspect
3
4 sys.path.append(os.path.join(os.path.dirname(__file__), 'nano'))
5
6 class ReloadApplicationMiddleware(object):
7 def __init__(self, import_func):
8 self.import_func = import_func
9 self.app = import_func()
10 self.files = self.get_module_mtimes()
11
12 def get_module_mtimes(self):
13 files = {}
14 for module in sys.modules.itervalues():
15 try:
16 file = inspect.getsourcefile(module)
17 files[file] = os.stat(file).st_mtime
18 except TypeError:
19 continue
20 return files
21
22 def shall_reload(self):
23 for file, mtime in self.get_module_mtimes().iteritems():
24 if not file in self.files or self.files[file] < mtime:
25 self.files = self.get_module_mtimes()
26 return True
27 return False
28
29 def __call__(self, *args, **kwargs):
30 if self.shall_reload():
31 print 'Reloading...'
32 self.app = self.import_func()
33 return self.app(*args, **kwargs)
34
35 def import_app():
36 sys.modules.pop('klaus', None)
37 sys.modules.pop('repo', None)
38 from klaus import app
39 return app
40
41 import bjoern
42 bjoern.run(ReloadApplicationMiddleware(import_app), '127.0.0.1', 8080)
0 """ Very dumb testing tool: Ensures all sites respond with HTTP 2xx/3xx """
1 import sys
2 import re
3 import time
4 import httplib
5 from collections import defaultdict
6 import atexit
7
8 def view_from_url(url):
9 try:
10 return url.split('/')[2]
11 except IndexError:
12 return url
13
14 AHREF_RE = re.compile('href="([\w/][^"]+)"')
15
16 BASE_URL = 'http://localhost:8080'
17
18 seen = set()
19 errors = defaultdict(set)
20 durations = defaultdict(list)
21
22 def main():
23 urls = {'/'}
24 while urls:
25 try:
26 http_conn.close()
27 except NameError:
28 pass
29 http_conn = httplib.HTTPConnection('localhost', 8080)
30 url = urls.pop()
31 if url in seen:
32 continue
33 seen.add(url)
34 if url.startswith('http'):
35 continue
36 if '-v' in sys.argv:
37 print 'Requesting %r...' % url
38 start = time.time()
39 http_conn.request('GET', BASE_URL + url)
40 response = http_conn.getresponse()
41 durations[view_from_url(url)].append(time.time() - start)
42 status = str(response.status)
43 if status[0] == '3':
44 urls.add(response.getheader('Location'))
45 elif status[0] == '2':
46 if not '/raw/' in url:
47 html = response.read()
48 html = re.sub('<pre>.*?</pre>', '', html)
49 urls.update(AHREF_RE.findall(html))
50 else:
51 if '--failfast' in sys.argv:
52 print url, status
53 exit(1)
54 errors[status].add(url)
55
56 def print_stats():
57 import pprint
58 print len(seen)
59 pprint.pprint(dict(errors))
60 print {url: sum(times)/len(times) for url, times in durations.iteritems()}
61 atexit.register(print_stats)
62
63 main()
0 #!/usr/bin/env python2
1 # coding: utf-8
2 import sys, os
3 import argparse
4
5 try:
6 import nano
7 except ImportError:
8 sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir, 'nano'))
9 try:
10 import nano
11 except ImportError:
12 raise ImportError(
13 "Could not find a copy of nano (https://github.com/jonashaag/nano). "
14 "Use 'git submodule update --init' to initialize the nano submodule "
15 "or copy the 'nano.py' into the klaus root directory by hand."
16 )
17
18 try:
19 from bjoern import run
20 except ImportError:
21 from wsgiref.simple_server import make_server
22 def run(app, host, port):
23 make_server(host, port, app).serve_forever()
24
25 def valid_directory(path):
26 if not os.path.exists(path):
27 raise argparse.ArgumentTypeError('%r: No such directory' % path)
28 return path
29
30 def main():
31 parser = argparse.ArgumentParser(epilog='Gemüse kaufen!')
32 parser.add_argument('host', help='(without http://)')
33 parser.add_argument('port', type=int)
34 parser.add_argument('--display-host', dest='custom_host')
35 parser.add_argument('repo', nargs='+', type=valid_directory,
36 help='repository directories to serve')
37 args = parser.parse_args()
38 sys.argv = ['this is a hack'] + args.repo
39
40 from klaus import app
41 if args.custom_host:
42 app.custom_host = args.custom_host
43
44 run(app, args.host, args.port)
45
46 if __name__ == '__main__':
47 main()