home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 February / maximum-cd-2011-02.iso / DiscContents / digsby_setup85.exe / lib / plugins / digsby_updater / UpdateProgress.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-11-24  |  9.9 KB  |  239 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. import sys
  5. import logging
  6. import peak.util.addons as addons
  7. import gui
  8. import hooks
  9. import util
  10. import common
  11. import common.filetransfer as FT
  12. log = logging.getLogger('d_updater.progress')
  13.  
  14. class UpdateStates(FT.FileTransferStates):
  15.     CHECKING_FILES = 'Checking files'
  16.     FAILED = 'Update failed'
  17.     TransferringStates = FT.FileTransferStates.TransferringStates | set((CHECKING_FILES,))
  18.     ErrorStates = FT.FileTransferStates.ErrorStates | set((FAILED,))
  19.     FailStates = ErrorStates | set((FT.FileTransferStates.CANCELLED_BY_YOU,))
  20.  
  21.  
  22. class UpdateProgress(addons.AddOn, FT.FileTransfer):
  23.     ATROPHY_TIME = sys.maxint
  24.     direction = 'incoming'
  25.     states = UpdateStates
  26.     autoshow = False
  27.     autoremove = True
  28.     autoremove_states = set((UpdateStates.CANCELLED_BY_YOU, UpdateStates.FINISHED))
  29.     use_serviceicon = False
  30.     
  31.     def icon(self):
  32.         return gui.skin.get('serviceicons.digsby')
  33.  
  34.     icon = property(icon)
  35.     
  36.     def setup(self):
  37.         FT.FileTransfer.__init__(self)
  38.         self.name = _('Digsby Update')
  39.         self.buddy = util.Storage(name = 'Digsby Servers', alias = 'Digsby Servers', serviceicon = self.icon)
  40.         self.xfer_display_strings[self.states.CHECKING_FILES] = self.xfer_display_strings[self.states.TRANSFERRING] = (lambda x, d: _('%s: %s of %s -- %s remain') % (x.state, x.completed, x.size, util.nicetimecount(x.ETA)))
  41.         log.info('UpdateProgress setup')
  42.  
  43.     
  44.     def on_file_check_start(self, updater):
  45.         log.debug('File check starting')
  46.         self.updater = updater
  47.         self.completed = 0
  48.         self.size = len(updater.unchecked_files)
  49.         self.state = self.states.CHECKING_FILES
  50.  
  51.     
  52.     def on_file_checked(self, file):
  53.         self._setcompleted(self.completed + 1)
  54.  
  55.     
  56.     def on_file_check_complete(self, updater):
  57.         log.debug('File check complete')
  58.         self.updater = updater
  59.         self.state = self.states.WAITING_FOR_YOU
  60.  
  61.     
  62.     def on_file_download_complete(self, file):
  63.         log.debug('File download completed: %r', file.path)
  64.         self._setcompleted(self.completed + 1)
  65.  
  66.     
  67.     def on_update_download_start(self, files_to_download):
  68.         log.debug('Update download start: %r', files_to_download)
  69.         self.size = len(self.updater.update_files)
  70.         self.updater = None
  71.         self.state = self.states.TRANSFERRING
  72.         self.bytecounts = []
  73.         self._bytes_per_sec = 0
  74.         self.completed = 0
  75.         self._starttime = None
  76.         self._done = False
  77.  
  78.     
  79.     def on_update_download_complete(self, downloaded_files):
  80.         log.debug('All files downloaded')
  81.         self.state = self.states.FINISHED
  82.  
  83.     
  84.     def on_update_failed(self):
  85.         log.debug('Update failed')
  86.         self.autoremove = False
  87.         self.state = self.states.FAILED
  88.         util.Timer((10,), (lambda : (setattr(self, 'autoremove', True), setattr(self, 'state', self.states.FINISHED)))).start()
  89.  
  90.     
  91.     def cancel(self):
  92.         hooks.notify('digsby.updater.cancel')
  93.  
  94.     
  95.     def allow_cancel(self):
  96.         return self.state not in self.states.FailStates | self.states.CompleteStates
  97.  
  98.     
  99.     def allow_remove(self):
  100.         return self.state in self.states.FailStates | self.states.CompleteStates
  101.  
  102.     
  103.     def allow_open(self):
  104.         return False
  105.  
  106.     
  107.     def allow_open_folder(self):
  108.         return False
  109.  
  110.     
  111.     def allow_save(self):
  112.         return False
  113.  
  114.     
  115.     def allow_save_as(self):
  116.         return False
  117.  
  118.     
  119.     def allow_reject(self):
  120.         return False
  121.  
  122.     
  123.     def on_cancel(self):
  124.         self.state = self.states.CANCELLED_BY_YOU
  125.  
  126.     
  127.     def get_bottom_links(self):
  128.         return []
  129.  
  130.     
  131.     def get_right_links(self):
  132.         return [
  133.             ('remove', _('Remove'), (lambda : pass), self.allow_remove),
  134.             ('slower', _('Slower'), self.slower, self.allow_slower),
  135.             ('faster', _('Faster!'), self.faster, self.allow_faster),
  136.             ('cancel', _('Cancel'), self.cancel, self.allow_cancel)]
  137.  
  138.     
  139.     def faster(self):
  140.         hooks.notify('digsby.updater.fast_mode.enable')
  141.  
  142.     
  143.     def slower(self):
  144.         hooks.notify('digsby.updater.fast_mode.disable')
  145.  
  146.     
  147.     def allow_slower(self):
  148.         if self.allow_cancel() and self.updater is not None:
  149.             pass
  150.         return self.updater.fast_mode
  151.  
  152.     
  153.     def allow_faster(self):
  154.         if self.allow_cancel() and self.updater is not None:
  155.             pass
  156.         return not (self.updater.fast_mode)
  157.  
  158.  
  159.  
  160. def up():
  161.     if not common.pref('digsby.updater.use_transfer_window', type = bool, default = False):
  162.         return None
  163.     p = common.profile()
  164.     up = UpdateProgress(p)
  165.     return up
  166.  
  167.  
  168. def _insert_up(up):
  169.     if up.updater is not None or up.state in up.states.TransferringStates:
  170.         p = common.profile()
  171.         if up not in p.xfers:
  172.             log.info('putting UpdateProgress in profile.xfers')
  173.             p.xfers.insert(0, up)
  174.         
  175.     
  176.  
  177.  
  178. def on_file_check_start(updater):
  179.     u = up()
  180.     if u is None:
  181.         return None
  182.     u.on_file_check_start(updater)
  183.     _insert_up(u)
  184.  
  185.  
  186. def on_file_checked(file):
  187.     u = up()
  188.     if u is None:
  189.         return None
  190.     u.on_file_checked(file)
  191.     _insert_up(u)
  192.  
  193.  
  194. def on_file_check_complete(updater):
  195.     u = up()
  196.     if u is None:
  197.         return None
  198.     u.on_file_check_complete(updater)
  199.     _insert_up(u)
  200.  
  201.  
  202. def on_file_download_complete(file):
  203.     u = up()
  204.     if u is None:
  205.         return None
  206.     u.on_file_download_complete(file)
  207.     _insert_up(u)
  208.  
  209.  
  210. def on_update_download_start(files_to_download):
  211.     u = up()
  212.     if u is None:
  213.         return None
  214.     u.on_update_download_start(files_to_download)
  215.     _insert_up(u)
  216.  
  217.  
  218. def on_update_download_complete(downloaded_files):
  219.     u = up()
  220.     if u is None:
  221.         return None
  222.     u.on_update_download_complete(downloaded_files)
  223.     _insert_up(u)
  224.  
  225.  
  226. def on_cancel_update():
  227.     u = up()
  228.     if u is None:
  229.         return None
  230.     u.on_cancel()
  231.  
  232.  
  233. def on_update_failed():
  234.     u = up()
  235.     if u is None:
  236.         return None
  237.     u.on_update_failed()
  238.  
  239.