Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d399ec5
Showing
3 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
|