Skip to content

Instantly share code, notes, and snippets.

@eight
Created February 24, 2010 04:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eight/313096 to your computer and use it in GitHub Desktop.
Save eight/313096 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# coding: utf-8
####################################################################
# dullyhttpd.py
# $Id: dullyhttpd.py,v 1.2 2005/04/20 08:37:11 ymo Exp $
#
# メンテナンスなどで、一時的にどこのURLにアクセスしても、
# 同じメッセージを表示するために作ったもの。dully httpd.
#
# 例えば、80番ポートで動くApacheなどをシャットダウンした状態で
# dullyhttpdを80番ポートで動かしておくと、どこのURLにアクセスがあっても、
# コマンドラインで渡したファイルが送信される。
# オブジェクト指向万歳スクリプト。
#
# 使い方: dullyhttpd.py ポート番号 ファイル名
#
####################################################################
import sys,os
import BaseHTTPServer,SimpleHTTPServer
class DullyHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def translate_path(self, path):
print "request path: %s" % path
path = os.path.abspath(sys.argv[2])
return path
def dully(HandlerClass = DullyHTTPRequestHandler, ServerClass = BaseHTTPServer.HTTPServer):
SimpleHTTPServer.test(HandlerClass, ServerClass)
if __name__ == '__main__':
if len(sys.argv) < 3:
print """Usage: %s port filename
""" % os.path.basename(sys.argv[0])
sys.exit()
dully()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment