From 15ebdf6907887fe65c641d85de663fd83d13dc50 Mon Sep 17 00:00:00 2001 From: Florian Mounier Date: Wed, 5 Oct 2016 16:51:16 +0200 Subject: [PATCH] Add local script loading --- butterfly/__init__.py | 7 ++++++- butterfly/routes.py | 21 ++++++++++++++++++++- butterfly/templates/index.html | 1 + butterfly/utils.py | 1 + 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/butterfly/__init__.py b/butterfly/__init__.py index 3147788..6f9ccc2 100644 --- a/butterfly/__init__.py +++ b/butterfly/__init__.py @@ -46,13 +46,18 @@ class Route(tornado.web.RequestHandler): @property def builtin_themes_dir(self): return os.path.join( - os.path.dirname(__file__), 'themes') + os.path.dirname(__file__), 'themes') @property def themes_dir(self): 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( diff --git a/butterfly/routes.py b/butterfly/routes.py index 1a1eed2..dd301c5 100644 --- a/butterfly/routes.py +++ b/butterfly/routes.py @@ -340,7 +340,7 @@ class ThemesList(Route): 'built-in-%s' % theme for theme in os.listdir(self.builtin_themes_dir) if os.path.isdir(os.path.join( - self.builtin_themes_dir, theme)) and + self.builtin_themes_dir, theme)) and not theme.startswith('.')] else: builtin_themes = [] @@ -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() diff --git a/butterfly/templates/index.html b/butterfly/templates/index.html index c3d13e1..b501bab 100644 --- a/butterfly/templates/index.html +++ b/butterfly/templates/index.html @@ -23,5 +23,6 @@ '' if options.unminified else 'min.')) }}"> + diff --git a/butterfly/utils.py b/butterfly/utils.py index ab4a18e..b293c68 100644 --- a/butterfly/utils.py +++ b/butterfly/utils.py @@ -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