"Fossies" - the Fresh Open Source Software Archive

Member "PURELIB/trac/upgrades/db26.py" (27 Aug 2019, 2415 Bytes) of package /windows/misc/Trac-1.4.win32.exe:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "db26.py": 1.3.5_vs_1.3.6.

    1 # -*- coding: utf-8 -*-
    2 #
    3 # Copyright (C) 2010-2019 Edgewall Software
    4 # All rights reserved.
    5 #
    6 # This software is licensed as described in the file COPYING, which
    7 # you should have received as part of this distribution. The terms
    8 # are also available at https://trac.edgewall.org/wiki/TracLicense.
    9 #
   10 # This software consists of voluntary contributions made by many
   11 # individuals. For the exact contribution history, see the revision
   12 # history and logs, available at https://trac.edgewall.org/.
   13 
   14 import os
   15 
   16 from trac.util.text import exception_to_unicode, printerr
   17 
   18 
   19 def do_upgrade(env, ver, cursor):
   20     """
   21     1. Zero-pad Subversion revision numbers in the cache.
   22     2. Remove wiki-macros directory.
   23     """
   24     # Zero-pad Subversion revision numbers.
   25     cursor.execute("""
   26         SELECT id, value FROM repository WHERE name='repository_dir'
   27         """)
   28     for id in [id for id, dir in cursor if dir.startswith('svn:')]:
   29         cursor.execute("SELECT DISTINCT rev FROM revision WHERE repos=%s",
   30                        (id,))
   31         for rev in {row[0] for row in cursor}:
   32             cursor.execute("""
   33                 UPDATE revision SET rev=%s WHERE repos=%s AND rev=%s
   34                 """, ('%010d' % int(rev), id, rev))
   35 
   36         cursor.execute("SELECT DISTINCT rev FROM node_change WHERE repos=%s",
   37                        (id,))
   38         for rev in {row[0] for row in cursor}:
   39             cursor.execute("""
   40                 UPDATE node_change SET rev=%s WHERE repos=%s AND rev=%s
   41                 """, ('%010d' % int(rev), id, rev))
   42 
   43     # Remove wiki-macros if it is empty and warn if it isn't.
   44     wiki_macros = os.path.join(env.path, 'wiki-macros')
   45     try:
   46         entries = os.listdir(wiki_macros)
   47     except OSError:
   48         pass
   49     else:
   50         if entries:
   51             printerr("Warning: the wiki-macros directory in the environment "
   52                      "is non-empty, but Trac\ndoesn't load plugins from "
   53                      "there anymore. Please remove it by hand.")
   54         else:
   55             try:
   56                 os.rmdir(wiki_macros)
   57             except OSError as e:
   58                 printerr("Error while removing wiki-macros: %(err)s\nTrac "
   59                          "doesn't load plugins from wiki-macros anymore. "
   60                          "Please remove it by hand.",
   61                          err=exception_to_unicode(e))