#Copyright (c) 2005 by Mark T. Holder, Florida State University. (see end of file) '''Convenience functions to consolidate repetitive tasks and hide cipres implementation details''' # CIPRES types are corba-enabled versions of the PIPRes datatypes. # The separation only exists so that users of PIPRes are not required # to have the corba portions of the PIPRes (and omniorbPy) installed # if they only want to use pure python portions of PIPRes. # The Cipres versions of the types have a method createCorbaVersion(self) # which returns of the corresponding CipresIDL_api1 type ready to be passed as an # argument to or a return value from a remote call. from PIPRes.util.cipres_registry_from_xml import CipresRegistryInterface, CipresRegistryExtension, parseEntryCommandline, PythonRegistryInfo, PipresRegistryEntry from PIPRes.wrap.idl import CipresInterfaceEnum from PIPRes.util.io import expandPath from PIPRes.util.cipres import getCipresProperties class SimpleRegistryEntry(PipresRegistryEntry): '''A class for creating new registry entries at runtime.''' def __init__(self, applicationName, interface, **kwargs): '''kwargs can contain the data that would be in an cipres_registry.xml file. either ommand/commandline/ior must be specified. sending the kwarg cipresC or cipresPython, automatically adds cipres arguments and launch env, etc.''' cipresProperties = kwargs.get('cipresProperties') if cipresProperties is None: cipresProperties = getCipresProperties() defaults = ( ('entryType', 0), ('args', []), ('description', ''), ('uiXmlFilename', ''), ('launchEnv', {}), ('ior', ''), ('command', ''), ('debugMode', False), ('python', None)) if isinstance(interface, str): interface = CipresInterfaceEnum.getCode(interface) ctorDict = { 'applicationName' : applicationName, 'interface' : interface } for k, v in defaults: ctorDict[k] = kwargs.get(k,v) pyAtt = ctorDict['python'] for optional in PipresRegistryEntry.extensionsToXML: if optional in kwargs: ctorDict[d] = kwargs[d] if kwargs.has_key('commandline'): ctorDict['command'], args = parseEntryCommandline(kwargs['commandline']) ctorDict['args'] = args + ctorDict['args'] if ctorDict['ior'] == '' and ctorDict['command'] == '': if bool(kwargs.get('cipresPython')): ctorDict['command'] = 'python' if len(ctorDict['args']) == 0: raise TypeError, 'Expecting a script name as the first element of the list "args" when "cipresPython" is True' else: raise TypeError, 'A non-empty "command", "commandline", or "ior" argument is required' if pyAtt is not None: pydict = isinstance(pyAtt, PythonRegistryInfo) and pyAtt.__dict__ or pyAtt if bool(kwargs.get('cipresPython')) and len(ctorDict['args']) > 1: pydict['args'].extend(ctorDict['args'][1:]) ctorDict['python'] = PythonRegistryInfo(**pydict) if bool(kwargs.get('cipresC')) or bool(kwargs.get('cipresPython')): launchEnv = ctorDict['launchEnv'] dottedDecAddressArgs = bool(kwargs.get('cipresC')) and ['-ORBDottedDecimalAddresses', '1'] or [] ctorDict['args'] += ['-CipresImpl', CipresInterfaceEnum.getName(interface), ] + dottedDecAddressArgs + ['%%IORFILE', '-CipresNoNs'] if bool(kwargs.get('cipresPython')): if cipresProperties.platform.startswith('darwin'): launchEnv['DYLD_BIND_AT_LAUNCH'] = '1' if ctorDict.has_key('command'): import os ctorDict['command'] = expandPath(ctorDict['command']) PipresRegistryEntry.__init__(self, ctorDict) class SimpleRegistry(CipresRegistryInterface): def __init__(self, registryID, entries): if registryID: self.registryInstanceID = registryID self.entries = entries self._classifyRawEntries() self.properties = getCipresProperties() class RichCipresRegistry(CipresRegistryInterface, CipresRegistryExtension): '''Front end for interacting the the CipresRegistryFromXML. should be viewed as immutable. Provides getService functionality and bindOrRebind (for advertising services. Based on intialization, the interface knows whether it should check a name service or use the CipresRegistryFromXML to perform these tasks''' def __init__(self,**kwargs): reg = kwargs.get('cipresRegistry') if reg is None: self.entries = [] self._classifyRawEntries() else: import copy self.__dict__.update(copy.copy(reg.__dict__)) self.implName = kwargs.get('implName') # can be overridden by specifying name in bindOrRebind self.namingContext = kwargs.get('namingContextRef', None) self.rootName = kwargs.get('nameOfContext', 'NameService') self.nsRegister = kwargs.get('nsRegister', False) self.nsLookup = kwargs.get('nsLookup', False) if (self.nsLookup or self.nsRegister) and None == self.namingContext: raise ValueError, 'namingContext must be provided if nsRegister or nsLookup is True' self.iorFileName = kwargs.get('iorFileName') self.objRefTranslator = kwargs.get('stubTranslator',{}) self.duplicateServiceChooser = kwargs.get('disambiguator') self.properties = getCipresProperties() # This file is part of the PIPRes library # # The PIPRes library is free software; you can redistribute it # and/or modify it under the terms of the GNU Lesser General # Public License as published by the Free Software Foundation; # either version 2.1 of the License, or (at your option) any later # version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free # Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, # MA 02111-1307, USA