Ticket #3693: trac_3693-part2.patch

File trac_3693-part2.patch, 3.4 kB (added by mhansen, 6 months ago)
  • a/sage/server/wiki/moin.py

    old new  
    1717from   sage.misc.viewer     import browser 
    1818from   sage.server.misc import print_open_msg 
    1919 
     20MOINMOIN_VERSION="1.7.1" 
     21 
    2022# if you change the default sage_wiki, you must also change local/bin/sage-wiki 
    2123def wiki_create_instance(directory='sage_wiki'): 
    2224    share = '%s/share/moin'%misc.SAGE_LOCAL 
     
    2931    os.system('cp -r %s/data %s/'%(share,directory)) 
    3032    os.system('cp -r %s/underlay %s'%(share,directory)) 
    3133    os.system('cp %s/config/wikiconfig.py %s/'%(share,directory)) 
    32     os.system('cp %s/server/moin.py %s/'%(share,directory)) 
    33     R = open('%s/moin.py'%directory,'r').read() 
    34     R = R.replace('/path/to/wikiconfig',directory) 
    35     open('%s/moin.py'%directory,'w').write(R) 
     34    os.system('cp %s/server/mointwisted.py %s/'%(share,directory)) 
     35 
     36    #Write the version number to the directory 
     37    v = open("%s/version-%s"%(directory, MOINMOIN_VERSION), "w") 
     38    v.write(" ") 
     39    v.close() 
     40 
     41def upgrade_157_to_171(directory, version): 
     42    #Make a backup 
     43    backupfile = '%s/backup-%s.tar %s'%(directory,version,directory) 
     44    print "Making a backup of the wiki at %s"%backupfile  
     45    os.system('tar -cf %s/*'%backupfile) 
     46 
     47    share = '%s/share/moin'%misc.SAGE_LOCAL 
     48 
     49    #Replace the underlay files with the new ones 
     50    import shutil 
     51    shutil.rmtree('%s/underlay'%directory) 
     52    os.system('cp -r %s/underlay %s'%(share,directory)) 
     53    os.system('cp -r %s/data/plugin/* %s/data/plugin/'%(share,directory)) 
     54     
     55    #Add the new server file 
     56    os.unlink('%s/moin.py'%directory) 
     57    os.system('cp %s/server/mointwisted.py %s/'%(share,directory)) 
     58              
     59    #Add the new wikiconfig 
     60    os.system('cp %s/config/wikiconfig.py %s/'%(share,directory)) 
     61     
     62    #Add the new version file 
     63    v = open("%s/version-%s"%(directory, MOINMOIN_VERSION), "w") 
     64    v.write(" ") 
     65    v.close() 
     66         
     67 
     68UPGRADE_FUNCTIONS = {('1.5.7', '1.7.1'): upgrade_157_to_171} 
     69 
     70def upgrade_if_necessary(directory): 
     71    #If we're at the latest version, return 
     72    if os.path.exists("%s/version-%s"%(directory, MOINMOIN_VERSION)): 
     73        return 
     74 
     75    #Get the version of the wiki 
     76    version = [v for v in os.listdir(directory) if 'version-' in v] 
     77    if len(version) > 1: 
     78        raise ValueError, "there should only be one version file in %s"%directory 
     79 
     80    if len(version) == 0: 
     81        version = '1.5.7' 
     82    else: 
     83        version = version[0] 
     84        version = version[version.find('-')+1:] 
     85 
     86    upgrade_function = UPGRADE_FUNCTIONS.get((version, MOINMOIN_VERSION), None) 
     87    if upgrade_function is not None: 
     88        print "Upgrading from version %s of MoinMoin to version %s"%(version, MOINMOIN_VERSION) 
     89        upgrade_function(directory, version) 
    3690 
    3791def wiki(directory='sage_wiki', 
    3892         port=9000, 
     
    49103    """ 
    50104    if not os.path.exists(directory): 
    51105        wiki_create_instance(directory) 
     106 
     107    upgrade_if_necessary(directory) 
     108 
    52109    os.chdir(directory) 
    53      
     110 
    54111    moin = '%s/share/moin/'%misc.SAGE_LOCAL 
    55112    port = int(port) 
    56  
    57113     
    58114    def run(port): 
    59115        ## Create the config file