Permalink
Browse files

Initial import

  • Loading branch information...
0 parents commit 35b213633ab04d22049fafea8f9bf5cc9c82b97c giulivo committed Feb 22, 2012
Showing with 861 additions and 0 deletions.
  1. +3 −0 .gitignore
  2. +5 −0 .openshift/action_hooks/build
  3. +5 −0 .openshift/action_hooks/deploy
  4. +4 −0 .openshift/action_hooks/post_deploy
  5. +5 −0 .openshift/action_hooks/pre_build
  6. +22 −0 .openshift/cron/README.cron
  7. 0 .openshift/cron/daily/.gitignore
  8. 0 .openshift/cron/hourly/.gitignore
  9. 0 .openshift/cron/minutely/.gitignore
  10. 0 .openshift/cron/monthly/.gitignore
  11. +16 −0 .openshift/cron/weekly/README
  12. +1 −0 .openshift/cron/weekly/chrono.dat
  13. +3 −0 .openshift/cron/weekly/chronograph
  14. +12 −0 .openshift/cron/weekly/jobs.allow
  15. +7 −0 .openshift/cron/weekly/jobs.deny
  16. +7 −0 .openshift/markers/README
  17. +54 −0 README
  18. +9 −0 README.textile
  19. 0 data/.gitkeep
  20. 0 libs/.gitkeep
  21. +10 −0 setup.py
  22. +112 −0 wsgi/application
  23. BIN wsgi/static/hosted/images/ajax-loader.png
  24. BIN wsgi/static/hosted/images/icons-18-black.png
  25. BIN wsgi/static/hosted/images/icons-18-white.png
  26. BIN wsgi/static/hosted/images/icons-36-black.png
  27. BIN wsgi/static/hosted/images/icons-36-white.png
  28. +4 −0 wsgi/static/hosted/jquery-1.7.1.min.js
  29. +2 −0 wsgi/static/hosted/jquery.mobile-1.0.1.min.css
  30. +177 −0 wsgi/static/hosted/jquery.mobile-1.0.1.min.js
  31. +3 −0 wsgi/static/myshoppinglist.js
  32. +13 −0 wsgi/templates/404.html
  33. +32 −0 wsgi/templates/base.html
  34. +22 −0 wsgi/templates/index.html
  35. +37 −0 wsgi/templates/list.html
  36. +96 −0 wsgi/templates/msl.py
  37. +14 −0 wsgi/templates/open.html
  38. BIN wsgi/templates/static/hosted/images/ajax-loader.png
  39. BIN wsgi/templates/static/hosted/images/icons-18-black.png
  40. BIN wsgi/templates/static/hosted/images/icons-18-white.png
  41. BIN wsgi/templates/static/hosted/images/icons-36-black.png
  42. BIN wsgi/templates/static/hosted/images/icons-36-white.png
  43. +4 −0 wsgi/templates/static/hosted/jquery-1.7.1.min.js
  44. +2 −0 wsgi/templates/static/hosted/jquery.mobile-1.0.1.min.css
  45. +177 −0 wsgi/templates/static/hosted/jquery.mobile-1.0.1.min.js
  46. +3 −0 wsgi/templates/static/myshoppinglist.js
@@ -0,0 +1,3 @@
+*.pyc
+*.pyo
+*~
@@ -0,0 +1,5 @@
+#!/bin/bash
+# This is a simple build script and will be executed on your CI system if
+# available. Otherwise it will execute while your application is stopped
+# before the deploy step. This script gets executed directly, so it
+# could be python, php, ruby, etc.
@@ -0,0 +1,5 @@
+#!/bin/bash
+# This deploy hook gets executed after dependencies are resolved and the
+# build hook has been run but before the application has been started back
+# up again. This script gets executed directly, so it could be python, php,
+# ruby, etc.
@@ -0,0 +1,4 @@
+#!/bin/bash
+# This is a simple post deploy hook executed after your application
+# is deployed and started. This script gets executed directly, so
+# it could be python, php, ruby, etc.
@@ -0,0 +1,5 @@
+#!/bin/bash
+# This is a simple script and will be executed on your CI system if
+# available. Otherwise it will execute while your application is stopped
+# before the build step. This script gets executed directly, so it
+# could be python, php, ruby, etc.
@@ -0,0 +1,22 @@
+Run scripts or jobs on a periodic basis
+=======================================
+Any scripts or jobs added to the minutely, hourly, daily, weekly or monthly
+directories will be run on a scheduled basis (frequency is as indicated by the
+name of the directory) using run-parts.
+
+run-parts ignores any files that are hidden or dotfiles (.*) or backup
+files (*~ or *,) or named *.{rpmsave,rpmorig,rpmnew,swp,cfsaved}
+
+The presence of two specially named files jobs.deny and jobs.allow controls
+how run-parts executes your scripts/jobs.
+ jobs.deny ===> Prevents specific scripts or jobs from being executed.
+ jobs.allow ===> Only execute the named scripts or jobs (all other/non-named
+ scripts that exist in this directory are ignored).
+
+The principles of jobs.deny and jobs.allow are the same as those of cron.deny
+and cron.allow and are described in detail at:
+ http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/ch-Automating_System_Tasks.html#s2-autotasks-cron-access
+
+See: man crontab or above link for more details and see the the weekly/
+ directory for an example.
+
No changes.
No changes.
No changes.
No changes.
@@ -0,0 +1,16 @@
+Run scripts or jobs on a weekly basis
+=====================================
+Any scripts or jobs added to this directory will be run on a scheduled basis
+(weekly) using run-parts.
+
+run-parts ignores any files that are hidden or dotfiles (.*) or backup
+files (*~ or *,) or named *.{rpmsave,rpmorig,rpmnew,swp,cfsaved} and handles
+the files named jobs.deny and jobs.allow specially.
+
+In this specific example, the chronograph script is the only script or job file
+executed on a weekly basis (due to white-listing it in jobs.allow). And the
+README and chrono.dat file are ignored either as a result of being black-listed
+in jobs.deny or because they are NOT white-listed in the jobs.allow file.
+
+For more details, please see ../README.cron file.
+
@@ -0,0 +1 @@
+Time And Relative D...n In Execution (Open)Shift!
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+echo "`date`: `cat $(dirname \"$0\")/chrono.dat`"
@@ -0,0 +1,12 @@
+#
+# Script or job files listed in here (one entry per line) will be
+# executed on a weekly-basis.
+#
+# Example: The chronograph script will be executed weekly but the README
+# and chrono.dat files in this directory will be ignored.
+#
+# The README file is actually ignored due to the entry in the
+# jobs.deny which is checked before jobs.allow (this file).
+#
+chronograph
+
@@ -0,0 +1,7 @@
+#
+# Any script or job files listed in here (one entry per line) will NOT be
+# executed (read as ignored by run-parts).
+#
+
+README
+
@@ -0,0 +1,7 @@
+Markers
+===========
+
+Adding marker files to this directory will have the following effects:
+
+force_clean_build - Will remove the python virtualenv and force rebuild it
+ including any previously downloaded libraries
54 README
@@ -0,0 +1,54 @@
+Feel free to change or remove this file, it is informational only.
+
+Repo layout
+===========
+wsgi/ - Externally exposed wsgi code goes
+wsgi/static/ - Public static content gets served here
+libs/ - Additional libraries
+data/ - For not-externally exposed wsgi code
+setup.py - Standard setup.py, specify deps here
+../data - For persistent data (also env var: OPENSHIFT_DATA_DIR)
+.openshift/action_hooks/pre_build - Script that gets run every git push before the build
+.openshift/action_hooks/build - Script that gets run every git push as part of the build process (on the CI system if available)
+.openshift/action_hooks/deploy - Script that gets run every git push after build but before the app is restarted
+.openshift/action_hooks/post_deploy - Script that gets run every git push after the app is restarted
+
+
+Environment Variables
+=====================
+
+OpenShift Express provides several environment variables to reference for ease
+of use. The following list are some common variables but far from exhaustive:
+
+ os.environ['OPENSHIFT_APP_NAME'] - Application name
+ os.environ['OPENSHIFT_APP_DIR'] - Application dir
+ os.environ['OPENSHIFT_DATA_DIR'] - For persistent storage (between pushes)
+ os.environ['OPENSHIFT_TMP_DIR'] - Temp storage (unmodified files deleted after 10 days)
+
+When embedding a database using rhc-ctl-app, you can reference environment
+variables for username, host and password:
+
+ os.environ['OPENSHIFT_DB_HOST'] - DB host
+ os.environ['OPENSHIFT_DB_PORT'] - DB Port
+ os.environ['OPENSHIFT_DB_USERNAME'] - DB Username
+ os.environ['OPENSHIFT_DB_PASSWORD'] - DB Password
+
+To get a full list of environment variables, simply add a line in your
+.openshift/action_hooks/build script that says "export" and push.
+
+
+Notes about layout
+==================
+Please leave wsgi, libs and data directories but feel free to create additional
+directories if needed.
+
+Note: Every time you push, everything in your remote repo dir gets recreated
+please store long term items (like an sqlite database) in ../data which will
+persist between pushes of your repo.
+
+
+Notes about setup.py
+====================
+
+Adding deps to the install_requires will have the openshift server actually
+install those deps at git push time.
@@ -0,0 +1,9 @@
+h2. My Shopping List
+
+This is a demo app written using "flask":http://flask.pocoo.org/ and "jQuery Mobile":http://jquerymobile.com , stores data in a "MongoDB":http://www.mongodb.org database.
+
+The app allows you to save some shopping list to be used from your mobile phone when at the mall! :)
+
+The app is conveniently hosted on "OpenShift":http://openshift.redhat.com , which offers MongoDB instances for free, as well as support for any Python WSGI app. Flask is not installed globally, but we have it installed in virtenv.
+
+Enjoy!
No changes.
No changes.
@@ -0,0 +1,10 @@
+from setuptools import setup
+
+setup(name='MyShoppingList',
+ version='1.0',
+ description='Mobile Shopping List App',
+ author='Giulio Fidente',
+ author_email='gfidente@redhat.com',
+ url='http://www.python.org/sigs/distutils-sig/',
+ install_requires=['Flask', 'pymongo'],
+ )
@@ -0,0 +1,112 @@
+#!/usr/bin/python
+import os
+
+virtenv = os.environ['APPDIR'] + '/virtenv/'
+os.environ['PYTHON_EGG_CACHE'] = os.path.join(virtenv, 'lib/python2.6/site-packages')
+virtualenv = os.path.join(virtenv, 'bin/activate_this.py')
+try:
+ execfile(virtualenv, dict(__file__=virtualenv))
+except IOError:
+ pass
+#
+# IMPORTANT: Put any additional includes below this line. If placed above this
+# line, it's possible required libraries won't be in your searchable path
+#
+
+from flask import Flask
+from flask import render_template, redirect, url_for, request, abort
+
+from random import sample
+from pymongo import Connection
+
+#import os
+import string
+
+dbhost = os.environ['OPENSHIFT_NOSQL_DB_HOST']
+dbport = int(os.environ['OPENSHIFT_NOSQL_DB_PORT'])
+dbuser = os.environ['OPENSHIFT_NOSQL_DB_USERNAME']
+dbpass = os.environ['OPENSHIFT_NOSQL_DB_PASSWORD']
+
+application = Flask(__name__)
+title = "My Shopping List"
+
+@application.route('/')
+def index():
+ return render_template('index.html', title=title, listid='Welcome')
+
+@application.route('/create')
+def create():
+ mongo = Connection(dbhost, dbport)
+ db = mongo.myshoppinglist
+ db.authenticate(dbuser, dbpass)
+ lists = db.lists
+ list = {}
+ listid = "".join(sample(string.lowercase + string.digits, 6))
+ list["listid"] = listid
+ mongo.end_request()
+ return redirect('/view/' + listid)
+
+@application.route('/delete/<listid>')
+def delete(listid):
+ mongo = Connection(dbhost, dbport)
+ db = mongo.myshoppinglist
+ db.authenticate(dbuser, dbpass)
+ lists = db.lists
+ lists.remove({"listid": listid})
+ mongo.end_request()
+ return redirect('/')
+
+@application.route('/open', methods=['POST', 'GET'])
+def open():
+ if request.method == 'POST':
+ listid = request.form['listid']
+ db = mongo.myshoppinglist
+ lists = db.lists
+ if lists.find({"listid": listid}).count() > 0:
+ return redirect('/view/' + listid)
+ else:
+ abort(404)
+ return render_template('open.html', title=title, listid='Open')
+
+@application.route('/view/<listid>', methods=['POST', 'GET'])
+def view(listid):
+ if request.method == 'POST':
+ listitem = request.form['listitem']
+ add_to_list(listid, listitem)
+ mongo = Connection(dbhost, dbport)
+ db = mongo.myshoppinglist
+ db.authenticate(dbuser, dbpass)
+ lists = db.lists
+ entry = lists.find_one({"listid": listid})
+ mongo.end_request()
+ entries = entry['text'] if entry else ''
+ return render_template('list.html', title=title, listid=listid, entries=entries)
+
+@application.route('/clean/<listid>', methods=['POST'])
+def clean(listid):
+ if request.method == 'POST':
+ remove_from_list(listid, request.form.keys())
+ return redirect('/view/' + listid)
+
+@application.errorhandler(404)
+def page_not_found(error):
+ return render_template('404.html', title=title, listid='Error'), 404
+
+def add_to_list(listid, listitem):
+ mongo = Connection(dbhost, dbport)
+ db = mongo.myshoppinglist
+ db.authenticate(dbuser, dbpass)
+ lists = db.lists
+ lists.update({"listid":listid}, {"$push": {"text":listitem}}, upsert=True)
+ mongo.end_request()
+
+def remove_from_list(listid, listitems):
+ mongo = Connection(dbhost, dbport)
+ db = mongo.myshoppinglist
+ db.authenticate(dbuser, dbpass)
+ lists = db.lists
+ lists.update({"listid":listid}, {"$pullAll": {"text":listitems}})
+ mongo.end_request()
+
+if __name__ == '__main__':
+ application.run(debug=True)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 35b2136

Please sign in to comment.