PageRenderTime 34ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/functional/example-backup/main.py

https://bitbucket.org/ianb/silverlining/
Python | 41 lines | 39 code | 2 blank | 0 comment | 7 complexity | 2bd3ff53c0504cb55aeebf61d8317a04 MD5 | raw file
Possible License(s): GPL-2.0
  1. import MySQLdb
  2. import os
  3. import time
  4. import traceback
  5. def application(environ, start_response):
  6. try:
  7. import sys
  8. print >> sys.stderr, dict(host=os.environ['CONFIG_MYSQL_HOST'] or '127.0.0.1',
  9. user=os.environ['CONFIG_MYSQL_USER'],
  10. passwd=os.environ['CONFIG_MYSQL_PASSWORD'],
  11. db=os.environ['CONFIG_MYSQL_DBNAME'],
  12. port=int(os.environ['CONFIG_MYSQL_PORT'])
  13. if os.environ['CONFIG_MYSQL_PORT'] else None)
  14. kw = {}
  15. if os.environ['CONFIG_MYSQL_HOST']:
  16. kw['host'] = os.environ['CONFIG_MYSQL_HOST']
  17. if os.environ['CONFIG_MYSQL_PORT']:
  18. kw['port'] = int(os.environ['CONFIG_MYSQL_PORT'])
  19. if os.environ['CONFIG_MYSQL_PASSWORD']:
  20. kw['passwd'] = os.environ['CONFIG_MYSQL_PASSWORD']
  21. conn = MySQLdb.connect(user=os.environ['CONFIG_MYSQL_USER'],
  22. db=os.environ['CONFIG_MYSQL_DBNAME'],
  23. **kw)
  24. cur = conn.cursor()
  25. cur.execute("""
  26. CREATE TABLE IF NOT EXISTS test_table (
  27. id INT PRIMARY KEY AUTO_INCREMENT,
  28. name TEXT,
  29. value TEXT
  30. );
  31. """)
  32. cur.execute("""
  33. INSERT INTO test_table (name, value) VALUES (%s, %s)
  34. """, ('time_run', str(time.time())))
  35. start_response('200 OK', [('content-type', 'text/plain')])
  36. return ['Inserted']
  37. except:
  38. start_response('500 Server Error', [('content-type', 'text/plain')])
  39. return [traceback.format_exc()]