~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to database/replication/report.py

  • Committer: Jeroen Vermeulen
  • Date: 2011-09-19 06:57:55 UTC
  • mto: This revision was merged to the branch mainline in revision 13994.
  • Revision ID: jeroen.vermeulen@canonical.com-20110919065755-lgot1hi4xfqrf492
Lint.  Lots of lint.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/python -S
2
2
#
3
 
# Copyright 2009 Canonical Ltd.  This software is licensed under the
 
3
# Copyright 2009-2011 Canonical Ltd.  This software is licensed under the
4
4
# GNU Affero General Public License version 3 (see the file LICENSE).
5
5
 
6
6
"""Generate a report on the replication setup.
16
16
__metaclass__ = type
17
17
__all__ = []
18
18
 
19
 
import _pythonpath
20
 
 
21
19
from cgi import escape as html_escape
22
20
from cStringIO import StringIO
23
21
from optparse import OptionParser
24
22
import sys
25
23
 
26
 
from canonical.database.sqlbase import connect, quote_identifier, sqlvalues
 
24
import _pythonpath
 
25
import replication.helpers
 
26
 
 
27
from canonical.database.sqlbase import (
 
28
    connect,
 
29
    quote_identifier,
 
30
    sqlvalues,
 
31
    )
27
32
from canonical.launchpad.scripts import db_options
28
 
import replication.helpers
29
33
 
30
34
 
31
35
class Table:
32
 
    labels = None # List of labels to render as the first row of the table.
33
 
    rows = None # List of rows, each row being a list of strings.
 
36
    """Representation of a table.
34
37
 
 
38
    :ivar labels: List of labels to render as the table's first row.
 
39
    :ivar rows: List of rows, each being a list of strings.
 
40
    """
35
41
    def __init__(self, labels=None):
36
42
        if labels is None:
37
43
            self.labels = []
76
82
        for label in table.labels:
77
83
            max_col_widths.append(len(label))
78
84
        for row in table.rows:
79
 
            row = list(row) # We need len()
80
 
            for col_idx in range(0,len(row)):
81
 
                col = row[col_idx]
 
85
            for col_idx, col in enumerate(row):
82
86
                max_col_widths[col_idx] = max(
83
 
                    len(str(row[col_idx])), max_col_widths[col_idx])
 
87
                    len(str(col)), max_col_widths[col_idx])
84
88
 
85
89
        out = StringIO()
86
90
        for label_idx in range(0, len(table.labels)):
88
92
                max_col_widths[label_idx]),
89
93
        print >> out
90
94
        for width in max_col_widths:
91
 
            print >> out, '='*width,
 
95
            print >> out, '=' * width,
92
96
        print >> out
93
97
        for row in table.rows:
94
98
            row = list(row)
95
99
            for col_idx in range(0, len(row)):
96
 
                print >> out, str(row[col_idx]).ljust(max_col_widths[col_idx]),
 
100
                print >> out, str(
 
101
                    row[col_idx]).ljust(max_col_widths[col_idx]),
97
102
            print >> out
98
103
        print >> out
99
104
 
266
271
                % replication.helpers.CLUSTERNAME)
267
272
        return 1
268
273
 
269
 
 
270
274
    # Set our search path to the schema of the cluster we care about.
271
275
    cur.execute(
272
276
            "SET search_path TO %s, public"