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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. from __future__ import with_statement
  5. __license__ = 'GPL v3'
  6. __copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
  7. __docformat__ = 'restructuredtext en'
  8. import os
  9. import cPickle
  10. import sys
  11. from multiprocessing.connection import Client
  12. from threading import Thread
  13. from Queue import Queue
  14. from contextlib import closing
  15. from binascii import unhexlify
  16. from calibre import prints
  17. PARALLEL_FUNCS = {
  18.     'lrfviewer': ('calibre.gui2.lrf_renderer.main', 'main', None),
  19.     'ebook-viewer': ('calibre.gui2.viewer.main', 'main', None),
  20.     'render_pages': ('calibre.ebooks.comic.input', 'render_pages', 'notification'),
  21.     'gui_convert': ('calibre.gui2.convert.gui_conversion', 'gui_convert', 'notification'),
  22.     'gui_catalog': ('calibre.gui2.convert.gui_conversion', 'gui_catalog', 'notification'),
  23.     'move_library': ('calibre.library.move', 'move_library', 'notification'),
  24.     'read_metadata': ('calibre.ebooks.metadata.worker', 'read_metadata_', 'notification'),
  25.     'read_pdf_metadata': ('calibre.utils.podofo.__init__', 'get_metadata_', None),
  26.     'write_pdf_metadata': ('calibre.utils.podofo.__init__', 'set_metadata_', None),
  27.     'save_book': ('calibre.ebooks.metadata.worker', 'save_book', 'notification') }
  28.  
  29. class Progress(Thread):
  30.     
  31.     def __init__(self, conn):
  32.         Thread.__init__(self)
  33.         self.daemon = True
  34.         self.conn = conn
  35.         self.queue = Queue()
  36.  
  37.     
  38.     def __call__(self, percent, msg = ''):
  39.         self.queue.put((percent, msg))
  40.  
  41.     
  42.     def run(self):
  43.         while True:
  44.             x = self.queue.get()
  45.             if x is None:
  46.                 break
  47.             
  48.             
  49.             try:
  50.                 self.conn.send(x)
  51.             continue
  52.             break
  53.             continue
  54.  
  55.  
  56.  
  57.  
  58. def get_func(name):
  59.     (module, func, notification) = PARALLEL_FUNCS[name]
  60.     module = __import__(module, fromlist = [
  61.         1])
  62.     func = getattr(module, func)
  63.     return (func, notification)
  64.  
  65.  
  66. def main():
  67.     isosx = isosx
  68.     import calibre.constants
  69.     if isosx and 'CALIBRE_WORKER_ADDRESS' not in os.environ:
  70.         gui_main = main
  71.         import calibre.gui2.main
  72.         return gui_main([
  73.             'calibre'])
  74.     address = cPickle.loads(unhexlify(os.environ['CALIBRE_WORKER_ADDRESS']))
  75.     key = unhexlify(os.environ['CALIBRE_WORKER_KEY'])
  76.     resultf = unhexlify(os.environ['CALIBRE_WORKER_RESULT'])
  77.     
  78.     try:
  79.         conn = _[1]
  80.         (name, args, kwargs, desc) = conn.recv()
  81.         (func, notification) = get_func(name)
  82.         notifier = Progress(conn)
  83.         if notification:
  84.             kwargs[notification] = notifier
  85.             notifier.start()
  86.         
  87.         result = func(*args, **kwargs)
  88.         if result is not None:
  89.             cPickle.dump(result, open(resultf, 'wb'), -1)
  90.         
  91.         notifier.queue.put(None)
  92.     finally:
  93.         pass
  94.  
  95.     sys.stdout.flush()
  96.     sys.stderr.flush()
  97.     return 0
  98.  
  99. if __name__ == '__main__':
  100.     sys.exit(main())
  101.  
  102.