aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorGravatar Brendan Taylor <whateley@gmail.com>2010-12-05 20:02:32 -0700
committerGravatar Brendan Taylor <whateley@gmail.com>2010-12-05 20:02:32 -0700
commit9f1a37a1e6ad41cd6c3c27d103b38719d2af7244 (patch)
tree29bb600c6229844055bcdf86c0d0b416335432ac /examples
parent9e295f95eea8c80d6c5bf6e8b85a42630a72d44f (diff)
parente5cd5eccb1af0fdedd26d33180a25b1b0f83c258 (diff)
Merge remote branch 'mathstuf/dev/per-site-settings' into dev/per-site-settings
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/data/scripts/per-site-settings.py35
1 files changed, 17 insertions, 18 deletions
diff --git a/examples/data/scripts/per-site-settings.py b/examples/data/scripts/per-site-settings.py
index 6503a00..6629d09 100755
--- a/examples/data/scripts/per-site-settings.py
+++ b/examples/data/scripts/per-site-settings.py
@@ -55,13 +55,13 @@ def grep_url(url, path, fin):
# 2 == command
state = 0
for line in fin:
- raw = line.lstrip()
- indent = len(line) - len(raw)
+ raw = line.strip()
+
+ indent = len(line) - len(raw) - 1
if not indent:
# Reset state
passing = [False, False]
state = 0
- cur_indent = 0
else:
# previous level
if indent < cur_indent:
@@ -71,18 +71,19 @@ def grep_url(url, path, fin):
passing[1] = False
state -= 1
# next level
- if cur_indent < indent:
+ elif cur_indent < indent:
state += 1
- # parse the line
- if state == 0:
- if not passing[0] and match_url(url, raw):
- passing[0] = True
- elif state == 1 and passing[0]:
- if not passing[1] and match_path(path, raw):
- passing[1] = True
- elif state == 2 and passing[1]:
- entries.append(raw)
+ # parse the line
+ if state == 0:
+ if not passing[0] and match_url(url, raw):
+ passing[0] = True
+ elif state == 1 and passing[0]:
+ if not passing[1] and match_path(path, raw):
+ passing[1] = True
+ elif state == 2 and passing[1]:
+ entries.append(raw)
+
cur_indent = indent
return entries
@@ -92,7 +93,7 @@ def write_to_socket(commands, sockpath):
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
sock.connect(sockpath)
for command in commands:
- sock.write(command)
+ sock.send(command)
sock.close()
@@ -106,12 +107,10 @@ if __name__ == '__main__':
if mode & stat.S_IEXEC:
fin = tempfile.TemporaryFile()
subprocess.Popen([filepath], stdout=fin).wait()
- else
+ else:
fin = open(filepath, 'r')
- host, path = (url.hostname, url.path)
-
- commands = grep_url(host, path, fin)
+ commands = grep_url(url.hostname, url.path, fin)
fin.close()