Skip to content

Commit

Permalink
Folderizing the repository.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Wayne Parrott committed Nov 25, 2015
0 parents commit b24924e
Show file tree
Hide file tree
Showing 142 changed files with 8,633 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# Distribution / packaging
.Python
env/

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover

*.log

lib/
*.internal
secrets.tar.gz
client_secret.json
25 changes: 25 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
sudo: false
language: python
env:
matrix:
- STEP=1-hello-world
- STEP=2-structured-data
- STEP=3-binary-data
- STEP=4-auth
- STEP=5-logging
- STEP=6-pubsub
- STEP=7-gce
global:
- GOOGLE_APPLICATION_CREDENTIALS=$TRAVIS_BUILD_DIR/client-secret.json
before_install:
- openssl aes-256-cbc -K $encrypted_82d8befc5c58_key -iv $encrypted_82d8befc5c58_iv
-in secrets.tar.gz.enc -out secrets.tar.gz -d
- tar -xzf secrets.tar.gz
- pip install tox
before_script:
- echo $GOOGLE_APPLICATION_CREDENTIALS
- ls $TRAVIS_BUILD_DIR
- cp config.py $TRAVIS_BUILD_DIR/$STEP
- cd $TRAVIS_BUILD_DIR/$STEP
script:
- tox
17 changes: 17 additions & 0 deletions 1-hello-world/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
__pycache__
*.pyc
*.pyo
*.pyd
.Python
env
pip-log.txt
pip-delete-this-directory.txt
.tox
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
*.log
.git
41 changes: 41 additions & 0 deletions 1-hello-world/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright 2015 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.

# [START docker]
# The Google App Engine python runtime is Debian Jessie with Python installed
# and various os-level packages to allow installation of popular Python
# libraries. The source is on github at:
# https://github.com/GoogleCloudPlatform/python-docker
FROM gcr.io/google_appengine/python

# Create a virtualenv for the application dependencies.
# If you want to use Python 3, add the -p python3.4 flag.
RUN virtualenv /env

# Set virtualenv environment variables. This is equivalent to running
# source /env/bin/activate. This ensures the application is executed within
# the context of the virtualenv and will have access to its dependencies.
ENV VIRTUAL_ENV /env
ENV PATH /env/bin:$PATH

# Install dependencies.
ADD requirements.txt /app/requirements.txt
RUN pip install -r /app/requirements.txt

# Add application code.
ADD . /app

# Use Gunicorn to serve the application.
CMD gunicorn -b :$PORT main:app
# [END docker]
32 changes: 32 additions & 0 deletions 1-hello-world/app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright 2015 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.

# This file specifies your Python application's runtime configuration
# including URL routing, versions, static file uploads, etc. See
# https://developers.google.com/appengine/docs/python/config/appconfig
# for details.

# TODO: Enter your application id below. If you have signed up
# using cloud.google.com/console use the "project id" for your application
# id.

# [START runtime]
runtime: custom
vm: true
entrypoint: custom
# [END runtime]

# Temporary setting to keep gcloud from uploading the virtualenv
skip_files:
- ^v?env$
30 changes: 30 additions & 0 deletions 1-hello-world/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright 2015 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.

# [START app]
from flask import Flask


app = Flask(__name__)


@app.route('/')
def hello():
"""Return a friendly HTTP greeting."""
return 'Hello World!'


if __name__ == '__main__':
app.run(host='127.0.0.1', port=8080)
# [END app]
2 changes: 2 additions & 0 deletions 1-hello-world/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Flask==0.10.1
gunicorn==19.3.0
10 changes: 10 additions & 0 deletions 1-hello-world/tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[tox]
skipsdist = True
envlist = lint

[testenv:lint]
deps =
flake8
flake8-import-order
commands =
flake8 --exclude=env --import-order-style=google
17 changes: 17 additions & 0 deletions 2-structured-data/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
__pycache__
*.pyc
*.pyo
*.pyd
.Python
env
pip-log.txt
pip-delete-this-directory.txt
.tox
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
*.log
.git
39 changes: 39 additions & 0 deletions 2-structured-data/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright 2015 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

# The Google App Engine python runtime is Debian Jessie with Python installed
# and various os-level packages to allow installation of popular Python
# libraries. The source is on github at:
# https://github.com/GoogleCloudPlatform/python-docker
FROM gcr.io/google_appengine/python

# Create a virtualenv for the application dependencies.
# If you want to use Python 3, add the -p python3.4 flag.
RUN virtualenv /env

# Set virtualenv environment variables. This is equivalent to running
# source /env/bin/activate. This ensures the application is executed within
# the context of the virtualenv and will have access to its dependencies.
ENV VIRTUAL_ENV /env
ENV PATH /env/bin:$PATH

# Install dependencies.
ADD requirements.txt /app/requirements.txt
RUN pip install -r /app/requirements.txt

# Add application code.
ADD . /app

# Use Gunicorn to serve the application.
CMD gunicorn -b :$PORT main:app
23 changes: 23 additions & 0 deletions 2-structured-data/app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2015 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.

# This file specifies your Python application's runtime configuration.
# See https://cloud.google.com/appengine/docs/managed-vms/config for details.
runtime: custom
vm: true
entrypoint: custom

# Temporary setting to keep gcloud from uploading the virtualenv
skip_files:
- ^v?env$
61 changes: 61 additions & 0 deletions 2-structured-data/bookshelf/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Copyright 2015 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.

from flask import current_app, Flask, redirect, url_for


def create_app(config, debug=False, testing=False, config_overrides=None):
app = Flask(__name__)
app.config.from_object(config)

app.debug = debug
app.testing = testing

if config_overrides:
app.config.update(config_overrides)

# Setup the data model.
with app.app_context():
model = get_model()
model.init_app(app)

# Register the Bookshelf CRUD blueprint.
from .crud import crud
app.register_blueprint(crud, url_prefix='/books')

# Add a default root route.
@app.route("/")
def index():
return redirect(url_for('crud.list'))

return app


def get_model():
model_backend = current_app.config['DATA_BACKEND']
if model_backend == 'cloudsql':
from . import model_cloudsql
model = model_cloudsql
elif model_backend == 'datastore':
from . import model_datastore
model = model_datastore
elif model_backend == 'mongodb':
from . import model_mongodb
model = model_mongodb
else:
raise ValueError(
"No appropriate databackend configured. "
"Please specify datastore, cloudsql, or mongodb")

return model
Loading

0 comments on commit b24924e

Please sign in to comment.