r48150 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r48149‎ | r48150 | r48151 >
Date:23:31, 7 March 2009
Author:kim
Status:deferred
Tags:
Comment:
Code refactored using a refactoring editor.
All mention of "revision" has been replaced with "instance",
since we'll be using the word "revision" to refer to
svn revision numbers.

Since we're refactoring anyway, Also added settings_handler.py,
which provides default settings, and provides backwards compatibility
with old settings files. Then refactored all code to use that instead
of plain settings.py This will hopefully prevent some of the cases where
update_self could cause the program to crash.
Modified paths:
  • /trunk/wikiation/installer/download_installer.py (modified) (history)
  • /trunk/wikiation/installer/extension_installer.py (modified) (history)
  • /trunk/wikiation/installer/installation_system.py (modified) (history)
  • /trunk/wikiation/installer/installer.py (modified) (history)
  • /trunk/wikiation/installer/installers.py (modified) (history)
  • /trunk/wikiation/installer/isolation.py (modified) (history)
  • /trunk/wikiation/installer/mediawiki_installer.py (modified) (history)
  • /trunk/wikiation/installer/naive_installer.py (modified) (history)
  • /trunk/wikiation/installer/settings_handler.py (added) (history)
  • /trunk/wikiation/installer/toolkit_installer.py (modified) (history)
  • /trunk/wikiation/installer/util/allnaive.py (modified) (history)

Diff [purge]

Index: trunk/wikiation/installer/extension_installer.py
@@ -3,7 +3,7 @@
44 #
55 # Distributed under the terms of the MIT license.
66
7 -import settings
 7+import settings_handler as settings
88 import os, os.path, shutil
99 import subprocess
1010
@@ -15,14 +15,11 @@
1616 class Extension_Installer(Installation_System):
1717 system_name='extensions'
1818 destination_dir=None
19 -
20 -# def __init__(self, revision):
21 -# Installation_System.__init__(self, revision)
22 -
23 - def set_revision(self,revision):
24 - self.destination_dir=os.path.join(settings.revisionsdir,revision,"extensions")
25 - self.revision=revision
2619
 20+ def set_instance(self,instance):
 21+ self.destination_dir=os.path.join(settings.instancesdir,instance,"extensions")
 22+ self.instance=instance
 23+
2724
2825 def install_settings(self, installer_name):
2926 installdir=self.installdir_name(installer_name)
@@ -47,8 +44,8 @@
4845
4946
5047 def is_installed(self, installer_name):
51 - if self.revision==None:
52 - raise Extension_Installer_Exception("no revision specified ... did you try doing ... in <Revision> ?")
 48+ if self.instance==None:
 49+ raise Extension_Installer_Exception("no instance specified ... did you try doing ... in <instance> ?")
5350 return Installation_System.is_installed(self, installer_name)
5451
5552 def exec_task(self,installer_name,task,env=None):
Index: trunk/wikiation/installer/installer.py
@@ -9,7 +9,7 @@
1010 import readline
1111 import re
1212 import shutil
13 -import settings
 13+import settings_handler as settings
1414
1515 import installers
1616
Index: trunk/wikiation/installer/settings_handler.py
@@ -0,0 +1,57 @@
 2+# This software, copyright (C) 2008-2009 by Wikiation.
 3+# This software is developed by Kim Bruning.
 4+#
 5+# Distributed under the terms of the MIT license.
 6+# ======================================
 7+#Default settings file. DO NOT EDIT (edit settings.py instead)
 8+# =======================================
 9+
 10+import os
 11+
 12+# "You Are Here"
 13+installerdir=os.path.dirname(os.path.abspath(__file__))
 14+
 15+# where to find .install directories and the files contained therein
 16+installfiles=os.path.join(installerdir,'installfiles')
 17+
 18+
 19+# where to find mediawiki tags and trunk on svn
 20+tagsdir="http://svn.wikimedia.org/svnroot/mediawiki/tags"
 21+trunkdir="http://svn.wikimedia.org/svnroot/mediawiki/trunk"
 22+# we could alternately/additionally take a tag version for extensions. (future)
 23+extensionsdir=trunkdir+"/extensions"
 24+
 25+# where to install diverse revisions
 26+instancesdir='/var/www/revisions'
 27+
 28+
 29+# base scriptpath for every installation (ie, where to reach the above over the web)
 30+base_scriptpath="/revisions/"
 31+
 32+# where to install the toolkit
 33+toolkit_dir='/usr/local/wikiation'
 34+
 35+
 36+#where wikiation_check_isolation can be found
 37+isolation_create=toolkit_dir+'/wikiation_check_isolation/create_and_ul.sh'
 38+isolation_test=toolkit_dir+'/wikiation_check_isolation/dl_and_check.sh'
 39+
 40+# what mysql command should be used. (Who us? Use horrible hacks?)
 41+
 42+mysql_command="mysql -uwiki -pwiki1234"
 43+
 44+# run automated tests during installation
 45+# this is useful if you are in a testing environment.
 46+# If you are running production, you might want to leave
 47+# this set to False.
 48+run_automated_tests=False
 49+
 50+
 51+
 52+if os.path.exists(os.path.join(installerdir, 'settings.py')):
 53+ from settings import *
 54+
 55+#legacy support (rename old variables, etc)
 56+if 'revisionsdir' in globals():
 57+ instancesdir=revisionsdir
 58+
Index: trunk/wikiation/installer/isolation.py
@@ -4,7 +4,7 @@
55 # Distributed under the terms of the MIT license.
66
77 import sys,os, os.path
8 -import settings
 8+import settings_handler as settings
99
1010 #support for wikiation_check_isolation
1111
Index: trunk/wikiation/installer/toolkit_installer.py
@@ -1,13 +1,12 @@
2 -import settings
 2+import settings_handler as settings
33 import os, os.path, shutil
44 import subprocess
55
66 from installation_system import Installation_System
77
8 -
98 class Toolkit_Installer(Installation_System):
109 system_name='wikiation_toolkit'
1110 destination_dir=settings.toolkit_dir
12 -# def __init__(self,revision):
 11+# def __init__(self,instance):
1312 # Installation_System.__init__(self)
14 -
 13+
Index: trunk/wikiation/installer/installation_system.py
@@ -3,7 +3,7 @@
44 #
55 # Distributed under the terms of the MIT license.
66
7 -import settings
 7+import settings_handler as settings
88 import os, os.path, shutil
99 import subprocess
1010
@@ -14,18 +14,19 @@
1515 class Installation_System:
1616 system_name=None
1717 destination_dir=None
18 - revision=None
1918 as_alias=None
2019
21 - def __init__(self,revision=None):
 20+ def __init__(self,instance=None):
2221 self.subsystemdir=os.path.join(settings.installfiles, self.system_name)
 22+ self.destination_dir=None
 23+ self.instance=None
 24+ self.as_alias=None
 25+ if instance:
 26+ self.set_instance(instance)
2327
24 - if revision:
25 - self.set_revision(revision)
 28+ def set_instance(self,instance):
 29+ self.instance=instance
2630
27 - def set_revision(self,revision):
28 - self.revision=revision
29 -
3031 def get_installers(self):
3132 installers=os.listdir(self.subsystemdir)
3233 installers2=[]
@@ -49,7 +50,7 @@
5051 * if more than one match exists, one match is picked
5152 Exactly Which match is picked is not defined
5253 (so Don't Do That)
53 - * destination_dir is passed as a parameter
 54+ * destination_dir is passed as a parameter
5455 returns
5556 * stdout returned by task command if successful
5657 * None if task not available
Index: trunk/wikiation/installer/naive_installer.py
@@ -3,7 +3,7 @@
44 #
55 # Distributed under the terms of the MIT license.
66
7 -import settings
 7+import settings_handler as settings
88 import os, os.path, shutil
99 import subprocess
1010
Index: trunk/wikiation/installer/installers.py
@@ -3,7 +3,7 @@
44 #
55 # Distributed under the terms of the MIT license.
66
7 -import settings
 7+import settings_handler as settings
88 import os, os.path, shutil
99 import subprocess
1010 import installer_util
@@ -72,7 +72,7 @@
7373 return
7474
7575 if ppath["in_installer"]:
76 - system.set_revision(ppath["in_installer"])
 76+ system.set_instance(ppath["in_installer"])
7777 installed=None
7878 try:
7979 installed=system.get_installed()
@@ -117,7 +117,7 @@
118118
119119 system=get_system(ppath["system"])
120120 if ppath["in_installer"]:
121 - system.set_revision(ppath["in_installer"])
 121+ system.set_instance(ppath["in_installer"])
122122 if ppath["as_alias"]:
123123 system.as_alias=ppath["as_alias"]
124124
@@ -150,7 +150,7 @@
151151
152152 system=get_system(ppath["system"])
153153 if ppath["in_installer"]:
154 - system.set_revision(ppath["in_installer"])
 154+ system.set_instance(ppath["in_installer"])
155155 if ppath["as_alias"]:
156156 system.as_alias=ppath["as_alias"]
157157 try:
@@ -261,7 +261,7 @@
262262 # mysystem=get_system(system)
263263 #
264264 # if in_installer:
265 - # system.set_revision(ppath["in_installer"])
 265+ # system.set_instance(ppath["in_installer"])
266266 #
267267 # if system.is_installed(installer)
268268
Index: trunk/wikiation/installer/mediawiki_installer.py
@@ -2,7 +2,7 @@
33 #
44 # Distributed under the terms of the MIT license.
55
6 -import settings
 6+import settings_handler as settings
77 import os, os.path, shutil
88 import subprocess
99
@@ -27,9 +27,9 @@
2828 """installer for mediawiki revisions"""
2929 system_name='mediawiki_installer'
3030 # TODO: destination_dir isn't quite changable until we have finished refactoring everything (not today)
31 - destination_dir=settings.revisionsdir
3231 def __init__(self):
3332 Installation_System.__init__(self)
 33+ self.destination_dir=settings.instancesdir
3434
3535 def get_installers(self):
3636 """list available items"""
@@ -51,6 +51,8 @@
5252
5353 def get_installed(self):
5454 """list installed items"""
 55+ if not self.destination_dir:
 56+ raise Exception("Internal Error: Mediawiki_Installer: get_installed, self.destination_dir not set")
5557 return os.listdir(self.destination_dir)
5658
5759 def is_installed(self, installer_name):
@@ -83,7 +85,7 @@
8486 #duplicate of get_installed() TODO: Refactor
8587 def installed():
8688 """list installed items"""
87 - return os.listdir(settings.revisionsdir)
 89+ return os.listdir(settings.instancesdir)
8890
8991 #duplicate of get_installers() TODO: Refactor
9092 def available():
@@ -121,7 +123,7 @@
122124 return
123125
124126 #Everything checks out ok, so let's install.
125 - os.chdir(settings.revisionsdir)
 127+ os.chdir(settings.instancesdir)
126128 print "Checking out code from subversion (please be patient)..."
127129 if latest:
128130 checkout_latest(name)
@@ -150,7 +152,7 @@
151153 return
152154
153155 #Ok, looks like our arguments are valid.
154 - os.chdir(settings.revisionsdir)
 156+ os.chdir(settings.instancesdir)
155157 print "Dropping database..."
156158 dropdb(target)
157159 print "Deleting directory..."
@@ -182,17 +184,17 @@
183185 LocalSettings.php is the main configuration file for mediawiki."""
184186
185187 template=settings.installerdir+"/LocalSettings.php.template"
186 - localsettings=settings.revisionsdir+"/"+target+"/LocalSettings.php"
 188+ localsettings=settings.instancesdir+"/"+target+"/LocalSettings.php"
187189 replacements={'<<TARGET>>':target,"<<BASE_SCRIPTPATH>>":settings.base_scriptpath}
188190 replace_generic(replacements,template,localsettings)
189 - subdir=settings.revisionsdir+"/"+target+"/LocalSettings"
 191+ subdir=settings.instancesdir+"/"+target+"/LocalSettings"
190192 os.mkdir(subdir)
191193
192194 def logo(target):
193195 """copy a nice logo"""
194196
195197 logo=settings.installerdir+"/Logo.png"
196 - dest=settings.revisionsdir+"/"+target+"/Logo.png"
 198+ dest=settings.instancesdir+"/"+target+"/Logo.png"
197199 shutil.copy(logo,dest)
198200
199201 def makedb(target):
@@ -207,7 +209,7 @@
208210 """use the maintenance/tables.sql file provided by target mediawiki
209211 instance to generate our tables"""
210212
211 - target_file=settings.revisionsdir+"/"+target+"/maintenance/tables.sql"
 213+ target_file=settings.instancesdir+"/"+target+"/maintenance/tables.sql"
212214 do_sql(target, target_file)
213215
214216 def make_admin(target):
Index: trunk/wikiation/installer/download_installer.py
@@ -3,7 +3,7 @@
44 #
55 # Distributed under the terms of the MIT license.
66
7 -import settings
 7+import settings_handler as settings
88 import os, os.path, shutil
99 import subprocess
1010
@@ -21,9 +21,9 @@
2222 system_name='download'
2323 destination_dir=None
2424
25 - def set_revision(self,revision):
26 - self.destination_dir=os.path.join(settings.revisionsdir,revision,"extensions")
27 - Installation_System.set_revision(self,revision)
 25+ def set_instance(self,instance):
 26+ self.destination_dir=os.path.join(settings.instancesdir,instance,"extensions")
 27+ Installation_System.set_instance(self,instance)
2828
2929 def get_installers(self):
3030 l=list(os.popen('svn ls '+settings.extensionsdir))
@@ -36,10 +36,10 @@
3737 #exists() ok.
3838
3939 def installdir_name():
40 - raise Unsupported_Exception("naive installer does not use installdirs")
 40+ raise Unsupported_Exception("download installer does not use installdirs")
4141
4242 def exec_task():
43 - raise Unsupported_Exception("naive installer does not use installdirs, and therefore also does not exec scripts in installdirs")
 43+ raise Unsupported_Exception("download installer does not use installdirs, and therefore also does not exec scripts in installdirs")
4444
4545 def can_exec(self, installer_name, task):
4646 return False # we don't have an installdir, so we
@@ -48,8 +48,8 @@
4949 # get_installed: works ok.
5050
5151 def is_installed(self, installer_name):
52 - if self.revision==None:
53 - raise Download_Installer_Exception("no revision specified ... did you try doing ... in <Revision> ?")
 52+ if self.instance==None:
 53+ raise Download_Installer_Exception("no instance specified ... did you try doing ... in <instance> ?")
5454 path=os.path.join(self.destination_dir,installer_name)
5555 return os.path.isdir(path)
5656
Index: trunk/wikiation/installer/util/allnaive.py
@@ -28,7 +28,7 @@
2929
3030 def test_extension(extension_name):
3131 installer=Naive_Installer()
32 - installer.set_revision(target_wiki)
 32+ installer.set_instance(target_wiki)
3333 installer.install(extension_name)
3434 result=do_test()
3535 print "result=",result
@@ -40,7 +40,7 @@
4141 installer=Naive_Installer()
4242 # NOTE TO SELF set_revision is a bad name for this...
4343 # needs refactoring
44 - installer.set_revision(target_wiki)
 44+ installer.set_instance(target_wiki)
4545 naive_extensions=installer.get_installers()
4646 for extension_name in naive_extensions:
4747 print extension_name,

Status & tagging log