Changeset 1148


Ignore:
Timestamp:
02/16/09 16:05:22 (5 years ago)
Author:
wehart
Message:

. Adding support for reseting Option objects.

. Added option to ExtensionPoint? methods to explicitly request
all extension points. This disables the filtering done by
the PluginEnvironment?, which filters disabled plugins, by default.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/pyutilib/plugin/config/options.py

    r1147 r1148  
    5656        """Return a string value that describes the default option value""" 
    5757 
     58    def reset(self): 
     59        """Reset all options to their default values.""" 
     60 
    5861 
    5962class IUpdatedOptionsAction(Interface): 
     
    190193        self.set_value(_value_) 
    191194        return True 
     195 
     196    def reset(self): 
     197        """Set option to its default value""" 
     198        self.set_value(self.default) 
    192199 
    193200    def default_str(self): 
     
    225232        if name is None: 
    226233            raise OptionError, "The Option class requires a name" 
    227         self.set_value(self.default) 
     234        self.reset() 
    228235 
    229236    def _parse_option(self, k, v): 
  • trunk/pyutilib/plugin/config/tempfiles.py

    r1147 r1148  
    5757        self._tempfiles.append(ans[1]) 
    5858        os.close(ans[0]) 
     59        os.remove(ans[1]) 
    5960        return ans[1] 
    6061 
     
    7071        """Delete all temporary files.""" 
    7172        for file in self._tempfiles: 
    72             if not os.path.exists(file): 
    73                 raise IOError, "Cannot remove temporary file: "+file 
    74             os.remove(file) 
     73            if os.path.exists(file): 
     74                os.remove(file) 
    7575        self._tempfiles=[] 
    7676 
  • trunk/pyutilib/plugin/core.py

    r1147 r1148  
    360360        return self.extensions().__iter__() 
    361361 
    362     def __call__(self, key=None): 
     362    def __call__(self, key=None, all=False): 
    363363        """ 
    364364        Return a set of services that match the interface of this 
    365365        extension point. 
    366366        """ 
    367         tmp = self.extensions() 
     367        tmp = self.extensions(all=all) 
    368368        # 
    369369        # Return all extensions 
     
    387387        # 
    388388        ans = set() 
    389         for item in self.extensions(): 
     389        for item in self.extensions(all=all): 
    390390            try: 
    391391                if item.interface_key() == key: 
     
    396396        return ans 
    397397 
    398     def service(self, key=None): 
     398    def service(self, key=None, all=False): 
    399399        """ 
    400400        Return the unique service that matches the interface of this 
     
    402402        specified key, or if multiple services match. 
    403403        """ 
    404         ans = ExtensionPoint.__call__(self, key) 
     404        ans = ExtensionPoint.__call__(self, key=key, all=all) 
    405405        if len(ans) != 1: 
    406406                raise PluginError, "The ExtensionPoint does not have a unique service!  %d services are defined for interface %s." % (len(ans), self.interface. __name__) 
     
    414414        return len(self.extensions()) 
    415415 
    416     def extensions(self): 
     416    def extensions(self, all=False): 
    417417        """ 
    418418        Return a set of services that match the interface of this 
     
    421421        ans = set() 
    422422        for env in self.env: 
    423             ans.update(env[self.interface]) 
     423            ans.update(env.active_services(self.interface, all=all)) 
    424424        return ans 
    425425 
     
    475475        return cls in self.services 
    476476 
    477     def __getitem__(self, cls): 
     477    def active_services(self, cls, all=False): 
    478478        """ 
    479479        Return the services that have been activated for a specific interface class. 
     
    488488        # This could be optimized with a cache, but let's do that later... 
    489489        # 
    490         return filter(lambda x: id in x.__interfaces__ and x.enabled(), self.services) 
     490        return filter(lambda x: id in x.__interfaces__ and (all or x.enabled()), self.services) 
    491491 
    492492    def activate(self, service): 
     
    750750            return '<Plugin %s %r>' % (self.__class__.__name__, self.name) 
    751751 
     752    def disable(self): 
     753        """Disable this plugin.""" 
     754        self._enable = False 
     755 
     756    def enable(self): 
     757        """Enable this plugin.""" 
     758        self._enable = True 
     759 
    752760    def enabled(self): 
    753761        """Can be overriden to control whether a plugin is enabled.""" 
  • trunk/pyutilib/plugin_services.py

    r1147 r1148  
    1818    if name is None: 
    1919        return filter(lambda x:x.name, ep.extensions()) 
    20     return ep.service(name).get_path() 
     20    return ep.service(name, all=True) 
    2121 
    2222 
  • trunk/test/plugin/unit/test_core.py

    r1147 r1148  
    295295        PluginGlobals.push_env(env) 
    296296        s0 = Plugin1() 
    297         self.failIfEqual(env[IDebug1],[s0]) 
    298         self.failUnlessEqual(PluginGlobals.env("testing")[IDebug1],[s0]) 
    299         try: 
    300             env[s0] 
     297        self.failIfEqual(env.active_services(IDebug1),[s0]) 
     298        self.failUnlessEqual(PluginGlobals.env("testing").active_services(IDebug1),[s0]) 
     299        try: 
     300            env.active_services(s0) 
    301301            self.fail("Expected failure") 
    302302        except PluginError: 
Note: See TracChangeset for help on using the changeset viewer.