Created
January 11, 2016 15:49
-
-
Save Michcioperz/cbf0bba2654ff3899b9c to your computer and use it in GitHub Desktop.
quick file sharing over network solution based on lighttpd
This file contains hidden or 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
#!/usr/bin/env python3 | |
import argparse, tempfile, subprocess, os | |
parser = argparse.ArgumentParser() | |
parser.add_argument("-p", "--port", type=int, default=5004) | |
args = parser.parse_args() | |
conffd, conffile = tempfile.mkstemp(suffix="hostmenow") | |
os.close(conffd) # because it's idiotic | |
with open(conffile, "w") as f: | |
f.write(""" | |
server.document-root = "%s" | |
server.port = %i | |
mimetype.assign = ( | |
".html" => "text/html", | |
".txt" => "text/plain", | |
".js" => "text/javascript", | |
".jpg" => "image/jpeg", | |
".png" => "image/png" | |
) | |
dir-listing.activate = "enable" | |
""" % (os.getcwd(), args.port)) | |
assert subprocess.call(["lighttpd", "-t", "-f", conffile]) == 0 | |
subprocess.call(["lighttpd", "-D", "-f", conffile]) | |
os.remove(conffile) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment