I really like how I can easily share files on a network using the SimpleHTTPServer, but I wish there was an option like “download entire directory”. Is there an easy (one liner) way to implement this?
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Look at the sources, e.g. online here. Right now, if you call the server with a URL that’s a directory, its
index.htmlfile is served, or, missing that, thelist_directorymethod is called. Presumably, you want instead to make azipfile with the directory’s contents (recursively, I imagine), and serve that? Obviously there’s no way to do it with a one-line change, since you want to replace what are now lines 68-80 (in methodsend_head) plus the whole of methodlist_directory, lines 98-137 — that’s already at least a change to over 50 lines;-).If you’re OK with a change of several dozen lines, not one, and the semantics I’ve described are what you want, you could of course build the required zipfile as a
cStringIO.StringIOobject with the ZipFile class, and populate it with an os.walk on the directory in question (assuming you want, recursively, to get all subdirectories as well). But it’s most definitely not going to be a one-liner;-).