From ec0d37e0c0cb304332909a05bd9f984463b6fcae Mon Sep 17 00:00:00 2001 From: Marc Pervaz Boocha Date: Wed, 31 Aug 2022 17:39:04 +0530 Subject: Initial Commit --- .local/bin/http-dir | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100755 .local/bin/http-dir (limited to '.local/bin/http-dir') diff --git a/.local/bin/http-dir b/.local/bin/http-dir new file mode 100755 index 0000000..a1dd19d --- /dev/null +++ b/.local/bin/http-dir @@ -0,0 +1,29 @@ +#!/usr/bin/env python3 + +import argparse +import http.server +import os +import sys + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('--bind', '-b', metavar='ADDRESS',default='', help='specify alternate bind address (default: all interfaces)') + parser.add_argument('--directory', '-d', default=os.getcwd(), help='specify alternate directory (default: current directory)') + parser.add_argument('port', action='store', default=8000, type=int, + nargs='?', help='specify alternate port (default: 8000)') + args = parser.parse_args() + + class app(http.server.SimpleHTTPRequestHandler): + def __init__(self, request, client_address, server): + super().__init__(request, client_address, server, directory=args.directory) + + with http.server.ThreadingHTTPServer((args.bind, args.port), app) as httpd: + try: + httpd.serve_forever() + except KeyboardInterrupt: + sys.exit() + + + +if __name__ == '__main__': + main() -- cgit v1.2.3-70-g09d2