This file is indexed.

/usr/lib/python2.7/dist-packages/xxdiff/scripts/sqlschemas.py is in xxdiff-scripts 1:4.0.1+dfsg-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
# This file is part of the xxdiff package.  See xxdiff for license and details.

"""xx-sql-schemas [<options>] <db1> <db2>

Where <dbX> is of the form:   [user@]<dbname>[/schema]

Script that dumps the schemas for two PostgreSQL databases, re-orders the
contents so that they diff nicely, and spawns xxdiff on the results.

Note: for now this script only supports the PostgreSQL database.  If you want to
add support for another database, just add an option and an appropriate
xxdiff.db.* module rather than writing a dedicated script.  (I'm very flexible
about adding new features to this script.)
"""

__author__ = "Martin Blais <blais@furius.ca>"
__depends__ = ['xxdiff', 'Python-2.4', 'PostgreSQL']


# stdlib imports.
from os.path import *
import logging, shutil

# xxdiff imports.
import xxdiff.scripts
import xxdiff.invoke
import xxdiff.mapcompare
from xxdiff.db import postgresql


def parse_options():
    """
    Parse the options.
    """
    import optparse
    parser = optparse.OptionParser(__doc__.strip())

    xxdiff.mapcompare.options_graft(parser)
    postgresql.options_graft(parser)
    xxdiff.invoke.options_graft(parser)

    parser.add_option('-t', '--text-only', action='store_true',
                      help="Render as text files to disk instead of graphical diff.")

    opts, args = parser.parse_args()

    xxdiff.mapcompare.options_validate(opts, parser)
    postgresql.options_validate(opts, parser)
    xxdiff.invoke.options_validate(opts, parser)
    
    if len(args) != 2:
        parser.error("You need to specify two databases/schemas to compare.")
    
    dbspec1, dbspec2 = args

    return (opts,
            postgresql.parse_dbspec(dbspec1, parser, opts),
            postgresql.parse_dbspec(dbspec2, parser, opts))

def sqlcompare_main():
    """
    Main program for schema comparison script.
    """
    opts, db1, db2 = parse_options()
    
    # Dump the database schemas.
    for db in db1, db2:
        dump = postgresql.dump_schema(db.user, db.dbname, db.schema, opts)

        # Parse the dumps, produce an adequate map of its contained objects.
        dump_entries = postgresql.parse_dump(dump)
        db.objmap = dict(((name, type), contents)
                         for name, type, contents in dump_entries)

    # List all objects that were found.
    for key in sorted(set(db1.objmap.keys() + db2.objmap.keys())):
        print key

    # Render comparable files.
    files = xxdiff.mapcompare.render_diffable_maps(opts, db1.objmap, db2.objmap)

    # Set displayed titles.
    if opts.text_only:
        for db, f in zip([db1, db2], files):
            targetfn = '%s.schema' % db.dbname
            logging.info("Writing out %s" % targetfn)
            shutil.copyfile(f.name, targetfn)
    else:
        titles = xxdiff.invoke.title_opts(
            *['%s (SCHEMA)' % db.dbspec for db in (db1, db2)])

        # Invoke xxdiff .
        xxargs = titles + [x.name for x in files]
        xxdiff.invoke.xxdiff_display(opts, *xxargs)


def main():
    xxdiff.scripts.interruptible_main(sqlcompare_main)

if __name__ == '__main__':
    main()