Merge ~cjwatson/launchpad:services-database-print-function into launchpad:master
- Git
- lp:~cjwatson/launchpad
- services-database-print-function
- Merge into master
Proposed by
Colin Watson
Status: | Merged |
---|---|
Approved by: | Colin Watson |
Approved revision: | ea374c6ff68c637af89930b733ff3556f3d863d0 |
Merge reported by: | Otto Co-Pilot |
Merged at revision: | not available |
Proposed branch: | ~cjwatson/launchpad:services-database-print-function |
Merge into: | launchpad:master |
Diff against target: |
254 lines (+41/-31) 5 files modified
lib/lp/services/database/debug.py (+8/-6) lib/lp/services/database/postgresql.py (+9/-7) lib/lp/services/database/sort_sql.py (+4/-2) lib/lp/services/database/sqlbase.py (+16/-14) lib/lp/services/database/tests/script_isolation.py (+4/-2) |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Colin Watson (community) | Approve | ||
Review via email: mp+387849@code.launchpad.net |
Commit message
Port lp.services.
Description of the change
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | diff --git a/lib/lp/services/database/debug.py b/lib/lp/services/database/debug.py | |||
2 | index a061290..fef9033 100644 | |||
3 | --- a/lib/lp/services/database/debug.py | |||
4 | +++ b/lib/lp/services/database/debug.py | |||
5 | @@ -5,6 +5,8 @@ | |||
6 | 5 | Replace the psycopg connect method with one that returns a wrapped connection. | 5 | Replace the psycopg connect method with one that returns a wrapped connection. |
7 | 6 | ''' | 6 | ''' |
8 | 7 | 7 | ||
9 | 8 | from __future__ import absolute_import, print_function | ||
10 | 9 | |||
11 | 8 | import logging | 10 | import logging |
12 | 9 | import textwrap | 11 | import textwrap |
13 | 10 | import traceback | 12 | import traceback |
14 | @@ -19,15 +21,15 @@ def LN(*args, **kwargs): | |||
15 | 19 | A variable number of positional arguments are allowed. If | 21 | A variable number of positional arguments are allowed. If |
16 | 20 | LN(obj0, obj1, obj2) | 22 | LN(obj0, obj1, obj2) |
17 | 21 | is called, the text part of the output looks like the output from | 23 | is called, the text part of the output looks like the output from |
19 | 22 | print obj0, obj1, obj2 | 24 | print(obj0, obj1, obj2) |
20 | 23 | The optional keyword "wrap" causes the message to be line-wrapped. The | 25 | The optional keyword "wrap" causes the message to be line-wrapped. The |
21 | 24 | argument to "wrap" should be "1" or "True". "name" is another optional | 26 | argument to "wrap" should be "1" or "True". "name" is another optional |
22 | 25 | keyword parameter. This is best explained by an example: | 27 | keyword parameter. This is best explained by an example: |
23 | 26 | from linenum import LN | 28 | from linenum import LN |
24 | 27 | def fun1(): | 29 | def fun1(): |
26 | 28 | print LN('error', 'is', 'here') | 30 | print(LN('error', 'is', 'here')) |
27 | 29 | def fun2(): | 31 | def fun2(): |
29 | 30 | print LN('error', 'is', 'here', name='mess') | 32 | print(LN('error', 'is', 'here', name='mess')) |
30 | 31 | fun1() | 33 | fun1() |
31 | 32 | fun2() | 34 | fun2() |
32 | 33 | The output is: | 35 | The output is: |
33 | @@ -60,12 +62,12 @@ class ConnectionWrapper(object): | |||
34 | 60 | 62 | ||
35 | 61 | def __getattr__(self, key): | 63 | def __getattr__(self, key): |
36 | 62 | if key in ('rollback', 'close', 'commit'): | 64 | if key in ('rollback', 'close', 'commit'): |
38 | 63 | print '%s %r.__getattr__(%r)' % (LN(), self, key) | 65 | print('%s %r.__getattr__(%r)' % (LN(), self, key)) |
39 | 64 | self.__dict__['_log']('__getattr__(%r)', key) | 66 | self.__dict__['_log']('__getattr__(%r)', key) |
40 | 65 | return getattr(self._real_con, key) | 67 | return getattr(self._real_con, key) |
41 | 66 | 68 | ||
42 | 67 | def __setattr__(self, key, val): | 69 | def __setattr__(self, key, val): |
44 | 68 | print '%s %r.__setattr__(%r, %r)' % (LN(), self, key, val) | 70 | print('%s %r.__setattr__(%r, %r)' % (LN(), self, key, val)) |
45 | 69 | self.__dict__['_log']('__setattr__(%r, %r)', key, val) | 71 | self.__dict__['_log']('__setattr__(%r, %r)', key, val) |
46 | 70 | return setattr(self._real_con, key, val) | 72 | return setattr(self._real_con, key, val) |
47 | 71 | 73 | ||
48 | @@ -79,7 +81,7 @@ def debug_connect(*args, **kw): | |||
49 | 79 | logging.getLogger('lp.services.database.debug').debug( | 81 | logging.getLogger('lp.services.database.debug').debug( |
50 | 80 | 'connect(*%r, **%r) == %r', args, kw, con | 82 | 'connect(*%r, **%r) == %r', args, kw, con |
51 | 81 | ) | 83 | ) |
53 | 82 | print '%s connect(*%r, **%r) == %r' % (LN(), args, kw, con) | 84 | print('%s connect(*%r, **%r) == %r' % (LN(), args, kw, con)) |
54 | 83 | return con | 85 | return con |
55 | 84 | 86 | ||
56 | 85 | 87 | ||
57 | diff --git a/lib/lp/services/database/postgresql.py b/lib/lp/services/database/postgresql.py | |||
58 | index 2218f42..e6f8c38 100644 | |||
59 | --- a/lib/lp/services/database/postgresql.py | |||
60 | +++ b/lib/lp/services/database/postgresql.py | |||
61 | @@ -6,6 +6,8 @@ PostgreSQL specific helper functions, such as database introspection | |||
62 | 6 | and table manipulation | 6 | and table manipulation |
63 | 7 | """ | 7 | """ |
64 | 8 | 8 | ||
65 | 9 | from __future__ import absolute_import, print_function | ||
66 | 10 | |||
67 | 9 | __metaclass__ = type | 11 | __metaclass__ = type |
68 | 10 | 12 | ||
69 | 11 | import re | 13 | import re |
70 | @@ -39,7 +41,7 @@ def listReferences(cur, table, column, indirect=True, _state=None): | |||
71 | 39 | to change keys. | 41 | to change keys. |
72 | 40 | 42 | ||
73 | 41 | >>> for r in listReferences(cur, 'a', 'aid'): | 43 | >>> for r in listReferences(cur, 'a', 'aid'): |
75 | 42 | ... print repr(r) | 44 | ... print(repr(r)) |
76 | 43 | (u'a', u'selfref', u'a', u'aid', u'a', u'a') | 45 | (u'a', u'selfref', u'a', u'aid', u'a', u'a') |
77 | 44 | (u'b', u'aid', u'a', u'aid', u'c', u'c') | 46 | (u'b', u'aid', u'a', u'aid', u'c', u'c') |
78 | 45 | (u'c', u'aid', u'b', u'aid', u'a', u'a') | 47 | (u'c', u'aid', u'b', u'aid', u'a', u'a') |
79 | @@ -192,7 +194,7 @@ def listSequences(cur): | |||
80 | 192 | standalone. | 194 | standalone. |
81 | 193 | 195 | ||
82 | 194 | >>> for r in listSequences(cur): | 196 | >>> for r in listSequences(cur): |
84 | 195 | ... print repr(r) | 197 | ... print(repr(r)) |
85 | 196 | (u'public', u'a_aid_seq', u'a', u'aid') | 198 | (u'public', u'a_aid_seq', u'a', u'aid') |
86 | 197 | (u'public', u'standalone', None, None) | 199 | (u'public', u'standalone', None, None) |
87 | 198 | 200 | ||
88 | @@ -434,12 +436,12 @@ def allow_sequential_scans(cur, permission): | |||
89 | 434 | 436 | ||
90 | 435 | >>> allow_sequential_scans(cur, True) | 437 | >>> allow_sequential_scans(cur, True) |
91 | 436 | >>> cur.execute("SHOW enable_seqscan") | 438 | >>> cur.execute("SHOW enable_seqscan") |
93 | 437 | >>> print cur.fetchall()[0][0] | 439 | >>> print(cur.fetchall()[0][0]) |
94 | 438 | on | 440 | on |
95 | 439 | 441 | ||
96 | 440 | >>> allow_sequential_scans(cur, False) | 442 | >>> allow_sequential_scans(cur, False) |
97 | 441 | >>> cur.execute("SHOW enable_seqscan") | 443 | >>> cur.execute("SHOW enable_seqscan") |
99 | 442 | >>> print cur.fetchall()[0][0] | 444 | >>> print(cur.fetchall()[0][0]) |
100 | 443 | off | 445 | off |
101 | 444 | """ | 446 | """ |
102 | 445 | permission_value = 'false' | 447 | permission_value = 'false' |
103 | @@ -490,9 +492,9 @@ def fqn(namespace, name): | |||
104 | 490 | 492 | ||
105 | 491 | Quoting is done for the non trivial cases. | 493 | Quoting is done for the non trivial cases. |
106 | 492 | 494 | ||
108 | 493 | >>> print fqn('public', 'foo') | 495 | >>> print(fqn('public', 'foo')) |
109 | 494 | public.foo | 496 | public.foo |
111 | 495 | >>> print fqn(' foo ', '$bar') | 497 | >>> print(fqn(' foo ', '$bar')) |
112 | 496 | " foo "."$bar" | 498 | " foo "."$bar" |
113 | 497 | """ | 499 | """ |
114 | 498 | if re.search(r"[^a-z_]", namespace) is not None: | 500 | if re.search(r"[^a-z_]", namespace) is not None: |
115 | @@ -612,4 +614,4 @@ if __name__ == '__main__': | |||
116 | 612 | cur = con.cursor() | 614 | cur = con.cursor() |
117 | 613 | 615 | ||
118 | 614 | for table, column in listReferences(cur, 'person', 'id'): | 616 | for table, column in listReferences(cur, 'person', 'id'): |
120 | 615 | print '%32s %32s' % (table, column) | 617 | print('%32s %32s' % (table, column)) |
121 | diff --git a/lib/lp/services/database/sort_sql.py b/lib/lp/services/database/sort_sql.py | |||
122 | index 7ce77de..e43b727 100644 | |||
123 | --- a/lib/lp/services/database/sort_sql.py | |||
124 | +++ b/lib/lp/services/database/sort_sql.py | |||
125 | @@ -7,6 +7,8 @@ This library provides functions for the script sort_sql.py, which resides in | |||
126 | 7 | database/schema/. | 7 | database/schema/. |
127 | 8 | """ | 8 | """ |
128 | 9 | 9 | ||
129 | 10 | from __future__ import absolute_import, print_function | ||
130 | 11 | |||
131 | 10 | __metaclass__ = type | 12 | __metaclass__ = type |
132 | 11 | 13 | ||
133 | 12 | import re | 14 | import re |
134 | @@ -21,7 +23,7 @@ class Parser: | |||
135 | 21 | >>> p.feed("INSERT INTO foo (id, x) VALUES (1, 23);\n") | 23 | >>> p.feed("INSERT INTO foo (id, x) VALUES (1, 23);\n") |
136 | 22 | >>> p.feed("INSERT INTO foo (id, x) VALUES (2, 34);\n") | 24 | >>> p.feed("INSERT INTO foo (id, x) VALUES (2, 34);\n") |
137 | 23 | >>> for line in p.lines: | 25 | >>> for line in p.lines: |
139 | 24 | ... print repr(line) | 26 | ... print(repr(line)) |
140 | 25 | (None, "UPDATE foo SET bar='baz';") | 27 | (None, "UPDATE foo SET bar='baz';") |
141 | 26 | (None, '') | 28 | (None, '') |
142 | 27 | (1, 'INSERT INTO foo (id, x) VALUES (1, 23);') | 29 | (1, 'INSERT INTO foo (id, x) VALUES (1, 23);') |
143 | @@ -177,7 +179,7 @@ def print_lines_sorted(file, lines): | |||
144 | 177 | 179 | ||
145 | 178 | for line in block: | 180 | for line in block: |
146 | 179 | sort_value, string = line | 181 | sort_value, string = line |
148 | 180 | print >>file, string | 182 | print(string, file=file) |
149 | 181 | 183 | ||
150 | 182 | for line in lines: | 184 | for line in lines: |
151 | 183 | sort_value, string = line | 185 | sort_value, string = line |
152 | diff --git a/lib/lp/services/database/sqlbase.py b/lib/lp/services/database/sqlbase.py | |||
153 | index 26e3e7a..ca35d9f 100644 | |||
154 | --- a/lib/lp/services/database/sqlbase.py | |||
155 | +++ b/lib/lp/services/database/sqlbase.py | |||
156 | @@ -1,6 +1,8 @@ | |||
157 | 1 | # Copyright 2009-2012 Canonical Ltd. This software is licensed under the | 1 | # Copyright 2009-2012 Canonical Ltd. This software is licensed under the |
158 | 2 | # GNU Affero General Public License version 3 (see the file LICENSE). | 2 | # GNU Affero General Public License version 3 (see the file LICENSE). |
159 | 3 | 3 | ||
160 | 4 | from __future__ import absolute_import, print_function | ||
161 | 5 | |||
162 | 4 | __metaclass__ = type | 6 | __metaclass__ = type |
163 | 5 | __all__ = [ | 7 | __all__ = [ |
164 | 6 | 'block_implicit_flushes', | 8 | 'block_implicit_flushes', |
165 | @@ -423,15 +425,15 @@ def quote_identifier(identifier): | |||
166 | 423 | In SQL, identifiers are quoted using " rather than ' which is reserved | 425 | In SQL, identifiers are quoted using " rather than ' which is reserved |
167 | 424 | for strings. | 426 | for strings. |
168 | 425 | 427 | ||
170 | 426 | >>> print quoteIdentifier('hello') | 428 | >>> print(quoteIdentifier('hello')) |
171 | 427 | "hello" | 429 | "hello" |
173 | 428 | >>> print quoteIdentifier("'") | 430 | >>> print(quoteIdentifier("'")) |
174 | 429 | "'" | 431 | "'" |
176 | 430 | >>> print quoteIdentifier('"') | 432 | >>> print(quoteIdentifier('"')) |
177 | 431 | """" | 433 | """" |
179 | 432 | >>> print quoteIdentifier("\\") | 434 | >>> print(quoteIdentifier("\\")) |
180 | 433 | "\" | 435 | "\" |
182 | 434 | >>> print quoteIdentifier('\\"') | 436 | >>> print(quoteIdentifier('\\"')) |
183 | 435 | "\""" | 437 | "\""" |
184 | 436 | ''' | 438 | ''' |
185 | 437 | return '"%s"' % identifier.replace('"', '""') | 439 | return '"%s"' % identifier.replace('"', '""') |
186 | @@ -453,28 +455,28 @@ def convert_storm_clause_to_string(storm_clause): | |||
187 | 453 | >>> from lp.bugs.interfaces.bugtask import BugTaskImportance | 455 | >>> from lp.bugs.interfaces.bugtask import BugTaskImportance |
188 | 454 | >>> from storm.expr import And, Or | 456 | >>> from storm.expr import And, Or |
189 | 455 | 457 | ||
191 | 456 | >>> print convert_storm_clause_to_string(BugTask) | 458 | >>> print(convert_storm_clause_to_string(BugTask)) |
192 | 457 | BugTask | 459 | BugTask |
193 | 458 | 460 | ||
195 | 459 | >>> print convert_storm_clause_to_string(BugTask.id == 16) | 461 | >>> print(convert_storm_clause_to_string(BugTask.id == 16)) |
196 | 460 | BugTask.id = 16 | 462 | BugTask.id = 16 |
197 | 461 | 463 | ||
200 | 462 | >>> print convert_storm_clause_to_string( | 464 | >>> print(convert_storm_clause_to_string( |
201 | 463 | ... BugTask.importance == BugTaskImportance.UNKNOWN) | 465 | ... BugTask.importance == BugTaskImportance.UNKNOWN)) |
202 | 464 | BugTask.importance = 999 | 466 | BugTask.importance = 999 |
203 | 465 | 467 | ||
205 | 466 | >>> print convert_storm_clause_to_string(Bug.title == "foo'bar'") | 468 | >>> print(convert_storm_clause_to_string(Bug.title == "foo'bar'")) |
206 | 467 | Bug.title = E'foo''bar''' | 469 | Bug.title = E'foo''bar''' |
207 | 468 | 470 | ||
209 | 469 | >>> print convert_storm_clause_to_string( | 471 | >>> print(convert_storm_clause_to_string( |
210 | 470 | ... Or(BugTask.importance == BugTaskImportance.UNKNOWN, | 472 | ... Or(BugTask.importance == BugTaskImportance.UNKNOWN, |
212 | 471 | ... BugTask.importance == BugTaskImportance.HIGH)) | 473 | ... BugTask.importance == BugTaskImportance.HIGH))) |
213 | 472 | BugTask.importance = 999 OR BugTask.importance = 40 | 474 | BugTask.importance = 999 OR BugTask.importance = 40 |
214 | 473 | 475 | ||
216 | 474 | >>> print convert_storm_clause_to_string( | 476 | >>> print(convert_storm_clause_to_string( |
217 | 475 | ... And(Bug.title == 'foo', BugTask.bug == Bug.id, | 477 | ... And(Bug.title == 'foo', BugTask.bug == Bug.id, |
218 | 476 | ... Or(BugTask.importance == BugTaskImportance.UNKNOWN, | 478 | ... Or(BugTask.importance == BugTaskImportance.UNKNOWN, |
220 | 477 | ... BugTask.importance == BugTaskImportance.HIGH))) | 479 | ... BugTask.importance == BugTaskImportance.HIGH)))) |
221 | 478 | Bug.title = E'foo' AND BugTask.bug = Bug.id AND | 480 | Bug.title = E'foo' AND BugTask.bug = Bug.id AND |
222 | 479 | (BugTask.importance = 999 OR BugTask.importance = 40) | 481 | (BugTask.importance = 999 OR BugTask.importance = 40) |
223 | 480 | """ | 482 | """ |
224 | diff --git a/lib/lp/services/database/tests/script_isolation.py b/lib/lp/services/database/tests/script_isolation.py | |||
225 | index 887c1b4..6f9843b 100644 | |||
226 | --- a/lib/lp/services/database/tests/script_isolation.py | |||
227 | +++ b/lib/lp/services/database/tests/script_isolation.py | |||
228 | @@ -5,6 +5,8 @@ | |||
229 | 5 | settings work. Note we need to use a non-default isolation level to | 5 | settings work. Note we need to use a non-default isolation level to |
230 | 6 | confirm that the changes are actually being made by the API calls.""" | 6 | confirm that the changes are actually being made by the API calls.""" |
231 | 7 | 7 | ||
232 | 8 | from __future__ import absolute_import, print_function | ||
233 | 9 | |||
234 | 8 | __metaclass__ = type | 10 | __metaclass__ = type |
235 | 9 | __all__ = [] | 11 | __all__ = [] |
236 | 10 | 12 | ||
237 | @@ -26,7 +28,7 @@ def check(): | |||
238 | 26 | cur = cursor() | 28 | cur = cursor() |
239 | 27 | cur.execute("UPDATE Person SET homepage_content='foo' WHERE name='mark'") | 29 | cur.execute("UPDATE Person SET homepage_content='foo' WHERE name='mark'") |
240 | 28 | cur.execute("SHOW transaction_isolation") | 30 | cur.execute("SHOW transaction_isolation") |
242 | 29 | print cur.fetchone()[0] | 31 | print(cur.fetchone()[0]) |
243 | 30 | 32 | ||
244 | 31 | transaction.abort() | 33 | transaction.abort() |
245 | 32 | transaction.begin() | 34 | transaction.begin() |
246 | @@ -34,7 +36,7 @@ def check(): | |||
247 | 34 | cur = cursor() | 36 | cur = cursor() |
248 | 35 | cur.execute("UPDATE Person SET homepage_content='bar' WHERE name='mark'") | 37 | cur.execute("UPDATE Person SET homepage_content='bar' WHERE name='mark'") |
249 | 36 | cur.execute("SHOW transaction_isolation") | 38 | cur.execute("SHOW transaction_isolation") |
251 | 37 | print cur.fetchone()[0] | 39 | print(cur.fetchone()[0]) |
252 | 38 | 40 | ||
253 | 39 | dbconfig.override(dbuser='launchpad_main', isolation_level='read_committed') | 41 | dbconfig.override(dbuser='launchpad_main', isolation_level='read_committed') |
254 | 40 | disconnect_stores() | 42 | disconnect_stores() |
Self-approving, since this is trivial and mechanical.