Ticket #3693: trac_3693-combined.patch

File trac_3693-combined.patch, 4.1 KB (added by mhansen, 12 years ago)
  • sage/server/wiki/moin.py

    # HG changeset patch
    # User Mike Hansen <mhansen@gmail.com>
    # Date 1228794672 28800
    # Node ID 8322f0f8f0b46eff0532de51c10f7acd487f6e7d
    # Parent  b837ad36b5d2dcb525e626656092c48064ec4a6f
    * * *
    #3693 -- first steps toward moinmoin upgrade.
    * * *
    [mq]: trac_3693-part2.patch
    * * *
    Updated code to use MoinMoin 1.7.2.
    
    diff -r b837ad36b5d2 -r 8322f0f8f0b4 sage/server/wiki/moin.py
    a b  
    1616from   sage.misc.viewer     import browser
    1717from   sage.server.misc import print_open_msg
    1818
     19MOINMOIN_VERSION="1.7.2"
     20
    1921# if you change the default sage_wiki, you must also change local/bin/sage-wiki
    2022def wiki_create_instance(directory='sage_wiki'):
    21     from MoinMoin.server.standalone import StandaloneConfig, run
    22 
    2323    share = '%s/share/moin'%misc.SAGE_LOCAL
    2424   
    2525    if os.path.exists(directory):
     
    3030    os.system('cp -r %s/data %s/'%(share,directory))
    3131    os.system('cp -r %s/underlay %s'%(share,directory))
    3232    os.system('cp %s/config/wikiconfig.py %s/'%(share,directory))
    33     os.system('cp %s/server/moin.py %s/'%(share,directory))
    34     R = open('%s/moin.py'%directory,'r').read()
    35     R = R.replace('/path/to/wikiconfig',directory)
    36     open('%s/moin.py'%directory,'w').write(R)
     33    os.system('cp %s/server/mointwisted.py %s/'%(share,directory))
     34
     35    #Write the version number to the directory
     36    v = open("%s/version-%s"%(directory, MOINMOIN_VERSION), "w")
     37    v.write(" ")
     38    v.close()
     39
     40def upgrade_157_to_172(directory, version):
     41    #Make a backup
     42    backupfile = '%s/backup-%s.tar %s'%(directory,version,directory)
     43    print "Making a backup of the wiki at %s"%backupfile
     44    os.system('tar -cf %s/*'%backupfile)
     45
     46    share = '%s/share/moin'%misc.SAGE_LOCAL
     47
     48    #Replace the underlay files with the new ones
     49    import shutil
     50    shutil.rmtree('%s/underlay'%directory)
     51    os.system('cp -r %s/underlay %s'%(share,directory))
     52    os.system('cp -r %s/data/plugin/* %s/data/plugin/'%(share,directory))
     53   
     54    #Add the new server file
     55    os.unlink('%s/moin.py'%directory)
     56    os.system('cp %s/server/mointwisted.py %s/'%(share,directory))
     57             
     58    #Add the new wikiconfig
     59    os.system('cp %s/config/wikiconfig.py %s/'%(share,directory))
     60
     61    #Run the data migration script and clean the cache
     62    cwd = os.getcwd()
     63    os.chdir(directory)
     64    os.system('moin migration data')
     65    os.system('moin maint cleancache')
     66    os.chdir(cwd)
     67   
     68    #Add the new version file
     69    v = open("%s/version-%s"%(directory, MOINMOIN_VERSION), "w")
     70    v.write(" ")
     71    v.close()
     72
     73
     74UPGRADE_FUNCTIONS = {('1.5.7', '1.7.2'): upgrade_157_to_172}
     75
     76def upgrade_if_necessary(directory):
     77    #If we're at the latest version, return
     78    if os.path.exists("%s/version-%s"%(directory, MOINMOIN_VERSION)):
     79        return
     80
     81    #Get the version of the wiki
     82    version = [v for v in os.listdir(directory) if 'version-' in v]
     83    if len(version) > 1:
     84        raise ValueError, "there should only be one version file in %s"%directory
     85
     86    if len(version) == 0:
     87        version = '1.5.7'
     88    else:
     89        version = version[0]
     90        version = version[version.find('-')+1:]
     91
     92    upgrade_function = UPGRADE_FUNCTIONS.get((version, MOINMOIN_VERSION), None)
     93    if upgrade_function is not None:
     94        print "Upgrading from version %s of MoinMoin to version %s"%(version, MOINMOIN_VERSION)
     95        upgrade_function(directory, version)
    3796
    3897def wiki(directory='sage_wiki',
    3998         port=9000,
     
    50109    """
    51110    if not os.path.exists(directory):
    52111        wiki_create_instance(directory)
     112
     113    upgrade_if_necessary(directory)
     114
    53115    os.chdir(directory)
    54    
     116
    55117    moin = '%s/share/moin/'%misc.SAGE_LOCAL
    56118    port = int(port)
    57 
    58119   
    59120    def run(port):
    60121        ## Create the config file
     
    62123        config.write("""
    63124import sys
    64125sys.path.insert(0, '%s')
    65 from MoinMoin.server.twistedmoin import TwistedConfig, makeApp
     126from MoinMoin.server.server_twisted import TwistedConfig, makeApp
    66127class Config(TwistedConfig):
    67128    name = 'mointwisted'
    68129    docs = '%s/local/share/moin/htdocs'