Skip to content
This repository has been archived by the owner on Nov 16, 2022. It is now read-only.

Commit

Permalink
Merge pull request #263 from gratipay/startapp
Browse files Browse the repository at this point in the history
Upgrading Aspen to 0.37+
  • Loading branch information
chadwhitacre committed Jul 10, 2015
2 parents 9e39f78 + fbb9fab commit cb0042e
Show file tree
Hide file tree
Showing 15 changed files with 69 additions and 22 deletions.
7 changes: 6 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ python:
install:
- make env

before_script:
- make run&
- sleep 3 # Give webserver some time to start

# Dummy command until we have real tests
script: true
script:
- curl http://localhost:8536/

branches:
only:
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ clean:
find . -name \*.pyc -delete

run: env
./$(env_bin)/honcho -e defaults.env,local.env run ./env/bin/aspen \
--network_address :8536 --www_root=./www/ --project_root=./
./$(env_bin)/honcho -e defaults.env,local.env run ./env/bin/python \
./startapp.py --port=8536
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
web: aspen --network_address :$PORT --www_root=./www/ --project_root=./
web: python startapp.py --port=$PORT
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

[![Build Status](https://travis-ci.org/gratipay/inside.gratipay.com.svg)](https://travis-ci.org/gratipay/inside.gratipay.com)

**NOTE**: The quickstart may not work until vendorized
`virtualenv` + `pip` are upgraded to latest versions
that can handle wheels. So, for now you can create
virtualenv, install dependencies and run manually with:

```
virtualenv env
./env/bin/pip install -f vendor -r requirements.txt
./env/bin/python startapp.py
```


Quickstart:

```
Expand Down
17 changes: 8 additions & 9 deletions configure-aspen.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,14 @@
def add_nav_to_website(website):
website.nav = NavItem(website, None, website.www_root, '')

def add_nav_current_to_context(request, website):
fs = request.fs
if basename(request.fs) in website.indices:
fs = dirname(fs)
request.context['nav_current'] = website.nav.by_fs.get(fs, website.nav)

def add_nav_next_to_context(request, website):
nav_current = request.context['nav_current']
request.context['nav_next'] = nav_current.next_child
def add_nav_current_to_context(dispatch_result, website):
path = dispatch_result.match
if basename(path) in website.indices:
path = dirname(path)
return {'nav_current': website.nav.by_fs.get(path, website.nav)}

def add_nav_next_to_context(nav_current, website):
return {'nav_next': nav_current.next_child}

add_nav_to_website(website)

Expand Down
5 changes: 1 addition & 4 deletions nav.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@


def get_simplate_context(website, fs):
request = Request()
request.fs = fs
request.website = website
resource = resources.get(request)
resource = resources.get(website, fs)
return {} if isinstance(resource, StaticResource) else resource.pages[0]


Expand Down
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

Cheroot==4.0.0beta
aspen==0.37
filesystem_tree==1.0.1
first==2.0.1
mimeparse==0.1.3
first==2.0.0
dependency_injection==1.1.0
algorithm==1.0.0
aspen==0.28.3

MarkupSafe==0.18
Jinja2==2.7.1
Expand Down
32 changes: 32 additions & 0 deletions startapp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env python
"""
The main script to start website for development,
which also exports WSGI application for production.
"""

HOST = '' # by default run on all interfaces
PORT = 8537 # default/devserver port

import sys
from aspen.website import Website

aspen_config = [
'--www_root=www/',
'--project_root=.'
]

for param in sys.argv:
if param.startswith('--port'):
_, PORT = param.split('=')
PORT = int(PORT)


# by WSGI convention, we need to create webapp object
# and by default most WSGI servers look for 'application'
application = Website(aspen_config)

if __name__ == '__main__':
from wsgiref.simple_server import make_server
print("* Running development server on http://%s:%s" % (HOST, PORT))
make_server(HOST, PORT, application).serve_forever()

Binary file removed vendor/Cheroot-4.0.0beta.tar.gz
Binary file not shown.
Binary file removed vendor/aspen-0.28.3.tar.bz2
Binary file not shown.
Binary file added vendor/aspen-0.37-py27-none-any.whl
Binary file not shown.
Binary file added vendor/filesystem_tree-1.0.1.tar.gz
Binary file not shown.
Binary file removed vendor/first-2.0.0.tar.gz
Binary file not shown.
Binary file added vendor/first-2.0.1-py2.py3-none-any.whl
Binary file not shown.
6 changes: 4 additions & 2 deletions www/howto/index.spt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import os

nav_title = 'How To'
nav_children = [ name.rsplit('.', 1)[0] for name in os.listdir('howto')
if name.endswith('.spt') and name not in ('.', '..', 'index.spt')]
nav_children = []
for entry in os.listdir(os.path.join(website.www_root, 'howto')):
if entry.endswith('.spt') and entry not in ('.', '..', 'index.spt'):
nav_children.append(entry.rsplit('.', 1)[0])
nav_children.sort()
[---]
[---] text/html
Expand Down

0 comments on commit cb0042e

Please sign in to comment.