Merge lp:~canonical-isd-hackers/canonical-identity-provider/revert_cleanup_command into lp:canonical-identity-provider/release

Proposed by Danny Tamez
Status: Merged
Approved by: Ricardo Kirkner
Approved revision: no longer in the source branch.
Merged at revision: 172
Proposed branch: lp:~canonical-isd-hackers/canonical-identity-provider/revert_cleanup_command
Merge into: lp:canonical-identity-provider/release
Diff against target: 52 lines (+12/-6)
1 file modified
identityprovider/management/commands/cleanup.py (+12/-6)
To merge this branch: bzr merge lp:~canonical-isd-hackers/canonical-identity-provider/revert_cleanup_command
Reviewer Review Type Date Requested Status
Ricardo Kirkner (community) Approve
Review via email: mp+67080@code.launchpad.net

Commit message

Reverting cleanup.py

Description of the change

Reverting cleanup.py

To post a comment you must log in.
Revision history for this message
Ricardo Kirkner (ricardokirkner) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'identityprovider/management/commands/cleanup.py'
2--- identityprovider/management/commands/cleanup.py 2011-06-15 16:36:56 +0000
3+++ identityprovider/management/commands/cleanup.py 2011-07-07 16:50:59 +0000
4@@ -1,7 +1,6 @@
5 # Copyright 2010 Canonical Ltd. This software is licensed under the
6 # GNU Affero General Public License version 3 (see the file LICENSE).
7
8-import sys
9 import textwrap
10 import time
11 from optparse import make_option
12@@ -11,6 +10,8 @@
13 from django.db import connection, transaction
14 from django.utils.translation import ugettext as _
15
16+from identityprovider.utils import is_django_13
17+
18
19 class Command(BaseCommand):
20
21@@ -42,21 +43,26 @@
22
23 selected_queries = [query for query in queries if options.get(query)]
24 if not selected_queries:
25- print textwrap.dedent("""
26+ self.console_out(textwrap.dedent("""
27 No items selected to clean up. Please select at least one of
28
29 --sessions
30 --nonces
31- """)
32+ """))
33
34 for item in selected_queries:
35 if verbosity >= 1:
36- print "\nCleaning %s..." % item
37+ self.console_out("\nCleaning %s..." % item)
38 cursor = connection.cursor()
39 cursor.execute(queries[item])
40 while cursor.rowcount > 0:
41 if verbosity >= 2:
42- print "."
43- sys.stdout.flush()
44+ self.console_out(".")
45 cursor.execute(queries[item])
46 transaction.commit_unless_managed()
47+
48+ def console_out(self, text):
49+ if not is_django_13():
50+ print text
51+ else:
52+ self.stdout.write(text)