~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to database/replication/report.py

  • Committer: Stuart Bishop
  • Date: 2008-09-29 11:46:39 UTC
  • mto: This revision was merged to the branch mainline in revision 7142.
  • Revision ID: stuart.bishop@canonical.com-20080929114639-r3vxcmpf02pxk8qy
Improve initialize, less magic dev setup

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 
24
24
from canonical.database.sqlbase import connect, quote_identifier, sqlvalues
25
25
from canonical.launchpad.scripts import db_options
 
26
import replication.helpers
26
27
 
27
28
 
28
29
class Table:
234
235
def main():
235
236
    parser = OptionParser()
236
237
 
237
 
    # Default should be pulled from a config file.
238
 
    parser.add_option(
239
 
        "-c", "--cluster", dest="cluster", default="lpsl",
240
 
        help="Report on cluster CLUSTER_NAME", metavar="CLUSTER_NAME")
241
238
    parser.add_option(
242
239
        "-f", "--format", dest="mode", default="text",
243
240
        choices=['text', 'html'],
253
250
    else:
254
251
        assert False, "Unknown mode %s" % options.mode
255
252
 
256
 
    cluster_schema = "_%s" % options.cluster
257
 
 
258
253
    con = connect(options.dbuser)
259
254
    cur = con.cursor()
260
255
 
261
 
    # Check if the Slony schema exists to validate the --cluster option.
262
256
    cur.execute(
263
257
            "SELECT TRUE FROM pg_namespace WHERE nspname=%s"
264
 
            % sqlvalues(cluster_schema))
 
258
            % sqlvalues(replication.helpers.CLUSTER_NAMESPACE))
265
259
 
266
260
    if cur.fetchone() is None:
267
261
        parser.error(
268
262
                "No Slony-I cluster called %s in that database"
269
 
                % options.cluster)
 
263
                % replication.helpers.CLUSTERNAME)
270
264
        return 1
271
265
 
272
266
 
273
267
    # Set our search path to the schema of the cluster we care about.
274
268
    cur.execute(
275
 
            "SET search_path TO %s, public" % quote_identifier(cluster_schema))
 
269
            "SET search_path TO %s, public"
 
270
            % quote_identifier(CLUSTER_NAMESPACE))
276
271
 
277
272
    print node_overview_report(cur, options)
278
273
    print paths_report(cur, options)