Index: trunk/wikiation/installer/naive_installer.py |
— | — | @@ -0,0 +1,92 @@ |
| 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 | +import settings |
| 8 | +import os, os.path, shutil |
| 9 | +import subprocess |
| 10 | + |
| 11 | +from installation_system import Installation_System |
| 12 | +from extension_installer import Extension_Installer_Exception |
| 13 | + |
| 14 | +class Naive_Installer_Exception(Extension_Installer_Exception): |
| 15 | + pass |
| 16 | + |
| 17 | +class Unsupported_Exception(Exception): |
| 18 | + pass |
| 19 | + |
| 20 | +class Naive_Installer(Installation_System): |
| 21 | + system_name='extensions' |
| 22 | + destination_dir=None |
| 23 | + |
| 24 | + def set_revision(self,revision): |
| 25 | + self.destination_dir=os.path.join(settings.revisionsdir,revision,"extensions") |
| 26 | + Installation_System.set_revision(self,revision) |
| 27 | + |
| 28 | + def get_installers(self): |
| 29 | + l=list(os.popen('svn ls '+settings.extensionsdir)) |
| 30 | + # tidy l in place |
| 31 | + for i in range(len(l)): |
| 32 | + l[i]=l[i].strip() |
| 33 | + if l[i].endswith("/"): |
| 34 | + l[i]=l[i][:-1] |
| 35 | + return l |
| 36 | + #exists() ok. |
| 37 | + |
| 38 | + def installdir_name(): |
| 39 | + raise Unsupported_Exception("naive installer does not use installdirs") |
| 40 | + |
| 41 | + def exec_task(): |
| 42 | + raise Unsupported_Exception("naive installer does not use installdirs, and therefore also does not exec scripts in installdirs") |
| 43 | + |
| 44 | + def can_exec(self, installer_name, task): |
| 45 | + return False # we don't have an installdir, so we |
| 46 | + # can never exec a task. |
| 47 | + |
| 48 | + # get_installed: works ok. |
| 49 | + |
| 50 | + def is_installed(self, installer_name): |
| 51 | + if self.revision==None: |
| 52 | + raise Naive_Installer_Exception("no revision specified ... did you try doing ... in <Revision> ?") |
| 53 | + path=os.path.join(self.destination_dir,installer_name) |
| 54 | + return os.path.isdir(path) |
| 55 | + |
| 56 | + # get info will cause an exception to be raised |
| 57 | + # install: ok. |
| 58 | + |
| 59 | + def do_download (self, installer_name, destination_dir): |
| 60 | + os.chdir(destination_dir) |
| 61 | + command="svn checkout '"+\ |
| 62 | + settings.extensionsdir+"/"+\ |
| 63 | + installer_name+"'" |
| 64 | + #print command |
| 65 | + os.system(command) |
| 66 | + |
| 67 | + def _settings_filepath(self, installer_name): |
| 68 | + settingsdir=os.path.join(self.destination_dir,"../LocalSettings") |
| 69 | + filename=installer_name+".settings.php" |
| 70 | + filepath=os.path.join(settingsdir,filename) |
| 71 | + return filepath |
| 72 | + |
| 73 | + def install_settings(self,installer_name): |
| 74 | + |
| 75 | + settings=file(self._settings_filepath(installer_name),"w") |
| 76 | + |
| 77 | + n=installer_name |
| 78 | + settings.write('<?PHP\n') |
| 79 | + settings.write('require_once("$IP/extensions/'+n+'/'+n+'.php");\n'); |
| 80 | + settings.write('?>\n') |
| 81 | + settings.close() |
| 82 | + |
| 83 | + def uninstall_settings(self,installer_name): |
| 84 | + # rm -f (fail silently) |
| 85 | + try: |
| 86 | + os.unlink(self._settings_filepath(installer_name)) |
| 87 | + except OSError: |
| 88 | + pass |
| 89 | + |
| 90 | + def do_uninstall(self, installer_name, destination_dir): |
| 91 | + pathname=os.path.join(destination_dir, installer_name) |
| 92 | + shutil.rmtree(pathname,ignore_errors=True) |
| 93 | + |