Skip to content

Commit

Permalink
Adds GAE support
Browse files Browse the repository at this point in the history
  • Loading branch information
hufman committed Jul 4, 2013
1 parent fde10d7 commit 1f054a5
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.pyc
gae_bundle

25 changes: 25 additions & 0 deletions app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
application: vgmdbapi
version: 1
runtime: python27
api_version: 1
threadsafe: true

env_variables:
GAE_BASEURL: https://vgmdbapi.appspot.com/

handlers:
- url: /static
static_dir: static
- url: /.*
script: wsgi.application

libraries:
- name: markupsafe
version: latest
- name: lxml
version: latest
- name: yaml
version: latest
- name: setuptools
version: latest

30 changes: 30 additions & 0 deletions create_gae_bundle.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash
# Based off of CauliflowerVest's script
ROOT=$(dirname "$0")
BUNDLE_ROOT="$ROOT"/gae_bundle

[ -e "$BUNDLE_ROOT" ] && rm -rf "$BUNDLE_ROOT"
mkdir -p "$BUNDLE_ROOT"

copiedfiles="app.yaml wsgi.py vgmdb static"
for name in $copiedfiles; do
ln -s ../"$name" "$BUNDLE_ROOT"/"$name"
done

function find_module() {
python <<EOF
import imp
try:
print imp.find_module('$1'.split('.')[0])[1]
except ImportError:
pass
EOF
}

deps="bottle.py bs4 isodate jinja2 rdflib simplejson yaml"
for dep in $deps; do
depdir=$(find_module $dep)
[ -z "$depdir" ] && echo "Failed to find $dep" && continue
ln -s "$depdir" "$BUNDLE_ROOT"/$dep
done

30 changes: 30 additions & 0 deletions vgmdb/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
except:
pass

memcache = None
try:
import memcache
except:
Expand All @@ -13,6 +14,12 @@
except:
pass

gaecache = None
try:
from google.appengine.api import memcache as gaecache
except:
pass

class NullCache(object):
def __getitem__(self, key):
return None
Expand All @@ -37,12 +44,35 @@ def __setitem__(self, key, value):
except:
pass

class GaeCache(object):
def __init__(self):
self._gaecache = gaecache
def __getitem__(self, key):
# returns the value or None
try:
value = self._gaecache.get(key)
if value:
value = json.loads(value)
except:
return None
return value
def __setitem__(self, key, value):
try:
self._gaecache.set(key, json.dumps(value), time=86400)
except:
pass

cache = NullCache()
if memcache:
try:
cache = MemcacheCache(['127.0.0.1:11211'])
except:
pass
if gaecache:
try:
cache = GaeCache()
except:
pass

def get(key):
return cache[key]
Expand Down
5 changes: 5 additions & 0 deletions vgmdb/config.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
import os

BASE_URL = 'http://hufman.dyndns.org/vgmdb/'
AUTO_RELOAD = True

if os.environ.has_key('GAE_BASEURL'):
BASE_URL = os.environ['GAE_BASEURL']

0 comments on commit 1f054a5

Please sign in to comment.