diff options
-rw-r--r-- | .gitignore | 3 | ||||
-rwxr-xr-x | GIT-VERSION-GEN | 17 | ||||
-rw-r--r-- | Makefile | 85 | ||||
-rw-r--r-- | app.yaml | 19 | ||||
-rw-r--r-- | index.yaml | 11 | ||||
-rw-r--r-- | redirect.py | 71 | ||||
-rw-r--r-- | static/application_version | 0 | ||||
-rw-r--r-- | static/robots.txt | 8 |
8 files changed, 214 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a438a9c --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.pyc +/config.mak +/release diff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN new file mode 100755 index 0000000..6126f62 --- /dev/null +++ b/GIT-VERSION-GEN @@ -0,0 +1,17 @@ +#!/bin/sh + +VN=$(git describe --abbrev=8 HEAD 2>/dev/null) +case "$VN" in +v[0-9]*) : happy ;; +*) exit 1 ;; +esac + +dirty=$(sh -c 'git diff-index --name-only HEAD' 2>/dev/null) || dirty= +case "$dirty" in +'') + ;; +*) + VN="$VN-dirty" ;; +esac + +echo $VN diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f436819 --- /dev/null +++ b/Makefile @@ -0,0 +1,85 @@ +# android-issuetrackerredirect +# +# Define DATASTORE to the location where 'make serve' should store its +# runtime data files; by default this is /tmp/dev_appserver.datastore. +# +# Define REMOTE=1 to enable remote hosts to connect to the development +# web server started by 'make serve'. This may be a security risk. +# +# Define EMAIL=1 to enable sending email messages during 'make serve'. +# This may spam invalid addresses, so it is off by default. +# +# Define APPID to the unique Google App Engine application instance +# 'make update' will upload the application files to. +# +# Define DEV_APPSERVER to the location of dev_appserver.py from the +# Google App Engine SDK download. +# +# Define APPCFG to the location of appcfg.py from the Google App +# Engine SDK download. +# + +ifeq ($(shell uname),Darwin) + DEV_APPSERVER := python2.5 /usr/local/bin/dev_appserver.py +else + DEV_APPSERVER := dev_appserver.py +endif + +APPID = android-issuetrackerredirect +APPCFG = appcfg.py +CPIO = cpio -pd + +-include config.mak + +ifdef DATASTORE + WEB_ARG += --datastore_path=$(DATASTORE) +endif +ifeq (1,$(REMOTE)) + WEB_ARG += --address 0.0.0.0 +endif +ifeq (1,$(EMAIL)) + WEB_ARG += --enable_sendmail +endif + +R_WEB := release/web + +WEB_INCLUDE := $(strip \ + app.yaml \ + index.yaml \ + redirect.py \ + static \ +) + +## Top level targets +## + +all: web +release: release-web + +clean: + @rm -rf release *.pyc + +## Web application +## + +web: + +serve: web + $(DEV_APPSERVER) $(WEB_ARG) . + +release-web: web + @echo Building Android Issue Tracker Redirect `./GIT-VERSION-GEN` for $(APPID): + @rm -rf $(R_WEB) + @mkdir -p $(R_WEB) + @echo " Copying loose files" && \ + find $(WEB_INCLUDE) -print | $(CPIO) $(abspath $(R_WEB)) + @./GIT-VERSION-GEN >$(R_WEB)/static/application_version + @perl -pi -e 's/(application:).*/$$1 $(APPID)/' $(R_WEB)/app.yaml + @echo $(R_WEB) built for $(APPID). + +update: release-web + $(APPCFG) update $(R_WEB) + +version: + @printf '%s = ' '$(APPID)' + @curl http://$(APPID).appspot.com/application_version diff --git a/app.yaml b/app.yaml new file mode 100644 index 0000000..38cd13e --- /dev/null +++ b/app.yaml @@ -0,0 +1,19 @@ +application: android-issuetrackerredirect +version: 1 +runtime: python +api_version: 1 +default_expiration: 7d + +handlers: +- url: /(robots.txt) + static_files: static/\1 + upload: static/robots.txt + +- url: /(application_version) + static_files: static/\1 + mime_type: text/plain + expiration: 1s + upload: static/application_version + +- url: .* + script: redirect.py diff --git a/index.yaml b/index.yaml new file mode 100644 index 0000000..a3b9e05 --- /dev/null +++ b/index.yaml @@ -0,0 +1,11 @@ +indexes: + +# AUTOGENERATED + +# This index.yaml is automatically updated whenever the dev_appserver +# detects that a new type of query is run. If you want to manage the +# index.yaml file manually, remove the above marker line (the line +# saying "# AUTOGENERATED"). If you want to manage some indexes +# manually, move them above the marker line. The index.yaml file is +# automatically uploaded to the admin console when you next deploy +# your application using appcfg.py. diff --git a/redirect.py b/redirect.py new file mode 100644 index 0000000..22ac0e3 --- /dev/null +++ b/redirect.py @@ -0,0 +1,71 @@ +# Copyright 2008 Google Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Android Issue Tracker Redirect +""" + +PROJECT = 'http://code.google.com/p/android' + +from google.appengine.ext import webapp +from google.appengine.ext.webapp.util import run_wsgi_app + +def _CreateApplication(): + return webapp.WSGIApplication([ + (r'^/(\d+)$', RedirectExistingIssue), + (r'^/new$', RedirectNewIssue), + (r'^/entry$', RedirectNewIssue), + (r'^/create$', RedirectNewIssue), + (r'^/list$', RedirectList), + (r'^/', RedirectList), + (r'^/.*', PageNotFound), + ], + debug=False) + +class RedirectHandler(webapp.RequestHandler): + def issue(self, rest): + self.redirect('%s/issues/%s' % (PROJECT, rest), permanent=True) + +class RedirectExistingIssue(RedirectHandler): + def get(self, id): + self.issue('detail?id=%s' % id) + +class RedirectNewIssue(RedirectHandler): + def get(self): + self.issue('entry') + +class RedirectList(RedirectHandler): + def get(self): + self.issue('list') + +class PageNotFound(webapp.RequestHandler): + def get(self): + self.response.set_status(404) + self.response.headers['Content-Type'] = 'text/html; charset=utf-8' + self.response.out.write("""<html> +<head> + <title>Not Found</title> +</head> +<body> +<h1>Not Found</h1> +<p>The request resource is not available.</p> +<p>Try searching the <a href="%s/issues/list">active issue list</a>.</p> +</html> +""" % PROJECT) + +def main(): + run_wsgi_app(application) + +if __name__ == '__main__': + application = _CreateApplication() + main() diff --git a/static/application_version b/static/application_version new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/static/application_version diff --git a/static/robots.txt b/static/robots.txt new file mode 100644 index 0000000..c033917 --- /dev/null +++ b/static/robots.txt @@ -0,0 +1,8 @@ +# Directions for web crawlers. +# See http://www.robotstxt.org/wc/norobots.html. + +User-agent: HTTrack +User-agent: puf +User-agent: MSIECrawler +User-agent: Nutch +Disallow: / |