annotate rhodecode/lib/timerproxy.py @ 1307:c1516b35f91d beta

pep8ify
author Marcin Kuzminski <marcin@python-works.com>
date Tue, 03 May 2011 16:54:43 +0200
parents 1fb97030b9b7
children 1f47adeb67c2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
49
3ada2f409c1c Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
1 from sqlalchemy.interfaces import ConnectionProxy
3ada2f409c1c Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
2 import time
1191
1fb97030b9b7 let timerproxy use logging module
Marcin Kuzminski <marcin@python-works.com>
parents: 1186
diff changeset
3 import logging
1fb97030b9b7 let timerproxy use logging module
Marcin Kuzminski <marcin@python-works.com>
parents: 1186
diff changeset
4 log = logging.getLogger('timerproxy')
1fb97030b9b7 let timerproxy use logging module
Marcin Kuzminski <marcin@python-works.com>
parents: 1186
diff changeset
5
153
a5a3bcc5ee89 Added colored formatter to project, and configs
Marcin Kuzminski <marcin@python-works.com>
parents: 90
diff changeset
6 BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE = xrange(30, 38)
a5a3bcc5ee89 Added colored formatter to project, and configs
Marcin Kuzminski <marcin@python-works.com>
parents: 90
diff changeset
7
1307
c1516b35f91d pep8ify
Marcin Kuzminski <marcin@python-works.com>
parents: 1191
diff changeset
8
153
a5a3bcc5ee89 Added colored formatter to project, and configs
Marcin Kuzminski <marcin@python-works.com>
parents: 90
diff changeset
9 def color_sql(sql):
a5a3bcc5ee89 Added colored formatter to project, and configs
Marcin Kuzminski <marcin@python-works.com>
parents: 90
diff changeset
10 COLOR_SEQ = "\033[1;%dm"
a5a3bcc5ee89 Added colored formatter to project, and configs
Marcin Kuzminski <marcin@python-works.com>
parents: 90
diff changeset
11 COLOR_SQL = YELLOW
a5a3bcc5ee89 Added colored formatter to project, and configs
Marcin Kuzminski <marcin@python-works.com>
parents: 90
diff changeset
12 normal = '\x1b[0m'
1186
b9ea10d3e419 timperproxy will just measure the time of queries, and formatting will be handled by the new sql_formatter of queries from sqlalchemy itself. Updated ini files for new way logging
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
13 return COLOR_SEQ % COLOR_SQL + sql + normal
49
3ada2f409c1c Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
14
1307
c1516b35f91d pep8ify
Marcin Kuzminski <marcin@python-works.com>
parents: 1191
diff changeset
15
49
3ada2f409c1c Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
16 class TimerProxy(ConnectionProxy):
1186
b9ea10d3e419 timperproxy will just measure the time of queries, and formatting will be handled by the new sql_formatter of queries from sqlalchemy itself. Updated ini files for new way logging
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
17
492
a5a17000e45b timeproxy logging memory leak fix.
Marcin Kuzminski <marcin@python-works.com>
parents: 462
diff changeset
18 def __init__(self):
a5a17000e45b timeproxy logging memory leak fix.
Marcin Kuzminski <marcin@python-works.com>
parents: 462
diff changeset
19 super(TimerProxy, self).__init__()
1186
b9ea10d3e419 timperproxy will just measure the time of queries, and formatting will be handled by the new sql_formatter of queries from sqlalchemy itself. Updated ini files for new way logging
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
20
b9ea10d3e419 timperproxy will just measure the time of queries, and formatting will be handled by the new sql_formatter of queries from sqlalchemy itself. Updated ini files for new way logging
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
21 def cursor_execute(self, execute, cursor, statement, parameters,
b9ea10d3e419 timperproxy will just measure the time of queries, and formatting will be handled by the new sql_formatter of queries from sqlalchemy itself. Updated ini files for new way logging
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
22 context, executemany):
b9ea10d3e419 timperproxy will just measure the time of queries, and formatting will be handled by the new sql_formatter of queries from sqlalchemy itself. Updated ini files for new way logging
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
23
49
3ada2f409c1c Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
24 now = time.time()
3ada2f409c1c Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
25 try:
1191
1fb97030b9b7 let timerproxy use logging module
Marcin Kuzminski <marcin@python-works.com>
parents: 1186
diff changeset
26 log.info(color_sql(">>>>> STARTING QUERY >>>>>"))
49
3ada2f409c1c Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
27 return execute(cursor, statement, parameters, context)
3ada2f409c1c Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
28 finally:
3ada2f409c1c Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
29 total = time.time() - now
1191
1fb97030b9b7 let timerproxy use logging module
Marcin Kuzminski <marcin@python-works.com>
parents: 1186
diff changeset
30 log.info(color_sql("<<<<< TOTAL TIME: %f <<<<<" % total))