Browse Source

Merge pull request #1501 from TechEmpower/python-web2py

Python web2py
Brittany Mazza 10 years ago
parent
commit
61e32d459c

+ 1 - 0
.travis.yml

@@ -126,6 +126,7 @@ env:
     - "TESTDIR=Python/pyramid"
     - "TESTDIR=Python/pyramid"
     - "TESTDIR=Python/tornado"
     - "TESTDIR=Python/tornado"
     - "TESTDIR=Python/uwsgi"
     - "TESTDIR=Python/uwsgi"
+    - "TESTDIR=Python/web2py"
     - "TESTDIR=Python/wheezyweb"
     - "TESTDIR=Python/wheezyweb"
     - "TESTDIR=Python/wsgi"
     - "TESTDIR=Python/wsgi"
     - "TESTDIR=Racket/racket-ws"
     - "TESTDIR=Racket/racket-ws"

+ 45 - 0
frameworks/Python/web2py/README.md

@@ -0,0 +1,45 @@
+# web2py Benchmark Test 
+
+Main controller found [here](web2py/applications/app/controllers/default.py)
+
+Database model found [here](web2py/applications/app/models/db.py)
+
+Fortunes template found [here](web2py/applications/app/views/default/fortune.html)
+
+## Description
+
+web2py framework (http://www.web2py.com/)
+
+### Database
+
+MySQL
+
+### Server
+
+* Rocket (default web2py server)
+
+## Test URLs
+### JSON Encoding
+
+http://localhost:8080/json
+
+### Plaintext
+
+http://localhost:8080/plaintext
+
+### DB
+
+http://localhost:8080/db
+
+### Query
+
+http://localhost:8080/queries?queries=2
+
+### Update
+
+http://localhost:8080/updates?queries=2
+
+### Fortune
+
+http://localhost:8080/fortune
+

+ 2 - 0
frameworks/Python/web2py/app/app/ABOUT

@@ -0,0 +1,2 @@
+Write something about this app.
+Developed with web2py.

+ 4 - 0
frameworks/Python/web2py/app/app/LICENSE

@@ -0,0 +1,4 @@
+The web2py welcome app is licensed under public domain 
+(except for the css and js files that it includes, which have their own third party licenses).
+
+You can modify this license when you add your own code.

+ 1 - 0
frameworks/Python/web2py/app/app/__init__.py

@@ -0,0 +1 @@
+

+ 68 - 0
frameworks/Python/web2py/app/app/controllers/default.py

@@ -0,0 +1,68 @@
+# -*- coding: utf-8 -*-
+from random import randint
+from functools import partial
+import json as jsonOut
+
+def getQueryNum(queryString):
+    try:
+        num_queries = int(queryString)
+        if num_queries < 1:
+            return 1
+        if num_queries > 500:
+            return 500
+        return num_queries
+    except ValueError:
+         return 1
+
+def serializeWorld(world):
+    return {
+        "id" : world.id,
+        "randomNumber" : world.randomNumber
+    }
+
+def serializeFortune(fortune):
+    return {
+        "id" : fortune.id,
+        "message": fortune.message
+    }
+
+def plaintext():
+    response.headers["Content-Type"]="text/plain; charset=UTF-8"
+    return "Hello, World!"
+
+def json():
+    response.headers["Content-Type"]="application/json; charset=UTF-8"
+    return jsonOut.dumps({"message":"Hello, World!"})
+
+def db():
+    response.headers["Content-Type"]="application/json; charset=UTF-8"
+    wid = randint(1, 10000)
+    world = DATABASE.world[wid]
+    return jsonOut.dumps(serializeWorld(world))
+
+def queries():
+    response.headers["Content-Type"]="application/json; charset=UTF-8"
+    num_queries = getQueryNum(request.vars["queries"])
+    rp = partial(randint, 1, 10000)
+    worlds = [serializeWorld(DATABASE.world[rp()]) for _ in xrange(num_queries)]
+    return jsonOut.dumps(worlds)
+
+def updates():
+    response.headers["Content-Type"]="application/json; charset=UTF-8"
+    num_queries = getQueryNum(request.vars["queries"])
+    worlds = []
+    rp = partial(randint, 1, 10000)
+    ids = [rp() for _ in xrange(num_queries)]
+    ids.sort() # To avoid deadlock
+    for id in ids:
+        world = DATABASE(DATABASE.world.id==id).select()[0]
+        world.randomNumber = rp()
+        worlds.append(serializeWorld(world))
+    return jsonOut.dumps(worlds)
+
+def fortune():
+    fortunes = DATABASE(DATABASE.fortune).select()
+    fortune_list = fortunes.as_list();
+    fortune_list.append({"id":0, "message":"Additional fortune added at request time."})
+    fortune_list = sorted(fortune_list, key=lambda k: k["message"])
+    return dict(fortunes=fortune_list)

+ 47 - 0
frameworks/Python/web2py/app/app/models/db.py

@@ -0,0 +1,47 @@
+# -*- coding: utf-8 -*-
+
+#########################################################################
+## This scaffolding model makes your app work on Google App Engine too
+## File is released under public domain and you can use without limitations
+#########################################################################
+
+## if SSL/HTTPS is properly configured and you want all HTTP requests to
+## be redirected to HTTPS, uncomment the line below:
+# request.requires_https()
+
+## app configuration made easy. Look inside private/appconfig.ini
+from gluon.contrib.appconfig import AppConfig
+## once in production, remove reload=True to gain full speed
+myconf = AppConfig(reload=True)
+
+DATABASE = None
+DATABASE_URI = "mysql://benchmarkdbuser:benchmarkdbpass@localhost:3306/hello_world"
+
+if not request.env.web2py_runtime_gae:
+    ## if NOT running on Google App Engine use SQLite or other DB
+    db = DAL(DATABASE_URI, fake_migrate_all=True)
+    DATABASE = db
+else:
+    ## connect to Google BigTable (optional 'google:datastore://namespace')
+    db = DAL(DATABASE_URI, fake_migrate_all=True)
+    DATABASE = db
+    ## store sessions and tickets there
+    session.connect(request, response, db=db)
+    ## or store session in Memcache, Redis, etc.
+    ## from gluon.contrib.memdb import MEMDB
+    ## from google.appengine.api.memcache import Client
+    ## session.connect(request, response, db = MEMDB(Client()))
+
+## by default give a view/generic.extension to all actions from localhost
+## none otherwise. a pattern can be 'controller/function.extension'
+response.generic_patterns = ['*'] if request.is_local else []
+
+db.define_table("world",
+    Field("id"),
+    Field("randomNumber")
+)
+
+db.define_table("fortune",
+    Field("id"),
+    Field("message")
+)

+ 19 - 0
frameworks/Python/web2py/app/app/private/appconfig.ini

@@ -0,0 +1,19 @@
+; App configuration
+
+; db configuration
+[db]
+uri       = sqlite://storage.sqlite
+migrate   = 1
+pool_size = 1
+
+; smtp address and credentials
+[smtp]
+server = smtp.gmail.com:587
+sender = [email protected]
+login  = username:password
+
+
+; form styling
+[forms]
+formstyle = bootstrap3_inline
+separator = 

+ 38 - 0
frameworks/Python/web2py/app/app/routes.example.py

@@ -0,0 +1,38 @@
+# -*- coding: utf-8 -*-
+
+#  This is an app-specific example router
+#
+#  This simple router is used for setting languages from app/languages directory
+#  as a part of the application path:  app/<lang>/controller/function
+#  Language from default.py or 'en' (if the file is not found) is used as
+#  a default_language
+#
+# See <web2py-root-dir>/router.example.py for parameter's detail
+#-------------------------------------------------------------------------------------
+# To enable this route file you must do the steps:
+#
+# 1. rename <web2py-root-dir>/router.example.py to routes.py
+# 2. rename this APP/routes.example.py to APP/routes.py
+#    (where APP - is your application directory)
+# 3. restart web2py (or reload routes in web2py admin interfase)
+#
+# YOU CAN COPY THIS FILE TO ANY APPLICATION'S ROOT DIRECTORY WITHOUT CHANGES!
+
+from fileutils import abspath
+from languages import read_possible_languages
+
+possible_languages = read_possible_languages(abspath('applications', app))
+#NOTE! app - is an application based router's parameter with name of an
+#            application. E.g.'welcome'
+
+routers = {
+    app: dict(
+        default_language = possible_languages['default'][0],
+        languages = [lang for lang in possible_languages
+                           if lang != 'default']
+    )
+}
+
+#NOTE! To change language in your application using these rules add this line
+#in one of your models files:
+#   if request.uri_language: T.force(request.uri_language)

+ 1 - 0
frameworks/Python/web2py/app/app/views/__init__.py

@@ -0,0 +1 @@
+

+ 15 - 0
frameworks/Python/web2py/app/app/views/default/fortune.html

@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <title>Fortunes</title>
+  </head>
+  <body>
+    <table><tr><th>id</th><th>message</th></tr>
+    {{for fortune in fortunes:}}
+      <tr><td>{{=fortune["id"]}}</td><td>{{=fortune["message"]}}</td></tr>
+      {{pass}}
+      </table>
+  </body>
+</html>
+
+

+ 52 - 0
frameworks/Python/web2py/app/app/views/default/index.html

@@ -0,0 +1,52 @@
+{{left_sidebar_enabled,right_sidebar_enabled=False,('message' in globals())}}
+{{extend 'layout.html'}}
+
+{{block header}}
+    <header class="container-fluid background">
+      <div class="jumbotron text-center">
+        {{if response.title:}}
+        <h1>{{=response.title}}
+          <small>{{=response.subtitle or ''}}</small></h1>
+        {{pass}}
+      </div>
+    </header>
+{{end}}
+
+{{if 'message' in globals():}}
+<h2>{{=message}}</h2>
+<p class="lead">{{=T('How did you get here?')}}</p>
+<ol>
+  <li>{{=T('You are successfully running web2py')}}</li>
+  <li>{{=XML(T('You visited the url %s', A(request.env.path_info,_href=request.env.path_info)))}}</li>
+  <li>{{=XML(T('Which called the function %s located in the file %s',
+    (A(request.function+'()',_href='#'),
+    A('web2py/applications/%(application)s/controllers/%(controller)s.py' % request,
+    _href=URL('admin','default','peek', args=(request.application,'controllers',request.controller+'.py'))))))}}</li>
+  <li>{{=XML(T('The output of the file is a dictionary that was rendered by the view %s',
+    A('web2py/applications/%(application)s/views/%(controller)s/index.html' % request,
+    _href=URL('admin','default','peek',args=(request.application,'views',request.controller,'index.html')))))}}</li>
+  <li>{{=T('You can modify this application and adapt it to your needs')}}</li>
+</ol>
+{{elif 'content' in globals():}}
+{{=content}}
+{{else:}}
+{{=BEAUTIFY(response._vars)}}
+{{pass}}
+
+{{block right_sidebar}}
+<div class="panel panel-info">
+  <div class="panel-heading"><h3 class="panel-title"><a class="btn-block"
+      href="{{=URL('admin','default','index')}}">
+      <i class="glyphicon glyphicon-cog"></i>
+      {{=T("admin")}}
+    </a></h3></div>
+  <div class="panel-body">
+    {{=T("Don't know what to do?")}}
+  </div>
+  <ul class="list-group">
+    <li class="list-group-item">{{=A(T("Online examples"), _href=URL('examples','default','index'))}}</li>
+    <li class="list-group-item"><a href="http://web2py.com">web2py.com</a></li>
+    <li class="list-group-item"><a href="http://web2py.com/book">{{=T('Documentation')}}</a></li>
+  </ul>
+</div>
+{{end}}

+ 35 - 0
frameworks/Python/web2py/app/app/views/default/user.html

@@ -0,0 +1,35 @@
+{{extend 'layout.html'}}
+
+<h2>
+{{=T('Sign Up') if request.args(0) == 'register' else T('Log In') if request.args(0) == 'login' else T(request.args(0).replace('_',' ').title())}}
+</h2>
+
+<div class="container">
+    <div class="row">
+        <div id="web2py_user_form" class="col-lg-6">
+        {{
+        if request.args(0)=='login':
+            if not 'register' in auth.settings.actions_disabled:
+                form.add_button(T('Sign Up'),URL(args='register', vars={'_next': request.vars._next} if request.vars._next else None),_class='btn btn-default')
+            pass
+            if not 'request_reset_password' in auth.settings.actions_disabled:
+                form.add_button(T('Lost Password'),URL(args='request_reset_password'),_class='btn btn-default')
+            pass
+        pass
+        =form
+        }}
+        </div>
+    </div>
+</div>
+
+
+{{block page_js}}
+<script>
+    jQuery("#web2py_user_form input:visible:enabled:first").focus();
+{{if request.args(0)=='register':}}
+    web2py_validate_entropy(jQuery('#auth_user_password'),100);
+{{elif request.args(0)=='change_password':}}
+    web2py_validate_entropy(jQuery('#no_table_new_password'),100);
+{{pass}}
+</script>
+{{end page_js}}

+ 16 - 0
frameworks/Python/web2py/app/app/views/generic.html

@@ -0,0 +1,16 @@
+{{extend 'layout.html'}}
+{{"""
+
+You should not modify this file. 
+It is used as default when a view is not provided for your controllers
+
+"""}}
+<h2>{{=' '.join(x.capitalize() for x in request.function.split('_'))}}</h2>
+{{if len(response._vars)==1:}}
+{{=BEAUTIFY(response._vars.values()[0])}}
+{{elif len(response._vars)>1:}}
+{{=BEAUTIFY(response._vars)}}
+{{pass}}
+{{if request.is_local:}}
+{{=response.toolbar()}}
+{{pass}}

+ 14 - 0
frameworks/Python/web2py/app/routes.py

@@ -0,0 +1,14 @@
+routers = dict(
+    BASE = dict(
+        default_application='app',
+    )
+)
+
+routes_in = (
+	("/json", "/app/default/json"),
+	("/plaintext", "/app/default/plaintext"),
+        ("/db", "/app/default/db"),
+	("/queries", "/app/default/queries"),
+	("/updates", "/app/default/updates"),
+	("/fortune", "/app/default/fortune")
+)

+ 27 - 0
frameworks/Python/web2py/benchmark_config.json

@@ -0,0 +1,27 @@
+{
+  "framework": "web2py",
+  "tests": [{
+    "default": {
+      "setup_file": "setup",
+      "plaintext_url": "/plaintext",
+      "json_url": "/json",
+      "db_url": "/db",
+      "query_url": "/queries?queries=",
+      "fortune_url": "/fortune",
+      "update_url": "/updates?queries=",
+      "port": 8080,
+      "approach": "Realistic",
+      "classification": "Micro",
+      "database": "MySQL",
+      "framework": "web2py",
+      "language": "Python",
+      "orm": "Full",
+      "platform": "web2Py",
+      "webserver": "None",
+      "os": "Linux",
+      "database_os": "Linux",
+      "display_name": "web2py",
+      "notes": "CPython 2.7"
+    } 
+  }]
+}

+ 18 - 0
frameworks/Python/web2py/install.sh

@@ -0,0 +1,18 @@
+#!/bin/bash
+
+mkdir -p $IROOT/.pip_cache
+
+export PIP_DOWNLOAD_CACHE=$IROOT/.pip_cache
+
+fw_depends python2
+
+export PY2_ROOT=$IROOT/py2
+export PY2_PIP=$PY2_ROOT/bin/pip
+
+$PY2_PIP install --install-option="--prefix=${PY2_ROOT}" -r $TROOT/requirements.txt
+
+cd $TROOT
+rm -fr web2py
+git clone --recursive --branch R-2.10.3 https://github.com/web2py/web2py.git 
+cp -r app/app/ web2py/applications/
+cp app/routes.py web2py/

+ 1 - 0
frameworks/Python/web2py/requirements.txt

@@ -0,0 +1 @@
+mysqlclient==1.3.6

+ 4 - 0
frameworks/Python/web2py/setup.sh

@@ -0,0 +1,4 @@
+export PY2_ROOT=$IROOT/py2
+export PY2=$PY2_ROOT/bin/python
+
+$PY2 web2py/web2py.py -a '' -i 127.0.0.1 -p 8080  &