| 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 | |
|---|
| | 41 | def 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 | |
|---|
| | 68 | UPGRADE_FUNCTIONS = {('1.5.7', '1.7.1'): upgrade_157_to_171} |
|---|
| | 69 | |
|---|
| | 70 | def 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) |
|---|