Skip to content

Commit 0856ad1

Browse files
NonameNoname
Noname
authored and
Noname
committed
Better
1 parent f53610a commit 0856ad1

File tree

4 files changed

+23
-11
lines changed

4 files changed

+23
-11
lines changed

python/fserver.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,18 @@ def error(self, req):
3737
'''
3838

3939
@click.command('start')
40-
@click.option('--port', '-p', default=9999)
40+
@click.option('--port', '-p', default=9999, help="FastCGI port number on localhost")
4141
@click.option('--ip', '-h', default='127.0.0.1')
42-
@click.option('--vhost', '-v', default='cloudfire-demo.coinkite.com')
42+
@click.option('--vhost', '-v', help="Virtual hostname to use")
4343
@click.option('--redis-url', '-r', default='redis://localhost:6379/', help="URL for Redis server")
44-
@click.option('--debug', '-d', is_flag=True, help="Runs locally as web server")
45-
def start_server(ip, port, debug, redis_url, vhost):
44+
@click.option('--devmode', '-d', is_flag=False, help="Runs locally as web server. Dev only")
45+
def start_server(ip, port, devmode, redis_url, vhost):
4646
from example_app import app
4747

4848
RDB = redis.Redis.from_url(redis_url)
4949

5050
app.my_vhosts.append(vhost)
5151
app.redis = RDB
52-
app.debug = True
5352

5453
app.start_bg_tasks()
5554

@@ -61,8 +60,9 @@ def start_server(ip, port, debug, redis_url, vhost):
6160
sys.exit(1)
6261

6362

64-
if debug:
65-
app.run(host="0.0.0.0", port=port, debug=True)
63+
if devmode:
64+
app.debug = True
65+
app.run(host="0.0.0.0", port=port)
6666
else:
6767
print "Running as FastCGI at %s:%d" % (ip, port)
6868
MyWSGIServer(app, bindAddress=(ip, port), multiplexed=True, umask=0).run()

python/start.sh

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/sh
2+
#
3+
# NOTE: this assumes you're using a virtualenv called "ENV" in this directory
4+
#
5+
PY=ENV/bin/python
6+
VHOST=cloudfire-demo.coinkite.com
7+
8+
# update in-memory version of static files
9+
$PY upload.py multi http://$VHOST/static/ ../img
10+
11+
# start a fast-cgi server.
12+
$PY fserver.py -r unix:../redis.sock --vhost $VHOST

python/static

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../img

python/upload.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def blacklist_filename(fn):
2626
return False
2727

2828
def better_mimes(fname):
29+
# sigh, mimetypes.guess_type is incomplete...
2930
if fname.endswith('.svg'):
3031
return 'image/svg+xml'
3132
if fname.endswith('.md'):
@@ -69,11 +70,9 @@ def upload_file(host, fd, absurl):
6970
needs_write = False
7071

7172
ct, enc = guess_type(absurl, strict=False)
72-
print "%s = %s" % (absurl, ct)
7373
if not ct:
7474
ct = better_mimes(absurl)
75-
if not ct:
76-
ct = 'text/html'
75+
assert ct, "No good mime type for: %s" % absurl
7776
if not enc and ct and ct.startswith('text/'):
7877
enc = 'utf-8'
7978

@@ -125,7 +124,7 @@ def multi(baseurl, topdir):
125124
continue
126125
fname = os.path.join(root, fn)
127126
url = os.path.join(baseurl, fname[len(topdir)+1:])
128-
print '%s => %s' % (fname, url)
127+
#print '%s => %s' % (fname, url)
129128
wr = upload_file(host, click.open_file(fname), url)
130129
if wr: needs_write = True
131130

0 commit comments

Comments
 (0)