home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_1356 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  2.6 KB  |  69 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 time
  9. import os
  10. from threading import Thread
  11. from Queue import Empty
  12. from calibre.library.database2 import LibraryDatabase2
  13. from calibre.utils.ipc.server import Server
  14. from calibre.utils.ipc.job import ParallelJob
  15.  
  16. def move_library(from_, to, notification = (lambda x: x)):
  17.     time.sleep(1)
  18.     old = LibraryDatabase2(from_)
  19.     old.move_library_to(to, notification)
  20.     return True
  21.  
  22.  
  23. class MoveLibrary(Thread):
  24.     
  25.     def __init__(self, from_, to, count, result_queue):
  26.         Thread.__init__(self)
  27.         self.total = count
  28.         self.result_queue = result_queue
  29.         self.from_ = from_
  30.         self.to = to
  31.         self.count = 0
  32.         self.failed = False
  33.         self.details = None
  34.  
  35.     
  36.     def run(self):
  37.         job = ParallelJob('move_library', 'Move library from %s to %s' % (self.from_, self.to), (lambda x, y: x), args = [
  38.             self.from_,
  39.             self.to])
  40.         server = Server(pool_size = 1)
  41.         server.add_job(job)
  42.         while not job.is_finished:
  43.             time.sleep(0.2)
  44.             job.update(consume_notifications = False)
  45.             while True:
  46.                 
  47.                 try:
  48.                     title = job.notifications.get_nowait()[0]
  49.                     self.count += 1
  50.                     self.result_queue.put((float(self.count) / self.total, title))
  51.                 continue
  52.                 except Empty:
  53.                     break
  54.                     continue
  55.                 
  56.  
  57.                 None<EXCEPTION MATCH>Empty
  58.         job.update()
  59.         server.close()
  60.         if not job.result:
  61.             self.failed = True
  62.             self.details = job.details
  63.         
  64.         if os.path.exists(job.log_path):
  65.             os.remove(job.log_path)
  66.         
  67.  
  68.  
  69.