Skip to content

Commit

Permalink
Hacks
Browse files Browse the repository at this point in the history
  • Loading branch information
anandology committed Feb 7, 2009
0 parents commit d399ec5
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 0 deletions.
22 changes: 22 additions & 0 deletions doctest
@@ -0,0 +1,22 @@
#! /usr/bin/env python

import doctest
import os.path

def test(filename, verbose=False):
base, ext = os.path.splitext(filename)
name = base.replace(os.path.sep, '.')
mod = __import__(name, None, None, ['x'])
doctest.testmod(mod, verbose=verbose)

if __name__ == "__main__":
import sys
sys.path.insert(0, '.')

if '-v' in sys.argv:
sys.argv.remove('-v')
verbose = True
else:
verbose = False

test(sys.argv[1], verbose)
69 changes: 69 additions & 0 deletions lightty
@@ -0,0 +1,69 @@
#! /usr/bin/env python
#
# Script to run a given script as fastcgi using Lighttpd.
#
# vim:syntax=python

import sys
import os
import string

CONF = """
server.modules = ("mod_fastcgi", "mod_rewrite", "mod_accesslog", "mod_redirect")
server.document-root = "$root"
fastcgi.server = ( "/$script" =>
((
"socket" => ".fastcgi.$script.socket",
"bin-path" => "$root/$script",
"max-procs" => 1,
"bin-environment" => (
"REAL_SCRIPT_NAME" => ""
),
"check-local" => "disable"
))
)
url.rewrite-once = (
"^/favicon.ico$$" => "/static/favicon.ico",
"^/static/(.*)$$" => "/static/$$1",
"^/(.*)$$" => "/$script/$$1"
)
server.errorlog = "/dev/tty"
accesslog.filename = "/dev/tty"
server.port = $port
"""

def make_config(root, script, port):
return string.Template(CONF).substitute(locals())

def intget(x, index, default=None):
try:
return x[index]
except IndexError:
return default

def setup_path():
paths = ["/usr/sbin", "/usr/local/sbin"]
path = os.getenv('PATH') + ":" + ":".join(paths)
os.putenv("PATH", path)

def main():
script = sys.argv[1]
root = os.path.abspath(os.path.dirname(script))
script = os.path.basename(script)
port = intget(sys.argv, 2, 8080)

f = open('.lightty.conf', 'w')
f.write(make_config(root, script, port))
f.close()

setup_path()
os.system("lighttpd -D -f .lightty.conf")
os.unlink(".lightty.conf")

if __name__ == "__main__":
main()
16 changes: 16 additions & 0 deletions pyvi
@@ -0,0 +1,16 @@
#! /usr/bin/env python

import sys
import os

mod = __import__(sys.argv[1], {}, {}, ['x'])
file = mod.__file__

print file

if file.endswith('.pyc'):
file = file[:-1]

os.chdir(os.path.dirname(file))
os.system('vim ' + file)

0 comments on commit d399ec5

Please sign in to comment.