Add local script loading

This commit is contained in:
Florian Mounier
2016-10-05 16:51:16 +02:00
parent 6e29c702e3
commit 15ebdf6907
4 changed files with 28 additions and 2 deletions

View File

@@ -53,6 +53,11 @@ class Route(tornado.web.RequestHandler):
return os.path.join(
self.application.butterfly_dir, 'themes')
@property
def local_js_dir(self):
return os.path.join(
self.application.butterfly_dir, 'js')
def get_theme_dir(self, theme):
if theme.startswith('built-in-'):
return os.path.join(

View File

@@ -351,3 +351,22 @@ class ThemesList(Route):
'builtin_themes': sorted(builtin_themes),
'dir': self.themes_dir
}))
@url('/local.js')
class LocalJsStatic(Route):
def get(self):
self.set_header("Content-Type", 'application/javascript')
if os.path.exists(self.local_js_dir):
for fn in os.listdir(self.local_js_dir):
if not fn.endswith('.js'):
continue
with open(os.path.join(self.local_js_dir, fn), 'rb') as s:
while True:
data = s.read(16384)
if data:
self.write(data)
else:
self.write(';')
break
self.finish()

View File

@@ -23,5 +23,6 @@
'' if options.unminified else 'min.')) }}"></script>
<script src="{{ static_url('ext.%sjs' % (
'' if options.unminified else 'min.')) }}"></script>
<script src="{{ reverse_url('LocalJsStatic') }}"></script>
</body>
</html>

View File

@@ -216,6 +216,7 @@ def get_socket_env(inode, user):
'gnome-session',
'gnome-session-binary',
'startkde',
'startdde',
'xfce4-session']:
with open('/proc/%s/status' % pid) as e:
uid = None