Klaus Demo klaus / 7f3f5b4
Exclude hidden folders in autoreloading app Nephe authored 4 months ago Jonas Haag committed 4 months ago
3 changed file(s) with 17 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
00 from __future__ import print_function
1 import os
1 import glob
22 import time
33 import threading
44
55 from klaus import make_app
66
77
8 def is_hidden_folder(f):
9 return f[0] == '.'
10
11
812 # Shared state between poller and application wrapper
9 class _:
13 class S:
1014 #: the real WSGI app
1115 inner_app = None
1216 should_reload = True
1721 Polls `dir` for changes every `interval` seconds and sets `should_reload`
1822 accordingly.
1923 """
20 old_contents = os.listdir(dir)
24 glob_pattern = dir + '/*'
25 old_contents = glob.glob(glob_pattern)
2126 while 1:
2227 time.sleep(interval)
2328 if _.should_reload:
2429 # klaus application has not seen our change yet
2530 continue
26 new_contents = os.listdir(dir)
31 new_contents = glob.glob(glob_pattern)
2732 if new_contents != old_contents:
2833 # Directory contents changed => should_reload
2934 old_contents = new_contents
3540 if _.should_reload:
3641 # Refresh inner application with new repo list
3742 print("Reloading repository list...")
38 _.inner_app = make_app(
39 [os.path.join(repos_root, x) for x in os.listdir(repos_root)],
40 *args, **kwargs
41 )
43 _.inner_app = make_app(glob.glob(repos_root + '/*'), *args, **kwargs)
4244 _.should_reload = False
4345 return _.inner_app(environ, start_response)
4446
0 #!/bin/bash -e
1
2 # Hide the directory
3 cd ..
4 mv hidden_folder .hidden_folder
0 # Create an invalid git repo e.g an empty folder
1