From fa346cec3b307c6013a252475bac532ed0698dbb Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sun, 25 Mar 2012 18:38:33 -0700 Subject: [PATCH] Moved some Python scripts into new share/tools/ directory. Added fish_config function to launch web config --- Makefile.in | 15 +++++++++ share/functions/fish_config.fish | 3 ++ .../tools/create_manpage_completions.py | 0 .../tools/import_bash_settings.py | 0 .../tools/web_config}/index.html | 0 .../tools/web_config}/jquery.js | 0 .../tools/web_config}/webconfig.py | 32 +++++++++++++++---- 7 files changed, 43 insertions(+), 7 deletions(-) create mode 100644 share/functions/fish_config.fish rename create_manpage_completions.py => share/tools/create_manpage_completions.py (100%) rename import_bash_settings.py => share/tools/import_bash_settings.py (100%) rename {web_config => share/tools/web_config}/index.html (100%) rename {web_config => share/tools/web_config}/jquery.js (100%) rename {web_config => share/tools/web_config}/webconfig.py (89%) diff --git a/Makefile.in b/Makefile.in index 640e8c3c0..ce88be333 100644 --- a/Makefile.in +++ b/Makefile.in @@ -599,6 +599,8 @@ install-force: all install-translations $(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/fish/completions $(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/fish/functions $(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/fish/man + $(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/fish/tools + $(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/fish/tools/web_config $(INSTALL) -m 644 etc/config.fish $(DESTDIR)$(sysconfdir)/fish/ $(INSTALL) -m 644 share/config.fish $(DESTDIR)$(datadir)/fish/ for i in $(COMPLETIONS_DIR_FILES); do \ @@ -613,6 +615,19 @@ install-force: all install-translations $(INSTALL) -m 644 $$i $(DESTDIR)$(datadir)/fish/man/; \ true; \ done; + for i in share/tools/*.py; do\ + $(INSTALL) -m 755 $$i $(DESTDIR)$(datadir)/fish/tools/; \ + true; \ + done; + for i in share/tools/web_config/*; do\ + $(INSTALL) -m 644 $$i $(DESTDIR)$(datadir)/fish/tools/web_config/; \ + true; \ + done; + for i in share/tools/web_config/*.py; do\ + $(INSTALL) -m 755 $$i $(DESTDIR)$(datadir)/fish/tools/web_config/; \ + true; \ + done; + $(INSTALL) -m 755 -d $(DESTDIR)$(docdir) for i in user_doc/html/* ChangeLog; do \ if test -f $$i; then \ diff --git a/share/functions/fish_config.fish b/share/functions/fish_config.fish new file mode 100644 index 000000000..de59d8343 --- /dev/null +++ b/share/functions/fish_config.fish @@ -0,0 +1,3 @@ +function fish_config --description "Launch fish's web based configuration" + eval $__fish_datadir/tools/web_config/webconfig.py +end diff --git a/create_manpage_completions.py b/share/tools/create_manpage_completions.py similarity index 100% rename from create_manpage_completions.py rename to share/tools/create_manpage_completions.py diff --git a/import_bash_settings.py b/share/tools/import_bash_settings.py similarity index 100% rename from import_bash_settings.py rename to share/tools/import_bash_settings.py diff --git a/web_config/index.html b/share/tools/web_config/index.html similarity index 100% rename from web_config/index.html rename to share/tools/web_config/index.html diff --git a/web_config/jquery.js b/share/tools/web_config/jquery.js similarity index 100% rename from web_config/jquery.js rename to share/tools/web_config/jquery.js diff --git a/web_config/webconfig.py b/share/tools/web_config/webconfig.py similarity index 89% rename from web_config/webconfig.py rename to share/tools/web_config/webconfig.py index 59a05da69..c0f1aaf7e 100755 --- a/web_config/webconfig.py +++ b/share/tools/web_config/webconfig.py @@ -4,7 +4,7 @@ import SimpleHTTPServer import SocketServer import webbrowser import subprocess -import re, json, socket, sys, cgi +import re, json, socket, os, sys, cgi, select def run_fish_cmd(text): from subprocess import PIPE @@ -93,7 +93,6 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): for match in re.finditer(r"^fish_color_(\S+) ?(.*)", line): color_name, color_value = match.group(1, 2) result.append([color_name.strip(), parse_color(color_value)]) - print result return result def do_get_functions(self): @@ -200,7 +199,6 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): background_color = postvars.get('background_color') bold = postvars.get('bold') underline = postvars.get('underline') - print "underline: ", underline if what: # Not sure why we get lists here? output = self.do_set_color_for_variable(what[0], color[0], background_color[0], parse_bool(bold[0]), parse_bool(underline[0])) @@ -220,7 +218,16 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): # Output JSON json.dump(output, self.wfile) + def log_request(self, code='-', size='-'): + """ Disable request logging """ + pass +# Make sure that the working directory is the one that contains the script server file, +# because the document root is the working directory +where = os.path.dirname(sys.argv[0]) +os.chdir(where) + +# Try to find a suitable port PORT = 8000 while PORT <= 9000: try: @@ -235,11 +242,22 @@ while PORT <= 9000: PORT += 1 if PORT > 9000: - print "Unable to start a web server" + # Nobody say it + print "Unable to find an open port between 8000 and 9000" sys.exit(-1) -webbrowser.open("http://localhost:%d" % PORT) +url = 'http://localhost:%d' % PORT -print "serving at port", PORT -httpd.serve_forever() +print "Web config started at '%s'. Hit enter to stop." % url +webbrowser.open(url) + +# Select on stdin and httpd +stdin_no = sys.stdin.fileno() +while True: + ready_read, _, _ = select.select([sys.stdin.fileno(), httpd.fileno()], [], []) + if stdin_no in ready_read: + print "Shutting down." + break + else: + httpd.handle_request()