/tests/functional/example-backup/main.py
Python | 41 lines | 39 code | 2 blank | 0 comment | 7 complexity | 2bd3ff53c0504cb55aeebf61d8317a04 MD5 | raw file
Possible License(s): GPL-2.0
- import MySQLdb
- import os
- import time
- import traceback
- def application(environ, start_response):
- try:
- import sys
- print >> sys.stderr, dict(host=os.environ['CONFIG_MYSQL_HOST'] or '127.0.0.1',
- user=os.environ['CONFIG_MYSQL_USER'],
- passwd=os.environ['CONFIG_MYSQL_PASSWORD'],
- db=os.environ['CONFIG_MYSQL_DBNAME'],
- port=int(os.environ['CONFIG_MYSQL_PORT'])
- if os.environ['CONFIG_MYSQL_PORT'] else None)
- kw = {}
- if os.environ['CONFIG_MYSQL_HOST']:
- kw['host'] = os.environ['CONFIG_MYSQL_HOST']
- if os.environ['CONFIG_MYSQL_PORT']:
- kw['port'] = int(os.environ['CONFIG_MYSQL_PORT'])
- if os.environ['CONFIG_MYSQL_PASSWORD']:
- kw['passwd'] = os.environ['CONFIG_MYSQL_PASSWORD']
- conn = MySQLdb.connect(user=os.environ['CONFIG_MYSQL_USER'],
- db=os.environ['CONFIG_MYSQL_DBNAME'],
- **kw)
- cur = conn.cursor()
- cur.execute("""
- CREATE TABLE IF NOT EXISTS test_table (
- id INT PRIMARY KEY AUTO_INCREMENT,
- name TEXT,
- value TEXT
- );
- """)
- cur.execute("""
- INSERT INTO test_table (name, value) VALUES (%s, %s)
- """, ('time_run', str(time.time())))
- start_response('200 OK', [('content-type', 'text/plain')])
- return ['Inserted']
- except:
- start_response('500 Server Error', [('content-type', 'text/plain')])
- return [traceback.format_exc()]