Changeset 13168

Show
Ignore:
Timestamp:
03/13/2005 05:15:41 AM (4 years ago)
Author:
exarkun
Message:
Merge 13145:HEAD of /b/e/newplugins/ into trunk - resolves 906
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/admin/release-twisted

    r13134 r13168  
    123123    sh('tar cjhf %(tdir)s.tar.bz2 %(tdir)s' % locals()) 
    124124 
    125          
    126125 
    127126## 
     
    138137    sh('svn export %s Twisted.exp' % (opts['temptagurl'],)) 
    139138 
    140      
     139 
    141140def makeDocCore(opts): 
    142141    ver = opts['core-version'] 
     
    195194    os.makedirs(os.path.join(tdir, 'twisted')) 
    196195    os.makedirs(os.path.join(tdir, 'bin')) 
    197      
     196 
    198197    twisted_subprojects = ','.join(dist.twisted_subprojects) 
    199198 
     
    234233    zig = glob.glob('ZopeInterface-*.tgz') 
    235234    if not zig: 
    236         raise Exception("Please download ZopeInterface from " 
    237                         "http://www.zope.org/Products/ZopeInterface") 
     235        raise Exception( 
     236            "Creating sumo distribution rquires a ZopeInterface tarball - " 
     237            "Please download one from <http://www.zope.org/Products/ZopeInterface>.") 
    238238    zi = zig[0] 
    239239    os.makedirs(tdir) 
     
    258258                            % subproj) 
    259259        sumoReplace['%s-SVN-Trunk' % subproj.capitalize()] = subver 
    260                                     
     260 
    261261    replaceInFile(os.path.join(tdir, 'README'), sumoReplace) 
    262262    # replace versions for core 
     
    276276    sdir = 'Twisted%s-%s' % (proj.capitalize(), version) 
    277277    os.makedirs(sdir+'/twisted/%s' % (proj,)) 
     278    os.makedirs(sdir+'/twisted/plugins') 
     279 
    278280    sh(''' 
    279281    ln -s `pwd`/Twisted.exp/twisted/%(proj)s/* %(sdir)s/twisted/%(proj)s 
     
    283285    ln -s `pwd`/Twisted.exp/LICENSE %(sdir)s 
    284286    ln -s `pwd`/Twisted.exp/twisted/%(proj)s/topfiles/* %(sdir)s 
     287 
     288    # We want this project's plugin module 
     289    ln -s `pwd`/Twisted.exp/twisted/plugins/twisted_%(proj)s.py %(sdir)s/twisted/plugins 
    285290 
    286291    # we want copies so we can replace versions 
  • trunk/setup.py

    r13158 r13168  
    4343 
    4444    result = os.spawnv(os.P_WAIT, sys.executable, 
    45                    [sys.executable, setupPy] + args) 
     45                       [sys.executable, setupPy] + args) 
    4646    if result != 0: 
    4747        sys.stderr.write("Error: Subprocess exited with result %d for project %s\n" % 
  • trunk/twisted/lore/scripts/lore.py

    r11450 r13168  
    33 
    44import sys 
     5 
     6from zope.interface import Interface, Attribute 
     7 
    58from twisted.lore import process, default, indexer, numberer, htmlbook 
    6 from twisted.python import usage, plugin, reflect 
     9 
     10from twisted.python import usage, plugin as oldplugin, reflect 
     11from twisted import plugin as newplugin 
     12 
     13class IProcessor(Interface): 
     14    """ 
     15    """ 
     16 
     17    factory = Attribute( 
     18        "") 
    719 
    820class Options(usage.Options): 
     
    4052 
    4153def getProcessor(input, output, config): 
    42     plugins = plugin.getPlugIns("lore", None, None) 
     54    plugins = oldplugin._getPlugIns("lore") 
    4355    for plug in plugins: 
    4456        if plug.tapname == input: 
     
    4658            break 
    4759    else: 
    48         # try treating it as a module name 
    49         try: 
    50             module = reflect.namedModule(input) 
    51         except ImportError: 
    52             print '%s: no such input: %s' % (sys.argv[0], input) 
    53             return 
     60        plugins = newplugin.getPlugIns(IProcessor) 
     61        for plug in plugins: 
     62            if plug.name == input: 
     63                module = reflect.namedModule(plug.moduleName) 
     64                break 
     65        else: 
     66            # try treating it as a module name 
     67            try: 
     68                module = reflect.namedModule(input) 
     69            except ImportError: 
     70                print '%s: no such input: %s' % (sys.argv[0], input) 
     71                return 
    5472    try: 
    5573        return process.getProcessor(module, output, config) 
     
    6078def getWalker(df, opt): 
    6179    klass = process.Walker 
    62     if opt['plain']:  
     80    if opt['plain']: 
    6381        klass = process.PlainReportingWalker 
    64     if opt['null']:  
     82    if opt['null']: 
    6583        klass = process.NullReportingWalker 
    6684    return klass(df, opt['inputext'], opt['linkrel']) 
  • trunk/twisted/python/dist.py

    r13096 r13168  
    3535 
    3636        kw['packages'] = getPackages(projdir, parent='twisted') 
     37 
     38        plugin = "twisted/plugins/twisted_" + projname + ".py" 
     39        if os.path.exists(plugin): 
     40            kw.setdefault('py_modules', []).append(plugin.replace("/", ".")[:-3]) 
     41 
    3742        kw['data_files'] = getDataFiles(projdir, parent='twisted') 
     43 
    3844        del kw['twisted_subproject'] 
     45    else: 
     46        if 'plugins' in kw: 
     47            py_modules = [] 
     48            for plg in kw['plugins']: 
     49                py_modules.append("twisted.plugins." + plg) 
     50            kw.setdefault('py_modules', []).extend(py_modules) 
     51            del kw['plugins'] 
     52 
    3953    if 'cmdclass' not in kw: 
    4054        kw['cmdclass'] = { 
  • trunk/twisted/python/plugin.py

    r12868 r13168  
    3434    def isLoaded(self): 
    3535        """Check to see if the module for this plugin has been imported yet. 
    36          
     36 
    3737        @rtype: C{int} 
    3838        @return: A true value if the module for this plugin has been loaded, 
     
    4343    def load(self): 
    4444        """Load the module for this plugin. 
    45          
     45 
    4646        @rtype: C{ModuleType} 
    4747        @return: The module object that is loaded. 
     
    6666        """Register a new plug-in. 
    6767        """ 
     68        warnings.warn("The twisted.python.plugin system is deprecated.  " 
     69                      "See twisted.plugin for the revised edition.", 
     70                      DeprecationWarning, 2) 
    6871        self.plugins.append(PlugIn(name, module, **kw)) 
    6972 
     
    99102    debug information about the loading process.  If it is any other true value, 
    100103    this debug information is written to stdout (This behavior is deprecated). 
    101      
     104 
    102105    @type showProgress: C{None} or a callable taking one argument. 
    103106    @param showProgress: If not None, this is invoked with floating point 
    104     values between 0 and 1 describing the progress of the loading process.  
     107    values between 0 and 1 describing the progress of the loading process. 
    105108    If it is any other true value, this progress information is written to 
    106109    stdout.  (This behavior is deprecated). 
     
    127130    loaded = {} 
    128131    seenNames = {} 
    129      
     132 
    130133    # XXX Some people claim to have found non-strings in sys.path (an empty 
    131134    # list, in particular).  Instead of tracking down the cause for their 
     
    133136    # without further investigation.  At some point, someone should track 
    134137    # down where non-strings are coming from and do something about them. 
    135     paths = [cacheTransform(p) for p in sys.path  
     138    paths = [cacheTransform(p) for p in sys.path 
    136139             if isinstance(p, str) and os.path.isdir(p)] 
    137140 
     
    194197    against the C{type} argument to the C{register} function in the 
    195198    plugin.tml files. 
    196      
     199 
    197200    @type fileList: C{list} of C{str} 
    198201    @param fileList: A list of the files to attempt to load plugin 
    199202    information from.  One name is put in their scope, the C{register} 
    200203    function. 
    201      
     204 
    202205    @type debugInspection: C{None} or a callable taking one argument 
    203206    @param debugInspection: If not None, this is invoked with strings containing 
    204207    debug information about the loading process.  If it is any other true value, 
    205208    this debug information is written to stdout (This behavior is deprecated). 
    206      
     209 
    207210    @type showProgress: C{None} or a callable taking one argument. 
    208211    @param showProgress: If not None, this is invoked with floating point 
    209     values between 0 and 1 describing the progress of the loading process.  
     212    values between 0 and 1 describing the progress of the loading process. 
    210213    If it is any other true value, this progress information is written to 
    211214    stdout.  (This behavior is deprecated). 
     
    218221            "int parameter for debugInspection is deprecated, pass None or " 
    219222            "a function that takes a single argument instead.", 
    220             DeprecationWarning, 2 
     223            DeprecationWarning, 4 
    221224        ) 
    222225    if isinstance(showProgress, types.IntType): 
     
    224227            "int parameter for showProgress is deprecated, pass None or " 
    225228            "a function that takes a single argument instead.", 
    226             DeprecationWarning, 2 
     229            DeprecationWarning, 4 
    227230        ) 
    228231    result = [] 
    229232    debugInspection, showProgress = _prepCallbacks(debugInspection, showProgress) 
    230      
     233 
    231234    if not fileList: 
    232235        raise ValueError("No plugins passed to loadPlugins") 
     
    240243        pname = os.path.split(os.path.abspath(tmlFile))[-2] 
    241244        dropin = DropIn(pname) 
    242         ns = {'register': dropin.register} 
     245        ns = {'register': dropin.register, '__name__': tmlFile} 
    243246        try: 
    244247            execfile(tmlFile, ns) 
     
    247250            debugInspection("Error loading: %s" % e) 
    248251            continue 
    249          
     252 
    250253        ldp = len(dropin.plugins) or 1.0 
    251254        incr = increments * (1.0 / ldp) 
     
    266269def getPlugIns(plugInType, debugInspection=None, showProgress=None): 
    267270    """Helper function to get all the plugins of a particular type. 
    268      
     271 
    269272    @type plugInType: C{str} 
    270273    @param plugInType: The type of plugin to search for.  This is tested 
    271274    against the C{type} argument to the C{register} function in the 
    272275    plugin.tml files. 
    273      
     276 
    274277    @type debugInspection: C{None} or a callable taking one argument 
    275278    @param debugInspection: If not None, this is invoked with strings containing 
    276279    debug information about the loading process.  If it is any other true value, 
    277280    this debug information is written to stdout (This behavior is deprecated). 
    278      
     281 
    279282    @type showProgress: C{None} or a callable taking one argument. 
    280283    @param showProgress: If not None, this is invoked with floating point 
    281     values between 0 and 1 describing the progress of the loading process.  
     284    values between 0 and 1 describing the progress of the loading process. 
    282285    If it is any other true value, this progress information is written to 
    283286    stdout.  (This behavior is deprecated). 
     
    286289    @return: A list of C{PlugIn} objects that were found. 
    287290    """ 
     291    warnings.warn("The twisted.python.plugin system is deprecated.  " 
     292                  "See twisted.plugin for the revised edition.", 
     293                  DeprecationWarning, 2) 
     294    return _getPlugIns(plugInType, debugInspection, showProgress) 
     295 
     296def _getPlugIns(plugInType, debugInspection=None, showProgress=None): 
    288297    if isinstance(debugInspection, types.IntType): 
    289298        warnings.warn( 
    290299            "int parameter for debugInspection is deprecated, pass None or " 
    291300            "a function that takes a single argument instead.", 
    292             DeprecationWarning, 2 
     301            DeprecationWarning, 3 
    293302        ) 
    294303    if isinstance(showProgress, types.IntType): 
     
    296305            "int parameter for showProgress is deprecated, pass None or " 
    297306            "a function that takes a single argument instead.", 
    298             DeprecationWarning, 2 
     307            DeprecationWarning, 3 
    299308        ) 
    300309    debugInspection, showProgress = _prepCallbacks(debugInspection, showProgress) 
  • trunk/twisted/scripts/mktap.py

    r13136 r13168  
    1  
    21# Copyright (c) 2001-2004 Twisted Matrix Laboratories. 
    32# See LICENSE for details. 
    43 
    5 # 
     4import sys, os 
     5 
     6from zope.interface import Interface, Attribute, implements 
     7from twisted.python.components import backwardsCompatImplements 
     8 
    69from twisted.application import service, compat, app 
    710from twisted.persisted import sob 
    8 from twisted.python import usage, util, plugin 
    9 import sys, os 
     11from twisted.python import log, usage, util, plugin as oldplugin 
     12from twisted import plugin as newplugin 
     13 
     14class IServiceMaker(Interface): 
     15    name = Attribute( 
     16        "A brief string naming this TAP plugin, for example \"Mega Crusher 2000\".") 
     17 
     18    tapname = Attribute( 
     19        "A short string naming this TAP plugin, for example \"web\" or " 
     20        "\"pencil\".") 
     21 
     22    description = Attribute( 
     23        "A brief summary of the features provided by this TAP plugin.") 
     24 
     25    options = Attribute( 
     26        "A C{twisted.python.usage.Options} subclass defining the" 
     27        "configuration options for this application.") 
     28 
     29    def makeService(options): 
     30        """Create an object implementing C{twisted.application.service.IService} 
     31 
     32        Configure the object according to the specified options. 
     33 
     34        @param options: A mapping (typically a C{dict} or 
     35        C{twisted.python.usage.Options} instance) of configuration 
     36        options to desired configuration values. 
     37        """ 
     38 
    1039try: 
    1140    import pwd, grp 
     
    3362 
    3463def loadPlugins(debug = None, progress = None): 
    35     plugins = plugin.getPlugIns("tap", debug, progress) 
    3664    tapLookup = {} 
     65 
     66    plugins = oldplugin._getPlugIns("tap", debug, progress) 
    3767    for plug in plugins: 
    3868        if hasattr(plug, 'tapname'): 
     
    4171            shortTapName = plug.module.split('.')[-1] 
    4272        tapLookup[shortTapName] = plug 
     73 
     74    plugins = newplugin.getPlugIns(IServiceMaker) 
     75    for plug in plugins: 
     76        tapLookup[plug.tapname] = plug 
     77 
    4378    return tapLookup 
    4479 
     
    95130 
    96131    def init(self, tapLookup): 
    97         sc = [ [name, None, (lambda obj=module:obj.load().Options()), 
    98                 getattr(module, 'description', '')] 
    99                                      for name, module in tapLookup.items()] 
     132        sc = [] 
     133        for (name, module) in tapLookup.iteritems(): 
     134            if IServiceMaker.providedBy(module): 
     135                sc.append(( 
     136                    name, None, lambda m=module: m.options, module.description)) 
     137            else: 
     138                sc.append(( 
     139                    name, None, lambda obj=module: obj.load().Options(), 
     140                    getattr(module, 'description', ''))) 
     141 
    100142        sc.sort() 
    101143        self.subCommands = sc 
     
    148190    except KeyboardInterrupt: 
    149191        sys.exit(1) 
    150     ser = makeService(options.tapLookup[options.subCommand].load(), 
    151                       options.subCommand, 
    152                       options.subOptions) 
     192 
     193    plg = options.tapLookup[options.subCommand] 
     194    if not IServiceMaker.providedBy(plg): 
     195        plg = plg.load() 
     196    ser = makeService(plg, options.subCommand, options.subOptions) 
    153197    addToApplication(ser, 
    154198                     options.subCommand, options['append'], options['appname'], 
    155199                     options['type'], options['encrypted'], 
    156200                     *getid(options['uid'], options['gid'])) 
     201 
     202from twisted.python.reflect import namedAny 
     203from twisted.plugin import IPlugin 
     204 
     205class _tapHelper(object): 
     206    """ 
     207    Internal utility class to simplify the definition of \"new-style\" 
     208    mktap plugins based on existing, \"classic\" mktap plugins. 
     209    """ 
     210 
     211    implements(IPlugin, IServiceMaker) 
     212 
     213    def __init__(self, name, module, description, tapname): 
     214        self.name = name 
     215        self.module = module 
     216        self.description = description 
     217        self.tapname = tapname 
     218 
     219    def options(): 
     220        def get(self): 
     221            return namedAny(self.module).Options 
     222        return get, 
     223    options = property(*options()) 
     224 
     225    def makeService(): 
     226        def get(self): 
     227            return namedAny(self.module).makeService 
     228        return get, 
     229    makeService = property(*makeService()) 
     230backwardsCompatImplements(_tapHelper) 
  • trunk/twisted/scripts/trial.py

    r13118 r13168  
    1515 
    1616from twisted.application import app 
    17 from twisted.python import usage, reflect, failure, log, plugin 
     17from twisted.python import usage, reflect, failure, log 
     18from twisted import plugin 
    1819from twisted.python.util import spewer 
    1920from twisted.spread import jelly 
     
    124125    def _loadReporters(self): 
    125126        self.pluginFlags, self.optToQual = [], {} 
    126         self.plugins = plugin.getPlugIns("trial_reporter", None, None) 
     127        self.plugins = plugin.getPlugIns(itrial.IReporter) 
    127128        for p in self.plugins: 
    128129            self.pluginFlags.append([p.longOpt, p.shortOpt, p.description]) 
  • trunk/twisted/topfiles/setup.py

    r13126 r13168  
    9494 
    9595    # build stuff 
    96     packages=dist.getPackages('twisted', ignore=dist.twisted_subprojects), 
     96    packages=dist.getPackages('twisted', ignore=dist.twisted_subprojects + ['plugins']), 
     97    plugins=['__init__', 'notestplugin', 'testplugin', 'twisted_ftp', 'twisted_inet', 
     98             'twisted_manhole', 'twisted_portforward', 'twisted_socks', 'twisted_telnet', 
     99             'twisted_trial'], 
    97100    data_files=dist.getDataFiles('twisted', ignore=dist.twisted_subprojects), 
    98101    detectExtensions=detectExtensions, 
  • trunk/twisted/words/botbot.py

    r2860 r13168  
    55# Twisted Imports 
    66from twisted.words.service import WordsClient 
    7 from twisted.python.plugin import getPlugIns 
    87from twisted.python.failure import Failure 
    9 from twisted.python import log 
     8from twisted.python import log, plugin as oldplugin 
     9from twisted import plugin as newplugin 
     10 
     11from zope.interface import Interface 
     12 
     13class IBotBot(Interface): 
     14    def createBot(): 
     15        """Create a bot... bot. 
     16 
     17        No one uses this code, who cares what this method does. 
     18        """ 
    1019 
    1120class BotBot(WordsClient): 
     
    4857 
    4958    def loadBotList(self): 
    50         botTypeList = getPlugIns("twisted.words.bot") 
    5159        botTypes = {} 
     60 
     61        botTypeList = newplugin.getPlugIns(IBotBot) 
    5262        for bott in botTypeList: 
    5363            botTypes[bott.botType] = bott 
     64 
     65        botTypeList = oldplugin.getPlugIns("twisted.words.bot") 
     66        for bott in botTypeList: 
     67            botTypes[bott.botType] = bott.load() 
     68 
    5469        self.botTypes = botTypes 
    5570 
     
    7590    def bot_new(self, sender, message, metadata): 
    7691        bottype, botname = string.split(message, ' ', 1) 
    77         self.voice.service.addBot(botname, self.botTypes[bottype].load().createBot()) 
     92        self.voice.service.addBot(botname, self.botTypes[bottype].createBot()) 
    7893        self.voice.directMessage(sender, "Bot Created!") 
    7994