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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. __docformat__ = 'restructuredtext en'
  5. import new
  6. from IPython.iplib import InteractiveShell
  7. from IPython.Shell import MTInteractiveShell
  8. from twisted.internet.defer import Deferred
  9. NO_ACTIVE_CONTROLLER = '\nError:  No Controller is activated\nUse activate() on a RemoteController object to activate it for magics.\n'
  10.  
  11. def magic_result(self, parameter_s = ''):
  12.     
  13.     try:
  14.         activeController = __IPYTHON__.activeController
  15.     except AttributeError:
  16.         print NO_ACTIVE_CONTROLLER
  17.  
  18.     
  19.     try:
  20.         index = int(parameter_s)
  21.     except:
  22.         index = None
  23.  
  24.     result = activeController.get_result(index)
  25.     return result
  26.  
  27.  
  28. def magic_px(self, parameter_s = ''):
  29.     
  30.     try:
  31.         activeController = __IPYTHON__.activeController
  32.     except AttributeError:
  33.         print NO_ACTIVE_CONTROLLER
  34.  
  35.     print 'Parallel execution on engines: %s' % activeController.targets
  36.     result = activeController.execute(parameter_s)
  37.     return result
  38.  
  39.  
  40. def pxrunsource(self, source, filename = '<input>', symbol = 'single'):
  41.     
  42.     try:
  43.         code = self.compile(source, filename, symbol)
  44.     except (OverflowError, SyntaxError, ValueError):
  45.         self.showsyntaxerror(filename)
  46.         return None
  47.  
  48.     if code is None:
  49.         return True
  50.     if '_ip.magic("%autopx' in source or '_ip.magic("autopx' in source:
  51.         _disable_autopx(self)
  52.         return False
  53.     
  54.     try:
  55.         result = self.activeController.execute(source)
  56.     except:
  57.         '_ip.magic("autopx' in source
  58.         code is None
  59.         self.showtraceback()
  60.  
  61.     print result.__repr__()
  62.     return False
  63.  
  64.  
  65. def magic_autopx(self, parameter_s = ''):
  66.     if hasattr(self, 'autopx'):
  67.         if self.autopx == True:
  68.             _disable_autopx(self)
  69.         else:
  70.             _enable_autopx(self)
  71.     else:
  72.         _enable_autopx(self)
  73.  
  74.  
  75. def _enable_autopx(self):
  76.     
  77.     try:
  78.         activeController = __IPYTHON__.activeController
  79.     except AttributeError:
  80.         print 'No active RemoteController found, use RemoteController.activate().'
  81.  
  82.     self._original_runsource = self.runsource
  83.     self.runsource = new.instancemethod(pxrunsource, self, self.__class__)
  84.     self.autopx = True
  85.     print 'Auto Parallel Enabled\nType %autopx to disable'
  86.  
  87.  
  88. def _disable_autopx(self):
  89.     if hasattr(self, 'autopx'):
  90.         if self.autopx == True:
  91.             self.runsource = self._original_runsource
  92.             self.autopx = False
  93.             print 'Auto Parallel Disabled'
  94.         
  95.     
  96.  
  97. InteractiveShell.magic_result = magic_result
  98. InteractiveShell.magic_px = magic_px
  99. InteractiveShell.magic_autopx = magic_autopx
  100. del magic_result
  101. del magic_px
  102. del magic_autopx
  103.