r48850 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r48849‎ | r48850 | r48851 >
Date:02:11, 26 March 2009
Author:kim
Status:deferred
Tags:
Comment:
implement duplicate command
Modified paths:
  • /trunk/wikiation/installer/installer.py (modified) (history)
  • /trunk/wikiation/installer/installers.py (modified) (history)
  • /trunk/wikiation/installer/mediawiki_installer.py (modified) (history)
  • /trunk/wikiation/installer/settings_handler.py (modified) (history)

Diff [purge]

Index: trunk/wikiation/installer/settings_handler.py
@@ -42,11 +42,6 @@
4343 #where wikiation_check_isolation can be found
4444 isolation_create=toolkit_dir+'/wikiation_check_isolation/create_and_ul.sh'
4545 isolation_test=toolkit_dir+'/wikiation_check_isolation/dl_and_check.sh'
46 -
47 -# what mysql command should be used. (Who us? Use horrible hacks?)
48 -
49 -mysql_command="mysql -uwiki -pwiki1234"
50 -
5146 # run automated tests during installation
5247 # this is useful if you are in a testing environment.
5348 # If you are running production, you might want to leave
@@ -59,7 +54,27 @@
6055 adminuser_name="admin"
6156 adminuser_password="admin1234"
6257
 58+#mysql info
 59+mysql_user="root"
 60+mysql_pass=""
6361
 62+# what mysql commands should be used. (Who us? Use horrible hacks?)
 63+
 64+userpart=""
 65+passpart=""
 66+if mysql_user:
 67+ userpart="-u"+mysql_user
 68+if mysql_pass:
 69+ passpart="-p"+mysql_pass
 70+
 71+mysql_arguments=" "+userpart+" "+passpart
 72+
 73+if not 'mysql_command' in globals():
 74+ mysql_command="mysql "+mysql_arguments
 75+
 76+if not 'mysqldump_command' in globals():
 77+ mysqldump_command="mysqldump "+mysql_arguments
 78+
6479 if os.path.exists(os.path.join(installerdir, 'settings.py')):
6580 from settings import *
6681
Index: trunk/wikiation/installer/installer.py
@@ -80,6 +80,11 @@
8181 """install something"""
8282 installers.install(args)
8383
 84+def duplicate(args):
 85+ """duplicate an instance"""
 86+ if len(args)!=3:
 87+ print "syntax:\n duplicate source_instance destination_instance"
 88+ installers.duplicate(args)
8489
8590 def uninstall(args):
8691 """uninstall something"""
@@ -154,7 +159,8 @@
155160 "info":info,
156161 "check_isolation":check_isolation,
157162 "update_self":update_self,
158 - "update_tags":update_tags
 163+ "update_tags":update_tags,
 164+ "duplicate":duplicate
159165 }
160166
161167 # additional help texts for some commands.
Index: trunk/wikiation/installer/mediawiki_installer.py
@@ -115,7 +115,31 @@
116116 return settings.trunkdir
117117
118118
 119+ def duplicate(self, src, dst):
 120+ if not self.is_installed(src):
 121+ raise Mediawiki_Installer_Exception(src+" not found.")
119122
 123+ if self.is_installed(dst):
 124+ raise Mediawiki_Installer_Exception(dst+" already exists.")
 125+
 126+ srcpath= os.path.join(settings.instancesdir,src)
 127+ dstpath= os.path.join(settings.instancesdir,dst)
 128+ dbtmp=os.path.join(dstpath,"installerdbtmp.sql")
 129+ print "Copying instance files..."
 130+ shutil.copytree(srcpath,dstpath,symlinks=True)
 131+ print "updating unique settings"
 132+ uniquesettings(dst)
 133+ print "Copying instance database..."
 134+ dumpdb(src,dbtmp)
 135+ dropdb(dst)
 136+ createdb(dst)
 137+ do_sql(dst,dbtmp)
 138+ print "cleanup"
 139+ os.unlink(dbtmp)
 140+ print "done."
 141+
 142+
 143+
120144 #TODO: use this method everywhere a database name is requested
121145 def dbname(installer_name):
122146 """based on the name of the installer/instance, figure out what the name of the
@@ -172,8 +196,9 @@
173197 else:
174198 checkout(target+"/", name, revision)
175199
176 - print "Creating LocalSettings.php..."
 200+ print "Copying LocalSettings.php,creating unique settings..."
177201 localsettings(name)
 202+ uniquesettings(name)
178203 print "Copy logo..."
179204 logo(name)
180205 print "Setting up database..."
@@ -228,19 +253,22 @@
229254
230255 def localsettings(target):
231256 """Copy over our LocalSettings.php , and create InstallerUniqueSettings.php
232 - (which contains settings unique to this instance)
 257+ (which contains settings unique to this instance), and create LocalSettings dir.
233258 LocalSettings.php is the main configuration file for mediawiki."""
234259
235260 here=settings.installerdir+"/LocalSettings.php"
236261 instancedir=settings.instancesdir+"/"+target
237262 there=instancedir+"/LocalSettings.php"
238263 shutil.copy2(here,there)
 264+ subdir=os.path.join(settings.revisionsdir,target,"LocalSettings")
 265+ os.mkdir(subdir)
239266
 267+def uniquesettings(target):
240268 uniquesettings=settings.instancesdir+"/"+target+"/InstallerUniqueSettings.php"
241269 unique=file(uniquesettings,"w")
242270 unique.write('<?php\n')
243271 unique.write('$wgSitename = "Wikiation_'+target+'";\n')
244 - unique.write('$wgScriptPath = "'+settings.base_scriptpath+"/"+target+'";\n')
 272+ unique.write('$wgScriptPath = "'+settings.base_scriptpath+target+'";\n')
245273 unique.write('$wgDBname = "'+target+'";\n')
246274 unique.write('?>\n')
247275
@@ -276,6 +304,10 @@
277305 command="php "+phpfile+" --bureaucrat "+settings.adminuser_name+" "+settings.adminuser_password
278306 os.system(command)
279307
 308+def dumpdb(target,outfile):
 309+ command=settings.mysqldump_command+" "+target+" > "+outfile
 310+ os.system(command)
 311+
280312 def do_sql(target, infile):
281313 """execute an sql file, using mysql"""
282314
Index: trunk/wikiation/installer/installers.py
@@ -147,6 +147,14 @@
148148 system.get_info(ppath["installer"])
149149
150150
 151+def duplicate(args):
 152+ mw=get_system("mediawiki")
 153+ try:
 154+ mw.duplicate(args[1],args[2])
 155+ except Mediawiki_Installer_Exception,e:
 156+ print e.message
 157+
 158+
151159 def install(args):
152160 if len(args)<1:
153161 print "install: Internal error: expected more arguments"

Status & tagging log