Moved some Python scripts into new share/tools/ directory.

Added fish_config function to launch web config
This commit is contained in:
ridiculousfish 2012-03-25 18:38:33 -07:00
parent 0bdf7a598a
commit fa346cec3b
7 changed files with 43 additions and 7 deletions

View file

@ -599,6 +599,8 @@ install-force: all install-translations
$(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/fish/completions $(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/fish/completions
$(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/fish/functions $(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/fish/functions
$(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/fish/man $(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 etc/config.fish $(DESTDIR)$(sysconfdir)/fish/
$(INSTALL) -m 644 share/config.fish $(DESTDIR)$(datadir)/fish/ $(INSTALL) -m 644 share/config.fish $(DESTDIR)$(datadir)/fish/
for i in $(COMPLETIONS_DIR_FILES); do \ for i in $(COMPLETIONS_DIR_FILES); do \
@ -613,6 +615,19 @@ install-force: all install-translations
$(INSTALL) -m 644 $$i $(DESTDIR)$(datadir)/fish/man/; \ $(INSTALL) -m 644 $$i $(DESTDIR)$(datadir)/fish/man/; \
true; \ true; \
done; 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) $(INSTALL) -m 755 -d $(DESTDIR)$(docdir)
for i in user_doc/html/* ChangeLog; do \ for i in user_doc/html/* ChangeLog; do \
if test -f $$i; then \ if test -f $$i; then \

View file

@ -0,0 +1,3 @@
function fish_config --description "Launch fish's web based configuration"
eval $__fish_datadir/tools/web_config/webconfig.py
end

View file

@ -4,7 +4,7 @@ import SimpleHTTPServer
import SocketServer import SocketServer
import webbrowser import webbrowser
import subprocess import subprocess
import re, json, socket, sys, cgi import re, json, socket, os, sys, cgi, select
def run_fish_cmd(text): def run_fish_cmd(text):
from subprocess import PIPE from subprocess import PIPE
@ -93,7 +93,6 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
for match in re.finditer(r"^fish_color_(\S+) ?(.*)", line): for match in re.finditer(r"^fish_color_(\S+) ?(.*)", line):
color_name, color_value = match.group(1, 2) color_name, color_value = match.group(1, 2)
result.append([color_name.strip(), parse_color(color_value)]) result.append([color_name.strip(), parse_color(color_value)])
print result
return result return result
def do_get_functions(self): def do_get_functions(self):
@ -200,7 +199,6 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
background_color = postvars.get('background_color') background_color = postvars.get('background_color')
bold = postvars.get('bold') bold = postvars.get('bold')
underline = postvars.get('underline') underline = postvars.get('underline')
print "underline: ", underline
if what: if what:
# Not sure why we get lists here? # 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])) 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 # Output JSON
json.dump(output, self.wfile) 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 PORT = 8000
while PORT <= 9000: while PORT <= 9000:
try: try:
@ -235,11 +242,22 @@ while PORT <= 9000:
PORT += 1 PORT += 1
if PORT > 9000: 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) sys.exit(-1)
webbrowser.open("http://localhost:%d" % PORT) url = 'http://localhost:%d' % PORT
print "serving at port", PORT print "Web config started at '%s'. Hit enter to stop." % url
httpd.serve_forever() 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()