home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_1873 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  20.8 KB  |  519 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. __docformat__ = 'restructuredtext en'
  5. from new import instancemethod
  6. from types import FunctionType
  7. from twisted.application import service
  8. from twisted.internet import defer, reactor
  9. from twisted.python import log, components, failure
  10. from zope.interface import Interface, implements, Attribute
  11. from IPython.tools import growl
  12. from IPython.kernel.util import printer
  13. from IPython.kernel.twistedutil import gatherBoth
  14. from IPython.kernel import map as Map
  15. from IPython.kernel import error
  16. from IPython.kernel.pendingdeferred import PendingDeferredManager, two_phase
  17. from IPython.kernel.controllerservice import ControllerAdapterBase, ControllerService, IControllerBase
  18.  
  19. class IEngineMultiplexer(Interface):
  20.     
  21.     def execute(lines, targets = 'all'):
  22.         pass
  23.  
  24.     
  25.     def push(namespace, targets = 'all'):
  26.         pass
  27.  
  28.     
  29.     def pull(keys, targets = 'all'):
  30.         pass
  31.  
  32.     
  33.     def push_function(namespace, targets = 'all'):
  34.         pass
  35.  
  36.     
  37.     def pull_function(keys, targets = 'all'):
  38.         pass
  39.  
  40.     
  41.     def get_result(i = None, targets = 'all'):
  42.         pass
  43.  
  44.     
  45.     def reset(targets = 'all'):
  46.         pass
  47.  
  48.     
  49.     def keys(targets = 'all'):
  50.         pass
  51.  
  52.     
  53.     def kill(controller = False, targets = 'all'):
  54.         pass
  55.  
  56.     
  57.     def push_serialized(namespace, targets = 'all'):
  58.         pass
  59.  
  60.     
  61.     def pull_serialized(keys, targets = 'all'):
  62.         pass
  63.  
  64.     
  65.     def clear_queue(targets = 'all'):
  66.         pass
  67.  
  68.     
  69.     def queue_status(targets = 'all'):
  70.         pass
  71.  
  72.     
  73.     def set_properties(properties, targets = 'all'):
  74.         pass
  75.  
  76.     
  77.     def get_properties(keys = None, targets = 'all'):
  78.         pass
  79.  
  80.     
  81.     def del_properties(keys, targets = 'all'):
  82.         pass
  83.  
  84.     
  85.     def has_properties(keys, targets = 'all'):
  86.         pass
  87.  
  88.     
  89.     def clear_properties(targets = 'all'):
  90.         pass
  91.  
  92.  
  93.  
  94. class IMultiEngine(IEngineMultiplexer):
  95.     
  96.     def get_ids():
  97.         pass
  98.  
  99.  
  100.  
  101. class MultiEngine(ControllerAdapterBase):
  102.     implements(IMultiEngine)
  103.     
  104.     def __init(self, controller):
  105.         ControllerAdapterBase.__init__(self, controller)
  106.  
  107.     
  108.     def engineList(self, targets):
  109.         if isinstance(targets, int):
  110.             if targets not in self.engines.keys():
  111.                 log.msg('Engine with id %i is not registered' % targets)
  112.                 raise error.InvalidEngineID('Engine with id %i is not registered' % targets)
  113.             targets not in self.engines.keys()
  114.             return [
  115.                 self.engines[targets]]
  116.         isinstance(targets, int)
  117.         if isinstance(targets, (list, tuple)):
  118.             for id in targets:
  119.                 if id not in self.engines.keys():
  120.                     log.msg('Engine with id %r is not registered' % id)
  121.                     raise error.InvalidEngineID('Engine with id %r is not registered' % id)
  122.                 id not in self.engines.keys()
  123.             
  124.             return map(self.engines.get, targets)
  125.         if targets == 'all':
  126.             eList = self.engines.values()
  127.             if len(eList) == 0:
  128.                 msg = 'There are no engines registered.\n                     Check the logs in ~/.ipython/log if you think there should have been.'
  129.                 raise error.NoEnginesRegistered(msg)
  130.             len(eList) == 0
  131.             return eList
  132.         targets == 'all'
  133.         raise error.InvalidEngineID("targets argument is not an int, list of ints or 'all': %r" % targets)
  134.  
  135.     
  136.     def _performOnEngines(self, methodName, *args, **kwargs):
  137.         targets = kwargs.pop('targets')
  138.         log.msg('Performing %s on %r' % (methodName, targets))
  139.         engines = self.engineList(targets)
  140.         dList = []
  141.         for e in engines:
  142.             meth = getattr(e, methodName, None)
  143.             if meth is not None:
  144.                 dList.append(meth(*args, **kwargs))
  145.                 continue
  146.             raise AttributeError('Engine %i does not have method %s' % (e.id, methodName))
  147.         
  148.         return dList
  149.  
  150.     
  151.     def _performOnEnginesAndGatherBoth(self, methodName, *args, **kwargs):
  152.         
  153.         try:
  154.             dList = self._performOnEngines(methodName, *args, **kwargs)
  155.         except (error.InvalidEngineID, AttributeError, KeyError, error.NoEnginesRegistered):
  156.             return defer.fail(failure.Failure())
  157.  
  158.         d = gatherBoth(dList, fireOnOneErrback = 0, consumeErrors = 1, logErrors = 0)
  159.         d.addCallback(error.collect_exceptions, methodName)
  160.         return d
  161.  
  162.     
  163.     def get_ids(self):
  164.         return defer.succeed(self.engines.keys())
  165.  
  166.     
  167.     def execute(self, lines, targets = 'all'):
  168.         return self._performOnEnginesAndGatherBoth('execute', lines, targets = targets)
  169.  
  170.     
  171.     def push(self, ns, targets = 'all'):
  172.         return self._performOnEnginesAndGatherBoth('push', ns, targets = targets)
  173.  
  174.     
  175.     def pull(self, keys, targets = 'all'):
  176.         return self._performOnEnginesAndGatherBoth('pull', keys, targets = targets)
  177.  
  178.     
  179.     def push_function(self, ns, targets = 'all'):
  180.         return self._performOnEnginesAndGatherBoth('push_function', ns, targets = targets)
  181.  
  182.     
  183.     def pull_function(self, keys, targets = 'all'):
  184.         return self._performOnEnginesAndGatherBoth('pull_function', keys, targets = targets)
  185.  
  186.     
  187.     def get_result(self, i = None, targets = 'all'):
  188.         return self._performOnEnginesAndGatherBoth('get_result', i, targets = targets)
  189.  
  190.     
  191.     def reset(self, targets = 'all'):
  192.         return self._performOnEnginesAndGatherBoth('reset', targets = targets)
  193.  
  194.     
  195.     def keys(self, targets = 'all'):
  196.         return self._performOnEnginesAndGatherBoth('keys', targets = targets)
  197.  
  198.     
  199.     def kill(self, controller = False, targets = 'all'):
  200.         if controller:
  201.             targets = 'all'
  202.         
  203.         d = self._performOnEnginesAndGatherBoth('kill', targets = targets)
  204.         if controller:
  205.             log.msg('Killing controller')
  206.             d.addCallback((lambda _: reactor.callLater(2, reactor.stop)))
  207.             d.addBoth((lambda _: pass))
  208.         
  209.         return d
  210.  
  211.     
  212.     def push_serialized(self, namespace, targets = 'all'):
  213.         for k, v in namespace.iteritems():
  214.             log.msg('Pushed object %s is %f MB' % (k, v.getDataSize()))
  215.         
  216.         d = self._performOnEnginesAndGatherBoth('push_serialized', namespace, targets = targets)
  217.         return d
  218.  
  219.     
  220.     def pull_serialized(self, keys, targets = 'all'):
  221.         
  222.         try:
  223.             dList = self._performOnEngines('pull_serialized', keys, targets = targets)
  224.         except (error.InvalidEngineID, AttributeError, error.NoEnginesRegistered):
  225.             return defer.fail(failure.Failure())
  226.  
  227.         for d in dList:
  228.             d.addCallback(self._logSizes)
  229.         
  230.         d = gatherBoth(dList, fireOnOneErrback = 0, consumeErrors = 1, logErrors = 0)
  231.         d.addCallback(error.collect_exceptions, 'pull_serialized')
  232.         return d
  233.  
  234.     
  235.     def _logSizes(self, listOfSerialized):
  236.         if isinstance(listOfSerialized, (list, tuple)):
  237.             for s in listOfSerialized:
  238.                 log.msg('Pulled object is %f MB' % s.getDataSize())
  239.             
  240.         else:
  241.             log.msg('Pulled object is %f MB' % listOfSerialized.getDataSize())
  242.         return listOfSerialized
  243.  
  244.     
  245.     def clear_queue(self, targets = 'all'):
  246.         return self._performOnEnginesAndGatherBoth('clear_queue', targets = targets)
  247.  
  248.     
  249.     def queue_status(self, targets = 'all'):
  250.         log.msg('Getting queue status on %r' % targets)
  251.         
  252.         try:
  253.             engines = self.engineList(targets)
  254.         except (error.InvalidEngineID, AttributeError, error.NoEnginesRegistered):
  255.             return defer.fail(failure.Failure())
  256.  
  257.         dList = []
  258.         for None in engines:
  259.             e = None
  260.         
  261.         d = gatherBoth(dList, fireOnOneErrback = 0, consumeErrors = 1, logErrors = 0)
  262.         d.addCallback(error.collect_exceptions, 'queue_status')
  263.         return d
  264.  
  265.     
  266.     def get_properties(self, keys = None, targets = 'all'):
  267.         log.msg('Getting properties on %r' % targets)
  268.         
  269.         try:
  270.             engines = self.engineList(targets)
  271.         except (error.InvalidEngineID, AttributeError, error.NoEnginesRegistered):
  272.             return defer.fail(failure.Failure())
  273.  
  274.         dList = [ e.get_properties(keys) for e in engines ]
  275.         d = gatherBoth(dList, fireOnOneErrback = 0, consumeErrors = 1, logErrors = 0)
  276.         d.addCallback(error.collect_exceptions, 'get_properties')
  277.         return d
  278.  
  279.     
  280.     def set_properties(self, properties, targets = 'all'):
  281.         log.msg('Setting properties on %r' % targets)
  282.         
  283.         try:
  284.             engines = self.engineList(targets)
  285.         except (error.InvalidEngineID, AttributeError, error.NoEnginesRegistered):
  286.             return defer.fail(failure.Failure())
  287.  
  288.         dList = [ e.set_properties(properties) for e in engines ]
  289.         d = gatherBoth(dList, fireOnOneErrback = 0, consumeErrors = 1, logErrors = 0)
  290.         d.addCallback(error.collect_exceptions, 'set_properties')
  291.         return d
  292.  
  293.     
  294.     def has_properties(self, keys, targets = 'all'):
  295.         log.msg('Checking properties on %r' % targets)
  296.         
  297.         try:
  298.             engines = self.engineList(targets)
  299.         except (error.InvalidEngineID, AttributeError, error.NoEnginesRegistered):
  300.             return defer.fail(failure.Failure())
  301.  
  302.         dList = [ e.has_properties(keys) for e in engines ]
  303.         d = gatherBoth(dList, fireOnOneErrback = 0, consumeErrors = 1, logErrors = 0)
  304.         d.addCallback(error.collect_exceptions, 'has_properties')
  305.         return d
  306.  
  307.     
  308.     def del_properties(self, keys, targets = 'all'):
  309.         log.msg('Deleting properties on %r' % targets)
  310.         
  311.         try:
  312.             engines = self.engineList(targets)
  313.         except (error.InvalidEngineID, AttributeError, error.NoEnginesRegistered):
  314.             return defer.fail(failure.Failure())
  315.  
  316.         dList = [ e.del_properties(keys) for e in engines ]
  317.         d = gatherBoth(dList, fireOnOneErrback = 0, consumeErrors = 1, logErrors = 0)
  318.         d.addCallback(error.collect_exceptions, 'del_properties')
  319.         return d
  320.  
  321.     
  322.     def clear_properties(self, targets = 'all'):
  323.         log.msg('Clearing properties on %r' % targets)
  324.         
  325.         try:
  326.             engines = self.engineList(targets)
  327.         except (error.InvalidEngineID, AttributeError, error.NoEnginesRegistered):
  328.             return defer.fail(failure.Failure())
  329.  
  330.         dList = [ e.clear_properties() for e in engines ]
  331.         d = gatherBoth(dList, fireOnOneErrback = 0, consumeErrors = 1, logErrors = 0)
  332.         d.addCallback(error.collect_exceptions, 'clear_properties')
  333.         return d
  334.  
  335.  
  336. components.registerAdapter(MultiEngine, IControllerBase, IMultiEngine)
  337.  
  338. class ISynchronousEngineMultiplexer(Interface):
  339.     pass
  340.  
  341.  
  342. class ISynchronousMultiEngine(ISynchronousEngineMultiplexer):
  343.     
  344.     def get_pending_deferred(deferredID, block = True):
  345.         pass
  346.  
  347.     
  348.     def clear_pending_deferreds():
  349.         pass
  350.  
  351.  
  352.  
  353. class SynchronousMultiEngine(PendingDeferredManager):
  354.     implements(ISynchronousMultiEngine)
  355.     
  356.     def __init__(self, multiengine):
  357.         self.multiengine = multiengine
  358.         PendingDeferredManager.__init__(self)
  359.  
  360.     
  361.     def execute(self, lines, targets = 'all'):
  362.         d = self.multiengine.execute(lines, targets)
  363.         return d
  364.  
  365.     execute = two_phase(execute)
  366.     
  367.     def push(self, namespace, targets = 'all'):
  368.         return self.multiengine.push(namespace, targets)
  369.  
  370.     push = two_phase(push)
  371.     
  372.     def pull(self, keys, targets = 'all'):
  373.         d = self.multiengine.pull(keys, targets)
  374.         return d
  375.  
  376.     pull = two_phase(pull)
  377.     
  378.     def push_function(self, namespace, targets = 'all'):
  379.         return self.multiengine.push_function(namespace, targets)
  380.  
  381.     push_function = two_phase(push_function)
  382.     
  383.     def pull_function(self, keys, targets = 'all'):
  384.         d = self.multiengine.pull_function(keys, targets)
  385.         return d
  386.  
  387.     pull_function = two_phase(pull_function)
  388.     
  389.     def get_result(self, i = None, targets = 'all'):
  390.         return self.multiengine.get_result(i, targets = 'all')
  391.  
  392.     get_result = two_phase(get_result)
  393.     
  394.     def reset(self, targets = 'all'):
  395.         return self.multiengine.reset(targets)
  396.  
  397.     reset = two_phase(reset)
  398.     
  399.     def keys(self, targets = 'all'):
  400.         return self.multiengine.keys(targets)
  401.  
  402.     keys = two_phase(keys)
  403.     
  404.     def kill(self, controller = False, targets = 'all'):
  405.         return self.multiengine.kill(controller, targets)
  406.  
  407.     kill = two_phase(kill)
  408.     
  409.     def push_serialized(self, namespace, targets = 'all'):
  410.         return self.multiengine.push_serialized(namespace, targets)
  411.  
  412.     push_serialized = two_phase(push_serialized)
  413.     
  414.     def pull_serialized(self, keys, targets = 'all'):
  415.         return self.multiengine.pull_serialized(keys, targets)
  416.  
  417.     pull_serialized = two_phase(pull_serialized)
  418.     
  419.     def clear_queue(self, targets = 'all'):
  420.         return self.multiengine.clear_queue(targets)
  421.  
  422.     clear_queue = two_phase(clear_queue)
  423.     
  424.     def queue_status(self, targets = 'all'):
  425.         return self.multiengine.queue_status(targets)
  426.  
  427.     queue_status = two_phase(queue_status)
  428.     
  429.     def set_properties(self, properties, targets = 'all'):
  430.         return self.multiengine.set_properties(properties, targets)
  431.  
  432.     set_properties = two_phase(set_properties)
  433.     
  434.     def get_properties(self, keys = None, targets = 'all'):
  435.         return self.multiengine.get_properties(keys, targets)
  436.  
  437.     get_properties = two_phase(get_properties)
  438.     
  439.     def has_properties(self, keys, targets = 'all'):
  440.         return self.multiengine.has_properties(keys, targets)
  441.  
  442.     has_properties = two_phase(has_properties)
  443.     
  444.     def del_properties(self, keys, targets = 'all'):
  445.         return self.multiengine.del_properties(keys, targets)
  446.  
  447.     del_properties = two_phase(del_properties)
  448.     
  449.     def clear_properties(self, targets = 'all'):
  450.         return self.multiengine.clear_properties(targets)
  451.  
  452.     clear_properties = two_phase(clear_properties)
  453.     
  454.     def get_ids(self):
  455.         return self.multiengine.get_ids()
  456.  
  457.  
  458. components.registerAdapter(SynchronousMultiEngine, IMultiEngine, ISynchronousMultiEngine)
  459.  
  460. class IMultiEngineCoordinator(Interface):
  461.     
  462.     def scatter(key, seq, dist = 'b', flatten = False, targets = 'all'):
  463.         pass
  464.  
  465.     
  466.     def gather(key, dist = 'b', targets = 'all'):
  467.         pass
  468.  
  469.     
  470.     def raw_map(func, seqs, dist = 'b', targets = 'all'):
  471.         pass
  472.  
  473.  
  474.  
  475. class ISynchronousMultiEngineCoordinator(IMultiEngineCoordinator):
  476.     
  477.     def scatter(key, seq, dist = 'b', flatten = False, targets = 'all', block = True):
  478.         pass
  479.  
  480.     
  481.     def gather(key, dist = 'b', targets = 'all', block = True):
  482.         pass
  483.  
  484.     
  485.     def raw_map(func, seqs, dist = 'b', targets = 'all', block = True):
  486.         pass
  487.  
  488.  
  489.  
  490. class IMultiEngineExtras(Interface):
  491.     
  492.     def zip_pull(targets, keys):
  493.         pass
  494.  
  495.     
  496.     def run(targets, fname):
  497.         pass
  498.  
  499.  
  500.  
  501. class ISynchronousMultiEngineExtras(IMultiEngineExtras):
  502.     
  503.     def zip_pull(targets, keys, block = True):
  504.         pass
  505.  
  506.     
  507.     def run(targets, fname, block = True):
  508.         pass
  509.  
  510.  
  511.  
  512. class IFullMultiEngine(IMultiEngine, IMultiEngineCoordinator, IMultiEngineExtras):
  513.     pass
  514.  
  515.  
  516. class IFullSynchronousMultiEngine(ISynchronousMultiEngine, ISynchronousMultiEngineCoordinator, ISynchronousMultiEngineExtras):
  517.     pass
  518.  
  519.