[Python-apps-commits] r7285 - in packages/trac/trunk/debian (13 files)

adejong at users.alioth.debian.org adejong at users.alioth.debian.org
Sat Jul 9 21:50:36 UTC 2011


    Date: Saturday, July 9, 2011 @ 21:50:34
  Author: adejong
Revision: 7285

  * Switch to 3.0 (quilt) source format.

Added:
  packages/trac/trunk/debian/patches/20_add_interpreter_line.patch
    (from rev 7283, packages/trac/trunk/debian/patches/20_add_interpreter_line.dpatch)
  packages/trac/trunk/debian/patches/30_default_charset_utf8.patch
    (from rev 7283, packages/trac/trunk/debian/patches/30_default_charset_utf8.dpatch)
  packages/trac/trunk/debian/patches/50_sqlitetopg_script.patch
    (from rev 7283, packages/trac/trunk/debian/patches/50_sqlitetopg_script.dpatch)
  packages/trac/trunk/debian/patches/series
    (from rev 7283, packages/trac/trunk/debian/patches/00list)
Modified:
  packages/trac/trunk/debian/changelog
  packages/trac/trunk/debian/control
  packages/trac/trunk/debian/rules
  packages/trac/trunk/debian/source/format
Deleted:
  packages/trac/trunk/debian/README.source
  packages/trac/trunk/debian/patches/00list
  packages/trac/trunk/debian/patches/20_add_interpreter_line.dpatch
  packages/trac/trunk/debian/patches/30_default_charset_utf8.dpatch
  packages/trac/trunk/debian/patches/50_sqlitetopg_script.dpatch

Deleted: packages/trac/trunk/debian/README.source
===================================================================
--- packages/trac/trunk/debian/README.source	2011-07-09 21:20:27 UTC (rev 7284)
+++ packages/trac/trunk/debian/README.source	2011-07-09 21:50:34 UTC (rev 7285)
@@ -1 +0,0 @@
-Please see /usr/share/doc/dpatch/README.source.gz for patch system information.

Modified: packages/trac/trunk/debian/changelog
===================================================================
--- packages/trac/trunk/debian/changelog	2011-07-09 21:20:27 UTC (rev 7284)
+++ packages/trac/trunk/debian/changelog	2011-07-09 21:50:34 UTC (rev 7285)
@@ -10,6 +10,7 @@
   * Drop 70_cache_control_typo.dpatch: fixed upstream
   * Drop 80_correct_plugin_names.dpatch: upstream changed mechanism which
     probably also fixes the original issue.
+  * Switch to 3.0 (quilt) source format.
 
  -- Arthur de Jong <adejong at debian.org>  Sat, 09 Jul 2011 12:08:04 +0200
 

Modified: packages/trac/trunk/debian/control
===================================================================
--- packages/trac/trunk/debian/control	2011-07-09 21:20:27 UTC (rev 7284)
+++ packages/trac/trunk/debian/control	2011-07-09 21:50:34 UTC (rev 7285)
@@ -2,7 +2,7 @@
 Section: web
 Priority: optional
 Build-Depends-Indep: python-setuptools (>= 0.5)
-Build-Depends: python-genshi (>= 0.5), python-central, python-all (>= 2.5.4), debhelper (>= 7), dpatch
+Build-Depends: python-genshi (>= 0.5), python-central, python-all (>= 2.5.4), debhelper (>= 7)
 Maintainer: Python Applications Packaging Team <python-apps-team at lists.alioth.debian.org>
 Uploaders: Otavio Salvador <otavio at debian.org>, W. Martin Borgert <debacle at debian.org>
 Standards-Version: 3.9.1

Deleted: packages/trac/trunk/debian/patches/00list
===================================================================
--- packages/trac/trunk/debian/patches/00list	2011-07-09 21:20:27 UTC (rev 7284)
+++ packages/trac/trunk/debian/patches/00list	2011-07-09 21:50:34 UTC (rev 7285)
@@ -1,3 +0,0 @@
-20_add_interpreter_line.dpatch
-30_default_charset_utf8.dpatch
-50_sqlitetopg_script.dpatch

Deleted: packages/trac/trunk/debian/patches/20_add_interpreter_line.dpatch
===================================================================
--- packages/trac/trunk/debian/patches/20_add_interpreter_line.dpatch	2011-07-09 21:20:27 UTC (rev 7284)
+++ packages/trac/trunk/debian/patches/20_add_interpreter_line.dpatch	2011-07-09 21:50:34 UTC (rev 7285)
@@ -1,16 +0,0 @@
-#! /bin/sh /usr/share/dpatch/dpatch-run
-## 20_add_interpreter_line.dpatch by <debacle at debian.org>
-##
-## All lines beginning with `## DP:' are a description of the patch.
-## DP: adds the Python interpreter shebang line to modpython_frontend.py
-
- at DPATCH@
-
-diff -ur a/trac/web/modpython_frontend.py b/trac/web/modpython_frontend.py
---- a/trac/web/modpython_frontend.py	2009-02-16 21:15:19.000000000 +0100
-+++ b/trac/web/modpython_frontend.py	2009-09-15 11:02:20.000000000 +0200
-@@ -1,3 +1,4 @@
-+#!/usr/bin/env python
- # -*- coding: utf-8 -*-
- #
- # Copyright (C) 2004-2009 Edgewall Software

Copied: packages/trac/trunk/debian/patches/20_add_interpreter_line.patch (from rev 7283, packages/trac/trunk/debian/patches/20_add_interpreter_line.dpatch)
===================================================================
--- packages/trac/trunk/debian/patches/20_add_interpreter_line.patch	                        (rev 0)
+++ packages/trac/trunk/debian/patches/20_add_interpreter_line.patch	2011-07-09 21:50:34 UTC (rev 7285)
@@ -0,0 +1,10 @@
+Author: <debacle at debian.org>
+Description: Adds the Python interpreter shebang line to modpython_frontend.py.
+
+--- a/trac/web/modpython_frontend.py
++++ b/trac/web/modpython_frontend.py
+@@ -1,3 +1,4 @@
++#!/usr/bin/env python
+ # -*- coding: utf-8 -*-
+ #
+ # Copyright (C) 2004-2009 Edgewall Software

Deleted: packages/trac/trunk/debian/patches/30_default_charset_utf8.dpatch
===================================================================
--- packages/trac/trunk/debian/patches/30_default_charset_utf8.dpatch	2011-07-09 21:20:27 UTC (rev 7284)
+++ packages/trac/trunk/debian/patches/30_default_charset_utf8.dpatch	2011-07-09 21:50:34 UTC (rev 7285)
@@ -1,20 +0,0 @@
-#! /bin/sh /usr/share/dpatch/dpatch-run
-## 30_default_charset_utf8.dpatch by  <debacle at debian.org>
-##
-## All lines beginning with `## DP:' are a description of the patch.
-## DP: Use UTF-8 as default charset
-
- at DPATCH@
-
-diff -uraN trac-0.11.5.orig/trac/mimeview/api.py trac-0.11.5/trac/mimeview/api.py
---- trac-0.11.5.orig/trac/mimeview/api.py	2009-06-30 21:18:58.000000000 +0200
-+++ trac-0.11.5/trac/mimeview/api.py	2009-09-28 22:02:35.000000000 +0200
-@@ -579,7 +579,7 @@
-     annotators = ExtensionPoint(IHTMLPreviewAnnotator)
-     converters = ExtensionPoint(IContentConverter)
- 
--    default_charset = Option('trac', 'default_charset', 'iso-8859-15',
-+    default_charset = Option('trac', 'default_charset', 'utf-8',
-         """Charset to be used when in doubt.""")
- 
-     tab_width = IntOption('mimeviewer', 'tab_width', 8,

Copied: packages/trac/trunk/debian/patches/30_default_charset_utf8.patch (from rev 7283, packages/trac/trunk/debian/patches/30_default_charset_utf8.dpatch)
===================================================================
--- packages/trac/trunk/debian/patches/30_default_charset_utf8.patch	                        (rev 0)
+++ packages/trac/trunk/debian/patches/30_default_charset_utf8.patch	2011-07-09 21:50:34 UTC (rev 7285)
@@ -0,0 +1,14 @@
+Author: <debacle at debian.org>
+Description: Use UTF-8 as default charset.
+
+--- a/trac/mimeview/api.py
++++ b/trac/mimeview/api.py
+@@ -609,7 +609,7 @@
+     annotators = ExtensionPoint(IHTMLPreviewAnnotator)
+     converters = ExtensionPoint(IContentConverter)
+ 
+-    default_charset = Option('trac', 'default_charset', 'iso-8859-15',
++    default_charset = Option('trac', 'default_charset', 'utf-8',
+         """Charset to be used when in doubt.""")
+ 
+     tab_width = IntOption('mimeviewer', 'tab_width', 8,

Deleted: packages/trac/trunk/debian/patches/50_sqlitetopg_script.dpatch
===================================================================
--- packages/trac/trunk/debian/patches/50_sqlitetopg_script.dpatch	2011-07-09 21:20:27 UTC (rev 7284)
+++ packages/trac/trunk/debian/patches/50_sqlitetopg_script.dpatch	2011-07-09 21:50:34 UTC (rev 7285)
@@ -1,348 +0,0 @@
-#! /bin/sh /usr/share/dpatch/dpatch-run
-## 50_sqlitetopostgresql_script.dpatch by  <debacle at debian.org>
-##
-## All lines beginning with `## DP:' are a description of the patch.
-## DP: add script to migrate from SQlite to PostgreSQL
-
- at DPATCH@
-
-diff -uraN trac-0.11.5.orig/contrib/sqlitetopgscript/sqlite2pg trac-0.11.5/contrib/sqlitetopgscript/sqlite2pg
---- trac-0.11.5.orig/contrib/sqlitetopgscript/sqlite2pg	1970-01-01 01:00:00.000000000 +0100
-+++ trac-0.11.5/contrib/sqlitetopgscript/sqlite2pg	2008-06-12 05:06:56.000000000 +0200
-@@ -0,0 +1,336 @@
-+#!/usr/bin/env python
-+
-+# -*- coding: utf-8 -*-
-+#
-+# Copyright (C) 2008 John Hampton <pacopablo at pacopablo.com>
-+# All rights reserved.
-+#
-+# This software is licensed as described in the file COPYING, which
-+# you should have received as part of this distribution. The terms
-+# are also available at http://trac.edgewall.com/license.html.
-+#
-+# This software consists of voluntary contributions made by many
-+# individuals. For the exact contribution history, see the revision
-+# history and logs, available at:
-+# http://trac-hacks.org/wiki/SqliteToPgScript
-+#
-+# Basically, it boils down to: feel free to use/modify/distribute/etc.
-+# However, give me credit where due.  Also, if you like the script and
-+# find it useful, buy me a soda or candy bar or something if ever we
-+# meet. Thanks and enjoy.
-+#
-+# Author: John Hampton <pacopablo at pacopablo.com>
-+
-+
-+import os, os.path, sys
-+from trac.env import Environment, EnvironmentSetup, IEnvironmentSetupParticipant
-+from trac.core import ComponentMeta
-+from trac.db import DatabaseManager
-+from optparse import OptionParser
-+from psycopg2 import ProgrammingError, IntegrityError
-+from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT
-+
-+VERSION='0.10'
-+
-+class TableMigration(object):
-+    """
-+        Class to conatin all table migration functions
-+    """
-+    def __init__(self, sqlenv, pgenv, opts):
-+        """ Create a TableMigration instance.  Required are SQLite and
-+            PostgreSQL environment objects
-+        """
-+        self.sqlenv = sqlenv
-+        self.pgenv = pgenv
-+        self.opts = opts
-+        self.sdb = self.sqlenv.get_db_cnx()
-+        self.pgdb = self.pgenv.get_db_cnx()
-+        self.pgdb_schema = self.pgdb.schema
-+        pass
-+
-+    def lookupMethod(self, table):
-+        """ Get a reference to the function that handles migration for the
-+            specified table
-+        """
-+        m = getattr(self, ''.join(['migrate_', table.upper()]), None)
-+        if not m:
-+            m = self.default_copy 
-+        return m
-+
-+    def cleanTable(self, table):
-+        """ Clear the contents of the table """
-+        cur = self.pgdb.cursor()
-+        delete_from = "DELETE FROM %s" % table
-+        cur.execute(delete_from)
-+
-+    def migrateTable(self, table):
-+        """ Migrate the table specified. """
-+        if not self.opts.noclean:
-+            self.cleanTable(table)
-+        m = getattr(self, ''.join(['migrate_', table.upper()]), None)
-+        if not m:
-+            rc = self.default_copy(table)
-+        else:
-+            rc = m()
-+        return rc
-+
-+    def default_copy(self, table):
-+        """ Copy the table from the sqlite db to the postgresql db """
-+        select_all = "SELECT * FROM %s" % table
-+        scur = self.sdb.cursor()
-+        pgcur = self.pgdb.cursor()
-+        scur.execute(select_all)
-+        cols = scur.description
-+        if not cols:
-+            return True
-+        subs = ["%s" for x in range(len(cols))]
-+        insert_into = ''.join([ "INSERT INTO ", table, " VALUES (",
-+                                ','.join(subs), ")"])
-+        rows = row_exists = 0
-+        for row in scur:
-+            rows += 1
-+            try:
-+                pgcur.execute(insert_into, row)
-+            except (ProgrammingError, IntegrityError):
-+                row_exists += 1
-+            continue
-+        if row_exists:
-+            print "%s of %s rows already existed in the %s table" % \
-+                  (str(row_exists), str(rows), table)
-+        self.pgdb.commit()
-+        return row_exists > 0
-+
-+    def migrate_TICKET(self):
-+        """ Migrate the ticket table and adjust the sequences properly """
-+        self.default_copy('ticket')
-+        select_maxticket = "SELECT max(id) FROM ticket"
-+        pgcur = self.pgdb.cursor()
-+        pgcur.execute(select_maxticket)
-+        r = pgcur.fetchone()
-+        if r:
-+            pgcur.execute("SELECT setval('ticket_id_seq', %s)", r)
-+        self.pgdb.commit()
-+        
-+    def migrate_REPORT(self):
-+        """ Migrate the report table and adjust the sequences properly """
-+        self.default_copy('report')
-+        select_maxreport = "SELECT max(id) FROM report"
-+        pgcur = self.pgdb.cursor()
-+        pgcur.execute(select_maxreport)
-+        r = pgcur.fetchone()
-+        if r:
-+            pgcur.execute("SELECT setval('report_id_seq', %s)", r)
-+        self.pgdb.commit()
-+    
-+    def migrate_PERMISSION(self):
-+        """
-+            Migrate permission table
-+        """
-+        scur = self.sdb.cursor()
-+        pgcur = self.pgdb.cursor()
-+        rows = row_exists = 0
-+        if not self.opts.plist:
-+            sql_select = "SELECT * FROM permission"
-+        else:
-+            subs = []
-+            for x in range(len(self.opts.plist)):
-+                subs.append("%s")
-+                continue
-+            sql_select = ''.join([  "SELECT * FROM permission ",
-+                                    "WHERE username NOT IN (",
-+                                    ','.join(subs),
-+                                    ")",
-+                                 ])
-+        
-+        scur.execute(sql_select, self.opts.plist)
-+        sql_insert = "INSERT INTO permission VALUES (%s, %s)"
-+        for row in scur:
-+            rows += 1
-+            try:
-+                pgcur.execute(sql_insert, row)
-+            except (ProgrammingError, IntegrityError):
-+                row_exists += 1
-+            continue
-+        if row_exists:
-+            print "%s of %s rows already existed in the permission table" % (str(row_exists), str(rows))
-+        self.pgdb.commit()
-+        return row_exists > 0
-+
-+    def migrate_WIKI(self):
-+        """
-+            Migrate wiki table
-+        """
-+        scur = self.sdb.cursor()
-+        pgcur = self.pgdb.cursor()
-+        rows = row_exists = 0
-+        if not self.opts.wlist:
-+            sql_select = "SELECT * FROM wiki"
-+        else:
-+            subs = []
-+            for x in range(len(self.opts.wlist)):
-+                subs.append("%s")
-+                continue
-+            sql_select = ''.join([  "SELECT * FROM wiki ",
-+                                    "WHERE name NOT IN (",
-+                                    ','.join(subs),
-+                                    ")",
-+                                 ])
-+        
-+        scur.execute(sql_select, self.opts.wlist)
-+        sql_insert = "INSERT INTO wiki VALUES (%s, %s, %s, %s, %s, %s, %s, %s)"
-+        for row in scur:
-+            rows += 1
-+            try:
-+                pgcur.execute(sql_insert, row)
-+            except (ProgrammingError, IntegrityError):
-+                row_exists += 1
-+            continue
-+        if row_exists:
-+            print "%s of %s rows already existed in the wiki table" % (str(row_exists), str(rows))
-+        self.pgdb.commit()
-+        return row_exists > 0
-+
-+
-+def getSQLiteEnvironment(opts): 
-+    """ Create an Environment connected to the SQLite database """
-+
-+    dburi = opts.sqlite_uri
-+    env = Environment(opts.tracenv)
-+    env.config.set('trac', 'database', dburi)
-+    return env
-+
-+def getPostgreSQLEnvironment(opts):
-+    """ Create an Environment connected to the PostgreSQL database """
-+
-+    dburi = opts.pg_uri
-+    env = Environment(opts.tracenv)
-+    env.config.set('trac', 'database', dburi)
-+    try:
-+        cnx = env.get_db_cnx()
-+        cur = cnx.cursor()
-+        cur.execute("select value from system where name = 'database_version'");
-+    except ProgrammingError:
-+        cnx.rollback()
-+        DatabaseManager(env).init_db()
-+        DatabaseManager(env).shutdown()
-+        for x in filter(None, [env.compmgr[cls] for cls in 
-+                        ComponentMeta._registry.get(
-+                        IEnvironmentSetupParticipant, [])]):
-+            if isinstance(x, EnvironmentSetup):
-+                x.environment_created()        
-+    if env.needs_upgrade():
-+        env.upgrade()
-+    return env
-+
-+def getAllTables(env):
-+    """ Queries the PostgreSQL database for a list of tables """
-+    cnx = env.get_db_cnx()
-+    schema = cnx.schema or u'public'
-+    cur = cnx.cursor()
-+    select_tables = """SELECT tablename 
-+                         FROM pg_catalog.pg_tables 
-+                        WHERE schemaname = %s"""
-+    cur.execute(select_tables, (schema,))
-+    cnx.commit()
-+    return [table[0] for table in cur]
-+
-+def Main(opts):
-+    """
-+        Migrate data from SQLite to PostgreSQL
-+    """
-+    rc = 0
-+
-+    sqlenv = getSQLiteEnvironment(opts)
-+    pgenv = getPostgreSQLEnvironment(opts)
-+    tmigration = TableMigration(sqlenv, pgenv, opts)
-+    if not opts.tlist:
-+        opts.tlist = getAllTables(pgenv)
-+    for tname in opts.tlist:
-+        try:
-+            rc = tmigration.migrateTable(tname) or rc
-+        except AttributeError:
-+            print "Migration of %s has not been implemented" % tname
-+            pass
-+        continue
-+   
-+    return rc
-+
-+def doArgs(argv):
-+    """ Look if you can't guess what this function does, just give up now. """
-+    global VERSION
-+   
-+    version = "%%prog %s" % VERSION
-+    usage ="usage: %prog [options] [site]"
-+    description="%prog is used to migrate data from SQLite to PostgreSQL."
-+   
-+    parser = OptionParser(usage=usage, version=version, description=description)
-+   
-+    parser.add_option("-t", "--tracbase", dest="tracbase", type="string",
-+                        help="Parent path for trac sites",
-+                        metavar="<path>")
-+    parser.add_option("-e", "--tracenv", dest="tracenv", type="string",
-+                        help="Path to trac environment",
-+                        metavar="<path>")
-+    parser.add_option("-m", "--migrate", dest="migrate", type="string",
-+                        help="Comma separated list of tables to migrate",
-+                        metavar="<list>", default=None)
-+    parser.add_option("", "--exclude_perms", dest="perms_exclude", 
-+                        type="string", help="Comma separated list of users to "
-+                        "exclude from permission migration", metavar="<list>")
-+    parser.add_option("-w", "--wikipages", dest="wikipages", type="string",
-+                        help="Comma separated list of wiki page names to "
-+                        "ommit from the migration", metavar="<list>")
-+    parser.add_option("-p", "--pg_uri", dest="pg_uri", type="string",
-+                        help="DB URI for PostgreSQL database",
-+                        metavar="<uri>")
-+    parser.add_option("-s", "--sqlite_uri", dest="sqlite_uri", type="string",
-+                        help="DB URI for SQLite database",
-+                        metavar="<uri>", default="sqlite:db/trac.db")
-+    parser.add_option("", "--noclean", dest="noclean", action="store_true",
-+                        help="Do not clear PostgreSQL tables before transfer",
-+                        default=False)
-+   
-+    (options, args) = parser.parse_args(argv)
-+    if not options.tracenv:
-+        if  not options.tracbase:
-+            print ("You must specify the --tracenv or the --tracbase option")
-+            sys.exit(1)
-+        else:
-+            if len(args) < 1:
-+                print ("You must specify a project name\n")
-+                sys.exit(1)
-+            options.project = args[0]
-+            options.tracenv = os.path.join(options.tracbase, args[0])
-+
-+    if not options.pg_uri or not options.pg_uri.startswith('postgres://'):
-+        print ("You must specify a valid URI for the PostgreSQL database.")
-+        print ("  eg. postgres://user:password@localhost/dbname")
-+        sys.exit(1)
-+ 
-+    if not options.sqlite_uri or not options.sqlite_uri.startswith('sqlite:'):
-+        print ("You must specify a valid URI for the SQLite database.")
-+        print ("  eg. sqlite:db/trac.db")
-+        sys.exit(1)
-+
-+
-+    options.args = args
-+    options.tlist = options.migrate and \
-+                    [t.strip() for t in options.migrate.strip().split(',')]
-+    options.wlist = options.wikipages and \
-+                    [w.strip() for w in options.wikipages.strip().split(',')] \
-+                    or []
-+    options.plist = options.perms_exclude and \
-+                    [p.strip() for p in options.perms_exclude.strip().split(',')] \
-+                    or []
-+
-+    return options
-+
-+
-+def main(argv):
-+    opts = doArgs(argv)
-+    Main(opts)
-+    return 0
-+
-+if __name__ == '__main__':
-+    sys.exit(main(sys.argv[1:]))
-+    

Copied: packages/trac/trunk/debian/patches/50_sqlitetopg_script.patch (from rev 7283, packages/trac/trunk/debian/patches/50_sqlitetopg_script.dpatch)
===================================================================
--- packages/trac/trunk/debian/patches/50_sqlitetopg_script.patch	                        (rev 0)
+++ packages/trac/trunk/debian/patches/50_sqlitetopg_script.patch	2011-07-09 21:50:34 UTC (rev 7285)
@@ -0,0 +1,342 @@
+Author: <debacle at debian.org>
+Description: Add script to migrate from SQlite to PostgreSQL.
+
+--- /dev/null
++++ b/contrib/sqlitetopgscript/sqlite2pg
+@@ -0,0 +1,336 @@
++#!/usr/bin/env python
++
++# -*- coding: utf-8 -*-
++#
++# Copyright (C) 2008 John Hampton <pacopablo at pacopablo.com>
++# All rights reserved.
++#
++# This software is licensed as described in the file COPYING, which
++# you should have received as part of this distribution. The terms
++# are also available at http://trac.edgewall.com/license.html.
++#
++# This software consists of voluntary contributions made by many
++# individuals. For the exact contribution history, see the revision
++# history and logs, available at:
++# http://trac-hacks.org/wiki/SqliteToPgScript
++#
++# Basically, it boils down to: feel free to use/modify/distribute/etc.
++# However, give me credit where due.  Also, if you like the script and
++# find it useful, buy me a soda or candy bar or something if ever we
++# meet. Thanks and enjoy.
++#
++# Author: John Hampton <pacopablo at pacopablo.com>
++
++
++import os, os.path, sys
++from trac.env import Environment, EnvironmentSetup, IEnvironmentSetupParticipant
++from trac.core import ComponentMeta
++from trac.db import DatabaseManager
++from optparse import OptionParser
++from psycopg2 import ProgrammingError, IntegrityError
++from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT
++
++VERSION='0.10'
++
++class TableMigration(object):
++    """
++        Class to conatin all table migration functions
++    """
++    def __init__(self, sqlenv, pgenv, opts):
++        """ Create a TableMigration instance.  Required are SQLite and
++            PostgreSQL environment objects
++        """
++        self.sqlenv = sqlenv
++        self.pgenv = pgenv
++        self.opts = opts
++        self.sdb = self.sqlenv.get_db_cnx()
++        self.pgdb = self.pgenv.get_db_cnx()
++        self.pgdb_schema = self.pgdb.schema
++        pass
++
++    def lookupMethod(self, table):
++        """ Get a reference to the function that handles migration for the
++            specified table
++        """
++        m = getattr(self, ''.join(['migrate_', table.upper()]), None)
++        if not m:
++            m = self.default_copy
++        return m
++
++    def cleanTable(self, table):
++        """ Clear the contents of the table """
++        cur = self.pgdb.cursor()
++        delete_from = "DELETE FROM %s" % table
++        cur.execute(delete_from)
++
++    def migrateTable(self, table):
++        """ Migrate the table specified. """
++        if not self.opts.noclean:
++            self.cleanTable(table)
++        m = getattr(self, ''.join(['migrate_', table.upper()]), None)
++        if not m:
++            rc = self.default_copy(table)
++        else:
++            rc = m()
++        return rc
++
++    def default_copy(self, table):
++        """ Copy the table from the sqlite db to the postgresql db """
++        select_all = "SELECT * FROM %s" % table
++        scur = self.sdb.cursor()
++        pgcur = self.pgdb.cursor()
++        scur.execute(select_all)
++        cols = scur.description
++        if not cols:
++            return True
++        subs = ["%s" for x in range(len(cols))]
++        insert_into = ''.join([ "INSERT INTO ", table, " VALUES (",
++                                ','.join(subs), ")"])
++        rows = row_exists = 0
++        for row in scur:
++            rows += 1
++            try:
++                pgcur.execute(insert_into, row)
++            except (ProgrammingError, IntegrityError):
++                row_exists += 1
++            continue
++        if row_exists:
++            print "%s of %s rows already existed in the %s table" % \
++                  (str(row_exists), str(rows), table)
++        self.pgdb.commit()
++        return row_exists > 0
++
++    def migrate_TICKET(self):
++        """ Migrate the ticket table and adjust the sequences properly """
++        self.default_copy('ticket')
++        select_maxticket = "SELECT max(id) FROM ticket"
++        pgcur = self.pgdb.cursor()
++        pgcur.execute(select_maxticket)
++        r = pgcur.fetchone()
++        if r:
++            pgcur.execute("SELECT setval('ticket_id_seq', %s)", r)
++        self.pgdb.commit()
++
++    def migrate_REPORT(self):
++        """ Migrate the report table and adjust the sequences properly """
++        self.default_copy('report')
++        select_maxreport = "SELECT max(id) FROM report"
++        pgcur = self.pgdb.cursor()
++        pgcur.execute(select_maxreport)
++        r = pgcur.fetchone()
++        if r:
++            pgcur.execute("SELECT setval('report_id_seq', %s)", r)
++        self.pgdb.commit()
++
++    def migrate_PERMISSION(self):
++        """
++            Migrate permission table
++        """
++        scur = self.sdb.cursor()
++        pgcur = self.pgdb.cursor()
++        rows = row_exists = 0
++        if not self.opts.plist:
++            sql_select = "SELECT * FROM permission"
++        else:
++            subs = []
++            for x in range(len(self.opts.plist)):
++                subs.append("%s")
++                continue
++            sql_select = ''.join([  "SELECT * FROM permission ",
++                                    "WHERE username NOT IN (",
++                                    ','.join(subs),
++                                    ")",
++                                 ])
++
++        scur.execute(sql_select, self.opts.plist)
++        sql_insert = "INSERT INTO permission VALUES (%s, %s)"
++        for row in scur:
++            rows += 1
++            try:
++                pgcur.execute(sql_insert, row)
++            except (ProgrammingError, IntegrityError):
++                row_exists += 1
++            continue
++        if row_exists:
++            print "%s of %s rows already existed in the permission table" % (str(row_exists), str(rows))
++        self.pgdb.commit()
++        return row_exists > 0
++
++    def migrate_WIKI(self):
++        """
++            Migrate wiki table
++        """
++        scur = self.sdb.cursor()
++        pgcur = self.pgdb.cursor()
++        rows = row_exists = 0
++        if not self.opts.wlist:
++            sql_select = "SELECT * FROM wiki"
++        else:
++            subs = []
++            for x in range(len(self.opts.wlist)):
++                subs.append("%s")
++                continue
++            sql_select = ''.join([  "SELECT * FROM wiki ",
++                                    "WHERE name NOT IN (",
++                                    ','.join(subs),
++                                    ")",
++                                 ])
++
++        scur.execute(sql_select, self.opts.wlist)
++        sql_insert = "INSERT INTO wiki VALUES (%s, %s, %s, %s, %s, %s, %s, %s)"
++        for row in scur:
++            rows += 1
++            try:
++                pgcur.execute(sql_insert, row)
++            except (ProgrammingError, IntegrityError):
++                row_exists += 1
++            continue
++        if row_exists:
++            print "%s of %s rows already existed in the wiki table" % (str(row_exists), str(rows))
++        self.pgdb.commit()
++        return row_exists > 0
++
++
++def getSQLiteEnvironment(opts):
++    """ Create an Environment connected to the SQLite database """
++
++    dburi = opts.sqlite_uri
++    env = Environment(opts.tracenv)
++    env.config.set('trac', 'database', dburi)
++    return env
++
++def getPostgreSQLEnvironment(opts):
++    """ Create an Environment connected to the PostgreSQL database """
++
++    dburi = opts.pg_uri
++    env = Environment(opts.tracenv)
++    env.config.set('trac', 'database', dburi)
++    try:
++        cnx = env.get_db_cnx()
++        cur = cnx.cursor()
++        cur.execute("select value from system where name = 'database_version'");
++    except ProgrammingError:
++        cnx.rollback()
++        DatabaseManager(env).init_db()
++        DatabaseManager(env).shutdown()
++        for x in filter(None, [env.compmgr[cls] for cls in
++                        ComponentMeta._registry.get(
++                        IEnvironmentSetupParticipant, [])]):
++            if isinstance(x, EnvironmentSetup):
++                x.environment_created()
++    if env.needs_upgrade():
++        env.upgrade()
++    return env
++
++def getAllTables(env):
++    """ Queries the PostgreSQL database for a list of tables """
++    cnx = env.get_db_cnx()
++    schema = cnx.schema or u'public'
++    cur = cnx.cursor()
++    select_tables = """SELECT tablename
++                         FROM pg_catalog.pg_tables
++                        WHERE schemaname = %s"""
++    cur.execute(select_tables, (schema,))
++    cnx.commit()
++    return [table[0] for table in cur]
++
++def Main(opts):
++    """
++        Migrate data from SQLite to PostgreSQL
++    """
++    rc = 0
++
++    sqlenv = getSQLiteEnvironment(opts)
++    pgenv = getPostgreSQLEnvironment(opts)
++    tmigration = TableMigration(sqlenv, pgenv, opts)
++    if not opts.tlist:
++        opts.tlist = getAllTables(pgenv)
++    for tname in opts.tlist:
++        try:
++            rc = tmigration.migrateTable(tname) or rc
++        except AttributeError:
++            print "Migration of %s has not been implemented" % tname
++            pass
++        continue
++
++    return rc
++
++def doArgs(argv):
++    """ Look if you can't guess what this function does, just give up now. """
++    global VERSION
++
++    version = "%%prog %s" % VERSION
++    usage ="usage: %prog [options] [site]"
++    description="%prog is used to migrate data from SQLite to PostgreSQL."
++
++    parser = OptionParser(usage=usage, version=version, description=description)
++
++    parser.add_option("-t", "--tracbase", dest="tracbase", type="string",
++                        help="Parent path for trac sites",
++                        metavar="<path>")
++    parser.add_option("-e", "--tracenv", dest="tracenv", type="string",
++                        help="Path to trac environment",
++                        metavar="<path>")
++    parser.add_option("-m", "--migrate", dest="migrate", type="string",
++                        help="Comma separated list of tables to migrate",
++                        metavar="<list>", default=None)
++    parser.add_option("", "--exclude_perms", dest="perms_exclude",
++                        type="string", help="Comma separated list of users to "
++                        "exclude from permission migration", metavar="<list>")
++    parser.add_option("-w", "--wikipages", dest="wikipages", type="string",
++                        help="Comma separated list of wiki page names to "
++                        "ommit from the migration", metavar="<list>")
++    parser.add_option("-p", "--pg_uri", dest="pg_uri", type="string",
++                        help="DB URI for PostgreSQL database",
++                        metavar="<uri>")
++    parser.add_option("-s", "--sqlite_uri", dest="sqlite_uri", type="string",
++                        help="DB URI for SQLite database",
++                        metavar="<uri>", default="sqlite:db/trac.db")
++    parser.add_option("", "--noclean", dest="noclean", action="store_true",
++                        help="Do not clear PostgreSQL tables before transfer",
++                        default=False)
++
++    (options, args) = parser.parse_args(argv)
++    if not options.tracenv:
++        if  not options.tracbase:
++            print ("You must specify the --tracenv or the --tracbase option")
++            sys.exit(1)
++        else:
++            if len(args) < 1:
++                print ("You must specify a project name\n")
++                sys.exit(1)
++            options.project = args[0]
++            options.tracenv = os.path.join(options.tracbase, args[0])
++
++    if not options.pg_uri or not options.pg_uri.startswith('postgres://'):
++        print ("You must specify a valid URI for the PostgreSQL database.")
++        print ("  eg. postgres://user:password@localhost/dbname")
++        sys.exit(1)
++
++    if not options.sqlite_uri or not options.sqlite_uri.startswith('sqlite:'):
++        print ("You must specify a valid URI for the SQLite database.")
++        print ("  eg. sqlite:db/trac.db")
++        sys.exit(1)
++
++
++    options.args = args
++    options.tlist = options.migrate and \
++                    [t.strip() for t in options.migrate.strip().split(',')]
++    options.wlist = options.wikipages and \
++                    [w.strip() for w in options.wikipages.strip().split(',')] \
++                    or []
++    options.plist = options.perms_exclude and \
++                    [p.strip() for p in options.perms_exclude.strip().split(',')] \
++                    or []
++
++    return options
++
++
++def main(argv):
++    opts = doArgs(argv)
++    Main(opts)
++    return 0
++
++if __name__ == '__main__':
++    sys.exit(main(sys.argv[1:]))
++

Copied: packages/trac/trunk/debian/patches/series (from rev 7283, packages/trac/trunk/debian/patches/00list)
===================================================================
--- packages/trac/trunk/debian/patches/series	                        (rev 0)
+++ packages/trac/trunk/debian/patches/series	2011-07-09 21:50:34 UTC (rev 7285)
@@ -0,0 +1,3 @@
+20_add_interpreter_line.patch
+30_default_charset_utf8.patch
+50_sqlitetopg_script.patch

Modified: packages/trac/trunk/debian/rules
===================================================================
--- packages/trac/trunk/debian/rules	2011-07-09 21:20:27 UTC (rev 7284)
+++ packages/trac/trunk/debian/rules	2011-07-09 21:50:34 UTC (rev 7285)
@@ -1,10 +1,9 @@
 #!/usr/bin/make -f
 
 PYVER=$(shell python -c 'import sys; print sys.version[:3]')
-include /usr/share/dpatch/dpatch.make
 include /usr/share/python/python.mk
 
-clean: unpatch 
+clean:
 	dh_testdir
 	dh_testroot
 	rm -f build-stamp
@@ -12,7 +11,7 @@
 	-find . -name *\.py[co] -exec rm {} \;
 	dh_clean
 
-build: patch build-stamp
+build: build-stamp
 
 build-stamp:
 	dh_testdir
@@ -35,7 +34,7 @@
 	dh_testdir
 	dh_testroot
 	dh_installchangelogs
-	dh_installdocs debian/README.source
+	dh_installdocs
 	dh_install -Xtrac-post-commit-hook.cmd
 	dh_installman
 	dh_link

Modified: packages/trac/trunk/debian/source/format
===================================================================
--- packages/trac/trunk/debian/source/format	2011-07-09 21:20:27 UTC (rev 7284)
+++ packages/trac/trunk/debian/source/format	2011-07-09 21:50:34 UTC (rev 7285)
@@ -1 +1 @@
-1.0
+3.0 (quilt)




More information about the Python-apps-commits mailing list