Index: trunk/wikiation/installer/installer_util.py |
— | — | @@ -67,4 +67,73 @@ |
68 | 68 | |
69 | 69 | return target |
70 | 70 | |
| 71 | +def pretty_list(mylist,layout_width=None): |
| 72 | + """format a list ~like ls""" |
71 | 73 | |
| 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 @@ |
82 | 82 | print \ |
83 | 83 | """available.mediawiki: installed.mediawiki: |
84 | 84 | available.wikiation_toolkit: installed.wikiation_toolkit: |
85 | | -available.extension: installed.extension: """ |
| 85 | +available.extension: installed.extension: |
| 86 | +available.naive: installed.naive: |
| 87 | +""" |
86 | 88 | return |
87 | 89 | installers.ls(args) |
88 | 90 | |
Index: trunk/wikiation/installer/installers.py |
— | — | @@ -6,11 +6,13 @@ |
7 | 7 | import settings |
8 | 8 | import os, os.path, shutil |
9 | 9 | import subprocess |
| 10 | +import installer_util |
10 | 11 | |
11 | 12 | #from installation_system import Installation_System |
12 | 13 | from toolkit_installer import Toolkit_Installer |
13 | 14 | from extension_installer import Extension_Installer |
14 | 15 | from mediawiki_installer import Mediawiki_Installer |
| 16 | +from naive_installer import Naive_Installer |
15 | 17 | from installation_system import Installer_Exception |
16 | 18 | |
17 | 19 | class Parse_Exception(Exception): |
— | — | @@ -37,10 +39,8 @@ |
38 | 40 | |
39 | 41 | if output==None: |
40 | 42 | return |
| 43 | + print installer_util.pretty_list(output) |
41 | 44 | |
42 | | - for line in output: |
43 | | - print line |
44 | | - |
45 | 45 | def ls_available(ppath): |
46 | 46 | if ppath["system"]==None: |
47 | 47 | return ls_systems() |
— | — | @@ -268,6 +268,8 @@ |
269 | 269 | |
270 | 270 | |
271 | 271 | |
| 272 | + |
| 273 | + |
272 | 274 | def get_system(system_name): |
273 | 275 | if system_name not in systems: |
274 | 276 | print "Cannot find '"+system_name+"' in the list of supported installation systems." |
— | — | @@ -277,7 +279,7 @@ |
278 | 280 | |
279 | 281 | return sYstem() |
280 | 282 | |
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} |
282 | 284 | |
283 | 285 | if __name__=="__main__": |
284 | 286 | print "testing installers.py module" |
Index: trunk/wikiation/installer/installation_system.py |
— | — | @@ -166,7 +166,10 @@ |
167 | 167 | |
168 | 168 | if not self.exists(installer_name): |
169 | 169 | 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): |
171 | 174 | # if a particular step in the install procedure is not provided |
172 | 175 | # we simply skip it |
173 | 176 | if not self.can_exec(installer_name,"download"): |
— | — | @@ -197,14 +200,16 @@ |
198 | 201 | print installer_name+" does not appear to be installed" |
199 | 202 | return |
200 | 203 | |
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) |
205 | 206 | |
206 | | - self.exec_task(installer_name,"uninstall") |
207 | | - |
208 | 207 | self.uninstall_settings(installer_name) |
209 | 208 | # use is_installed to determine success. |
210 | 209 | 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 | + |