r47645 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r47644‎ | r47645 | r47646 >
Date:02:19, 22 February 2009
Author:kim
Status:deferred
Tags:
Comment:
Added the naive installer, which *should* be able to install maybe
80% of our 360+ extensions.

Also prettified the output of ls into columns.
This is not a luxury if you're trying to read a listing
of 360+ items ;-)
Modified paths:
  • /trunk/wikiation/installer/installation_system.py (modified) (history)
  • /trunk/wikiation/installer/installer.py (modified) (history)
  • /trunk/wikiation/installer/installer_util.py (modified) (history)
  • /trunk/wikiation/installer/installers.py (modified) (history)

Diff [purge]

Index: trunk/wikiation/installer/installer_util.py
@@ -67,4 +67,73 @@
6868
6969 return target
7070
 71+def pretty_list(mylist,layout_width=None):
 72+ """format a list ~like ls"""
7173
 74+ if layout_width==None:
 75+ layout_width=getTerminalSize()[0]
 76+
 77+
 78+ if layout_width:
 79+ #first find the widest item
 80+ max_width=0
 81+ for item in mylist:
 82+ width=len(item)+1
 83+ if width>max_width:
 84+ max_width=width
 85+
 86+ #now calculate
 87+ columns=max( layout_width/max_width ,1)
 88+ column_width=layout_width/columns-1
 89+
 90+ #and let's go
 91+ text=""
 92+ column=0
 93+ for item in mylist:
 94+ text+=item
 95+ text+=" "*(column_width-len(item)+1)
 96+ column+=1
 97+ if column>=columns:
 98+ text+="\n"
 99+ column=0
 100+ else:
 101+ #naive alternative in case we can't get a clear
 102+ #idea of what terminal we're on.
 103+ text="\n".join(mylist)
 104+
 105+ return text
 106+
 107+
 108+def getTerminalSize():
 109+ """determine the size of the terminal we are running in (where available)"""
 110+ def ioctl_GWINSZ(fd):
 111+ try:
 112+ import fcntl, termios, struct, os
 113+ cr = struct.unpack('hh', fcntl.ioctl(fd, termios.TIOCGWINSZ,
 114+ '1234'))
 115+ except:
 116+ return None
 117+ return cr
 118+ cr = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2)
 119+ if not cr:
 120+ try:
 121+ fd = os.open(os.ctermid(), os.O_RDONLY)
 122+ cr = ioctl_GWINSZ(fd)
 123+ os.close(fd)
 124+ except:
 125+ pass
 126+ if not cr:
 127+ try:
 128+ cr = (env['LINES'], env['COLUMNS'])
 129+ except:
 130+ cr = (25, 80)
 131+ return int(cr[1]), int(cr[0])
 132+
 133+
 134+if __name__=="__main__":
 135+ print "some tests for the utils module"
 136+
 137+ x=range(1000,200000,1512)
 138+ x=[str(i) for i in x]
 139+ print x
 140+ print pretty_list(x)
Index: trunk/wikiation/installer/installer.py
@@ -81,7 +81,9 @@
8282 print \
8383 """available.mediawiki: installed.mediawiki:
8484 available.wikiation_toolkit: installed.wikiation_toolkit:
85 -available.extension: installed.extension: """
 85+available.extension: installed.extension:
 86+available.naive: installed.naive:
 87+"""
8688 return
8789 installers.ls(args)
8890
Index: trunk/wikiation/installer/installers.py
@@ -6,11 +6,13 @@
77 import settings
88 import os, os.path, shutil
99 import subprocess
 10+import installer_util
1011
1112 #from installation_system import Installation_System
1213 from toolkit_installer import Toolkit_Installer
1314 from extension_installer import Extension_Installer
1415 from mediawiki_installer import Mediawiki_Installer
 16+from naive_installer import Naive_Installer
1517 from installation_system import Installer_Exception
1618
1719 class Parse_Exception(Exception):
@@ -37,10 +39,8 @@
3840
3941 if output==None:
4042 return
 43+ print installer_util.pretty_list(output)
4144
42 - for line in output:
43 - print line
44 -
4545 def ls_available(ppath):
4646 if ppath["system"]==None:
4747 return ls_systems()
@@ -268,6 +268,8 @@
269269
270270
271271
 272+
 273+
272274 def get_system(system_name):
273275 if system_name not in systems:
274276 print "Cannot find '"+system_name+"' in the list of supported installation systems."
@@ -277,7 +279,7 @@
278280
279281 return sYstem()
280282
281 -systems={'wikiation_toolkit':Toolkit_Installer,'extension': Extension_Installer, 'mediawiki':Mediawiki_Installer}
 283+systems={'wikiation_toolkit':Toolkit_Installer,'extension': Extension_Installer, 'mediawiki':Mediawiki_Installer,'naive': Naive_Installer}
282284
283285 if __name__=="__main__":
284286 print "testing installers.py module"
Index: trunk/wikiation/installer/installation_system.py
@@ -166,7 +166,10 @@
167167
168168 if not self.exists(installer_name):
169169 raise Installer_Exception("Can't find installer "+installer_name)
170 -
 170+
 171+ self.do_download(installer_name, destination_dir)
 172+
 173+ def do_download(self, installer_name, destination_dir):
171174 # if a particular step in the install procedure is not provided
172175 # we simply skip it
173176 if not self.can_exec(installer_name,"download"):
@@ -197,14 +200,16 @@
198201 print installer_name+" does not appear to be installed"
199202 return
200203
201 - # if a particular step in the install procedure is not provided
202 - # we simply skip it
203 - if not self.can_exec(installer_name,"uninstall"):
204 - return
 204+
 205+ self.do_uninstall(installer_name, destination_dir)
205206
206 - self.exec_task(installer_name,"uninstall")
207 -
208207 self.uninstall_settings(installer_name)
209208 # use is_installed to determine success.
210209 return not self.is_installed(installer_name)
211 -
 210+
 211+ def do_uninstall(self,installer_name, destination_dir):
 212+ # if a particular step in the install procedure is not provided
 213+ # we simply skip it
 214+ if self.can_exec(installer_name,"uninstall"):
 215+ self.exec_task(installer_name,"uninstall")
 216+

Status & tagging log