Revision: 48696 Author: kim Date: 2009-03-22 23:30:54 +0000 (Sun, 22 Mar 2009)
Log Message: ----------- Add Combined_Installer extension: now uses Combined_Installer This still needs lots of testing! Modified Paths: -------------- trunk/wikiation/installer/installation_system.py trunk/wikiation/installer/installer_util.py trunk/wikiation/installer/installers.py Added Paths: ----------- trunk/wikiation/installer/combined_installer.py trunk/wikiation/installer/extension_installer2.py Added: trunk/wikiation/installer/combined_installer.py =================================================================== --- trunk/wikiation/installer/combined_installer.py (rev 0) +++ trunk/wikiation/installer/combined_installer.py 2009-03-22 23:30:54 UTC (rev 48696) @@ -0,0 +1,174 @@ +# This software, copyright (C) 2008-2009 by Wikiation. +# This software is developed by Kim Bruning. +# +# Distributed under the terms of the MIT license. + + +from installation_system import Installation_System, Installer_Exception + +class Combined_Installer_Exception(Installer_Exception): + pass + +class Combined_Installer(Installation_System): + """operate a whole list of installers at once. + attempts to perform an action with each installer + in list in turn, until one of them works""" + system_name="combined" + destination_dir=None + systemlist=None + + def __init__(self, systemlist): + """initialize with a list of pre-initialized + installers + """ + Installation_System.__init__(self) + self.systemlist=systemlist + + def set_instance(self,instance): + """set instance on all items""" + for system in self.systemlist: + system.set_instance(instance) + + def get_installers(self): + installers=set() + for system in self.systemlist: + try: + installers.update(system.get_installers()) + except Exception: + pass + + installers2=list(installers) + installers2.sort() + return installers2 + + def get_revisions(self,installer_name): + revisions=[] + for system in self.systemlist: + try: + revisions=system.get_revisions(installer_name) + except Exception: + pass + + if revisions: + break + + return revisions + + def get_tags(self, installer_name): + tags=[] + for system in self.systemlist: + try: + tags=system.get_tags(installer_name) + except Exception: + pass + + if tags: + break + + return tags + + def get_svnbase(self): + return None + + # exists: ok + # installdir_name: unused + + def exec_task(self, installer_name, task, env=None): + """try systems, if any system can_exec, we exec. + short circuits: Only first system with capability + will exec""" + for system in self.systemlist: + if system.can_exec(task): + system.exec_task(installer_name, task, env) + break + + + def can_exec(self, installer_name, task): + """reply if we can execute a task, (allows nested + combined_installers, fwiw. Short circuits (stops + trying once it finds one system that supports the task))""" + for system in self.systemlist: + if system.can_exec(self, installer_name, task): + return True + + return False + + def get_installed(self): + """return a list of installed items (items installed by all the installers)""" + installers=set() + for system in self.systemlist: + try: + installers.update(system.get_installed()) + except Exception: + pass + + installers2=list(installers) + installers2.sort() + return installers2 + + def is_installed(self,installer_name): + """return true if any of the installers finds that the particular item is already installed. (short circuits)""" + for system in self.systemlist: + if system.is_installed(installer_name): + return True + + def get_info(self, installer_name): + """print out information about the target from the info file, short circuits""" + for system in self.systemlist: + ret=system.get_info() + if ret: + return ret + return None + + def install(self, installer_name): + """actually install something. Short circuits (Will try each installer, until success""" + for system in self.systemlist: + try: + if system.install(installer_name): + return True + except: #TODO sometimes an installer may recognise that something CAN NOT be installed, in that case, we should stop trying. + pass + + return False + + def setup(self, installer_name, destination_dir=None): + raise Combined_Installer_Exception("Internal Error:Can't do setup from here") + + + def download (self, installer_name, destination_dir=None): + raise Combined_Installer_Exception("Internal Error:Can't do download from here") + + + def install_settings(self,installer_name): + raise Combined_Installer_Exception("Internal Error:Can't do download from here") + + + def uninstall_settings(self,installer_name): + raise Combined_Installer_Exception("Internal Error:Can't do download from here") + + def uninstall(self, installer_name): + """actually uninstall something. Short circuits (Will try each installer, until success)""" + for system in self.systemlist: + try: + if system.uninstall(installer_name): + return True + except: #TODO sometimes an installer may recognise that something CAN NOT be uninstalled, in that case, we should stop trying + pass + + return False + + + + def get_extensionsdir(self): + raise Combined_Installer_Exception("Internal Error:Can't do download from here") + + + def __setattr__(self,name,value): + """also set any attributes for subsystems + we also set the same attribute locally. + Be careful when reading back!""" + self.__dict__[name]=value + if self.systemlist: + for system in self.systemlist: + system.__setattr__(name,value) + Added: trunk/wikiation/installer/extension_installer2.py =================================================================== --- trunk/wikiation/installer/extension_installer2.py (rev 0) +++ trunk/wikiation/installer/extension_installer2.py 2009-03-22 23:30:54 UTC (rev 48696) @@ -0,0 +1,20 @@ +# This software, copyright (C) 2008-2009 by Wikiation. +# This software is developed by Kim Bruning. +# +# Distributed under the terms of the MIT license. + +from combined_installer import Combined_Installer +from scripted_installer import Scripted_Installer +from naive_installer import Naive_Installer + + +def extension_installer2(): + """factory: returns a combined installer that installs extensions from either scripted or naive + + technical detail: + For use with installers.get_system(system_name) + we exploit the fact that instantiation has the same semantics as a function call""" + scripted=Scripted_Installer() + naive=Naive_Installer() + combined=Combined_Installer([scripted,naive]) + return combined Modified: trunk/wikiation/installer/installation_system.py =================================================================== --- trunk/wikiation/installer/installation_system.py 2009-03-22 23:27:27 UTC (rev 48695) +++ trunk/wikiation/installer/installation_system.py 2009-03-22 23:30:54 UTC (rev 48696) @@ -9,10 +9,10 @@ from tags import Tags -class Installer_Exception (Exception): +class Installer_Exception(Exception): pass -class Installation_System: +class Installation_System(object): """An Abstract Installation System. Don't instantiate this class directly. An installation system understands how to install and uninstall 'things' (instances). An instance might be a particular wiki @@ -241,6 +241,7 @@ if os.path.exists(info_filename): print file(info_filename).read() + return True else: print "This installer provides no information." Modified: trunk/wikiation/installer/installer_util.py =================================================================== --- trunk/wikiation/installer/installer_util.py 2009-03-22 23:27:27 UTC (rev 48695) +++ trunk/wikiation/installer/installer_util.py 2009-03-22 23:30:54 UTC (rev 48696) @@ -72,7 +72,7 @@ print "=== Wikiation installer (v. "+revision()+") ===" print - print "(last known safe version: 48528) (NOTE: 'extension:' has been renamed 'scripted:'" + print "(last known safe version: 48528)" print "Interactive mode.", print "Automated testing is", if settings.run_automated_tests: @@ -80,6 +80,9 @@ else: print "disabled." print + print "Note: 'extension:' now means something else" + print "if you want the old functionality: use 'scripted:'" + print print "please type a command and hit enter" print "help<enter> for help" print "^D, exit<enter> or quit<enter> to quit" Modified: trunk/wikiation/installer/installers.py =================================================================== --- trunk/wikiation/installer/installers.py 2009-03-22 23:27:27 UTC (rev 48695) +++ trunk/wikiation/installer/installers.py 2009-03-22 23:30:54 UTC (rev 48696) @@ -19,6 +19,7 @@ from naive_installer import Naive_Installer from installation_system import Installer_Exception from download_installer import Download_Installer +from extension_installer2 import extension_installer2 from tags import Tags, TagsException @@ -361,7 +362,7 @@ # Constants -systems={'wikiation_toolkit':Toolkit_Installer,'scripted': Scripted_Installer, 'mediawiki':Mediawiki_Installer,'naive': Naive_Installer, 'download':Download_Installer} +systems={'wikiation_toolkit':Toolkit_Installer,'scripted': Scripted_Installer, 'mediawiki':Mediawiki_Installer,'naive': Naive_Installer, 'download':Download_Installer, 'extension':extension_installer2} if __name__=="__main__": _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs