Last active
October 7, 2016 07:26
-
-
Save dreness/d2e3480b3161e05ab9dc85bbd2f0e2bd to your computer and use it in GitHub Desktop.
simple twisted web server on windows
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
# This is needed because SimpleHTTPServer in the standard python distribution isn't good enough for my use case of | |
# serving large mp4 files. Pretty much every request fails with a broken pipe. | |
# Start with the 'babun' package to provide the cli environment, based on cygwin. Python is included. | |
# http://babun.github.io | |
# Install virtualenv | |
pip install virtualenv | |
# Create and activate virtualenv | |
virtualenv web_env | |
cd web_env | |
source Scripts/activate | |
# install additional packages | |
pip install Twisted pypiwin32 | |
# Start the web server, specifying the path to the document root | |
twistd -n web --path 'D:\shadowplay\Overwatch' | |
# That's it! Web service should be listening on 8080. | |
# NB: do not be fooled by cygwin's ability to access other volumes with posix path semantics. | |
# While this does work sometimes... | |
{ ~ } » python -c 'import os ; print os.listdir("/d/shadowplay");' | |
['.DS_Store', 'Call of Duty Ghosts', 'Desktop', 'Overwatch', 'shadow_tmp', 'TitanFall', 'World Of Warcraft'] | |
# ... once inside the venv with the pypiwin32 module loaded (which is required because I don't know, I don't do windows :), | |
# the posix path semantics stop working: | |
{ ~ } » cd web_env | |
{ web_env } » source Scripts/activate | |
(web_env) { web_env } » python -c 'import os ; print os.listdir("/d/shadowplay");' | |
Traceback (most recent call last): | |
File "<string>", line 1, in <module> | |
WindowsError: [Error 3] The system cannot find the path specified: '/d/shadowplay/*.*' | |
# move into the dir on the other volume, then ask python for the path of the current dir | |
(web_env) { web_env } » cd /d/shadowplay | |
(web_env) { shadowplay } » python -c 'import os ; print os.path.abspath(os.getcwd());' | |
D:\shadowplay | |
# using paths in this style works with pypiwin32 loaded... | |
(web_env) { shadowplay } » python -c 'import os ; print os.listdir("D:\shadowplay");' | |
['.DS_Store', 'Call of Duty Ghosts', 'Desktop', 'Overwatch', 'shadow_tmp', 'TitanFall', 'World Of Warcraft'] | |
# ... and also without the pypiwin32 module loaded | |
{ ~ } » [ -n "${VIRTUAL_ENV}" ] || echo "not in a venv" | |
not in a venv | |
{ ~ } » python -c 'import os ; print os.listdir("D:\shadowplay");' | |
['.DS_Store', 'Call of Duty Ghosts', 'Desktop', 'Overwatch', 'shadow_tmp', 'TitanFall', 'World Of Warcraft'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment