annotate rhodecode/lib/timerproxy.py @ 4116:ffd45b185016 rhodecode-2.2.5-gpl

Imported some of the GPLv3'd changes from RhodeCode v2.2.5. This imports changes between changesets 21af6c4eab3d and 6177597791c2 in RhodeCode's original repository, including only changes to Python files and HTML. RhodeCode clearly licensed its changes to these files under GPLv3 in their /LICENSE file, which states the following: The Python code and integrated HTML are licensed under the GPLv3 license. (See: https://code.rhodecode.com/rhodecode/files/v2.2.5/LICENSE or http://web.archive.org/web/20140512193334/https://code.rhodecode.com/rhodecode/files/f3b123159901f15426d18e3dc395e8369f70ebe0/LICENSE for an online copy of that LICENSE file) Conservancy reviewed these changes and confirmed that they can be licensed as a whole to the Kallithea project under GPLv3-only. While some of the contents committed herein are clearly licensed GPLv3-or-later, on the whole we must assume the are GPLv3-only, since the statement above from RhodeCode indicates that they intend GPLv3-only as their license, per GPLv3ยง14 and other relevant sections of GPLv3.
author Bradley M. Kuhn <bkuhn@sfconservancy.org>
date Wed, 02 Jul 2014 19:03:13 -0400
parents bf263968da47
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 1512
diff changeset
1 # -*- coding: utf-8 -*-
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 1512
diff changeset
2 # This program is free software: you can redistribute it and/or modify
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 1512
diff changeset
3 # it under the terms of the GNU General Public License as published by
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 1512
diff changeset
4 # the Free Software Foundation, either version 3 of the License, or
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 1512
diff changeset
5 # (at your option) any later version.
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 1512
diff changeset
6 #
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 1512
diff changeset
7 # This program is distributed in the hope that it will be useful,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 1512
diff changeset
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 1512
diff changeset
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 1512
diff changeset
10 # GNU General Public License for more details.
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 1512
diff changeset
11 #
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 1512
diff changeset
12 # You should have received a copy of the GNU General Public License
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 1512
diff changeset
13 # along with this program. If not, see <http://www.gnu.org/licenses/>.
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 1512
diff changeset
14
49
3ada2f409c1c Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
15 import time
1191
1fb97030b9b7 let timerproxy use logging module
Marcin Kuzminski <marcin@python-works.com>
parents: 1186
diff changeset
16 import logging
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 1512
diff changeset
17 from sqlalchemy.interfaces import ConnectionProxy
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 1512
diff changeset
18
1191
1fb97030b9b7 let timerproxy use logging module
Marcin Kuzminski <marcin@python-works.com>
parents: 1186
diff changeset
19 log = logging.getLogger('timerproxy')
1fb97030b9b7 let timerproxy use logging module
Marcin Kuzminski <marcin@python-works.com>
parents: 1186
diff changeset
20
153
a5a3bcc5ee89 Added colored formatter to project, and configs
Marcin Kuzminski <marcin@python-works.com>
parents: 90
diff changeset
21 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
22
1307
c1516b35f91d pep8ify
Marcin Kuzminski <marcin@python-works.com>
parents: 1191
diff changeset
23
153
a5a3bcc5ee89 Added colored formatter to project, and configs
Marcin Kuzminski <marcin@python-works.com>
parents: 90
diff changeset
24 def color_sql(sql):
a5a3bcc5ee89 Added colored formatter to project, and configs
Marcin Kuzminski <marcin@python-works.com>
parents: 90
diff changeset
25 COLOR_SEQ = "\033[1;%dm"
a5a3bcc5ee89 Added colored formatter to project, and configs
Marcin Kuzminski <marcin@python-works.com>
parents: 90
diff changeset
26 COLOR_SQL = YELLOW
a5a3bcc5ee89 Added colored formatter to project, and configs
Marcin Kuzminski <marcin@python-works.com>
parents: 90
diff changeset
27 normal = '\x1b[0m'
1360
1f47adeb67c2 Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents: 1307
diff changeset
28 return ''.join([COLOR_SEQ % COLOR_SQL, sql, normal])
49
3ada2f409c1c Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
29
1307
c1516b35f91d pep8ify
Marcin Kuzminski <marcin@python-works.com>
parents: 1191
diff changeset
30
49
3ada2f409c1c Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
31 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
32
492
a5a17000e45b timeproxy logging memory leak fix.
Marcin Kuzminski <marcin@python-works.com>
parents: 462
diff changeset
33 def __init__(self):
a5a17000e45b timeproxy logging memory leak fix.
Marcin Kuzminski <marcin@python-works.com>
parents: 462
diff changeset
34 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
35
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
36 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
37 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
38
49
3ada2f409c1c Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
39 now = time.time()
3ada2f409c1c Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
40 try:
1191
1fb97030b9b7 let timerproxy use logging module
Marcin Kuzminski <marcin@python-works.com>
parents: 1186
diff changeset
41 log.info(color_sql(">>>>> STARTING QUERY >>>>>"))
49
3ada2f409c1c Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
42 return execute(cursor, statement, parameters, context)
3ada2f409c1c Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
43 finally:
3ada2f409c1c Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
44 total = time.time() - now
1191
1fb97030b9b7 let timerproxy use logging module
Marcin Kuzminski <marcin@python-works.com>
parents: 1186
diff changeset
45 log.info(color_sql("<<<<< TOTAL TIME: %f <<<<<" % total))