home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 October / maximum-cd-2011-10.iso / DiscContents / digsby_setup.exe / lib / plugins / digsby_updater / UpdateProgress.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2011-06-22  |  10.0 KB  |  245 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', icon = None)
  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.         
  46.         try:
  47.             self.buddy.icon = self.icon
  48.         except gui.skin.SkinException:
  49.             pass
  50.  
  51.         log.debug('File check starting')
  52.         self.updater = updater
  53.         self.completed = 0
  54.         self.size = len(updater.unchecked_files)
  55.         self.state = self.states.CHECKING_FILES
  56.  
  57.     
  58.     def on_file_checked(self, file):
  59.         self._setcompleted(self.completed + 1)
  60.  
  61.     
  62.     def on_file_check_complete(self, updater):
  63.         log.debug('File check complete')
  64.         self.updater = updater
  65.         self.state = self.states.WAITING_FOR_YOU
  66.  
  67.     
  68.     def on_file_download_complete(self, file):
  69.         log.debug('File download completed: %r', file.path)
  70.         self._setcompleted(self.completed + 1)
  71.  
  72.     
  73.     def on_update_download_start(self, files_to_download):
  74.         log.debug('Update download start: %r', files_to_download)
  75.         self.size = len(self.updater.update_files)
  76.         self.updater = None
  77.         self.state = self.states.TRANSFERRING
  78.         self.bytecounts = []
  79.         self._bytes_per_sec = 0
  80.         self.completed = 0
  81.         self._starttime = None
  82.         self._done = False
  83.  
  84.     
  85.     def on_update_download_complete(self, downloaded_files):
  86.         log.debug('All files downloaded')
  87.         self.state = self.states.FINISHED
  88.  
  89.     
  90.     def on_update_failed(self):
  91.         log.debug('Update failed')
  92.         self.autoremove = False
  93.         self.state = self.states.FAILED
  94.         util.Timer((10,), (lambda : (setattr(self, 'autoremove', True), setattr(self, 'state', self.states.FINISHED)))).start()
  95.  
  96.     
  97.     def cancel(self):
  98.         hooks.notify('digsby.updater.cancel')
  99.  
  100.     
  101.     def allow_cancel(self):
  102.         return self.state not in self.states.FailStates | self.states.CompleteStates
  103.  
  104.     
  105.     def allow_remove(self):
  106.         return self.state in self.states.FailStates | self.states.CompleteStates
  107.  
  108.     
  109.     def allow_open(self):
  110.         return False
  111.  
  112.     
  113.     def allow_open_folder(self):
  114.         return False
  115.  
  116.     
  117.     def allow_save(self):
  118.         return False
  119.  
  120.     
  121.     def allow_save_as(self):
  122.         return False
  123.  
  124.     
  125.     def allow_reject(self):
  126.         return False
  127.  
  128.     
  129.     def on_cancel(self):
  130.         self.state = self.states.CANCELLED_BY_YOU
  131.  
  132.     
  133.     def get_bottom_links(self):
  134.         return []
  135.  
  136.     
  137.     def get_right_links(self):
  138.         return [
  139.             ('remove', _('Remove'), (lambda : pass), self.allow_remove),
  140.             ('slower', _('Slower'), self.slower, self.allow_slower),
  141.             ('faster', _('Faster!'), self.faster, self.allow_faster),
  142.             ('cancel', _('Cancel'), self.cancel, self.allow_cancel)]
  143.  
  144.     
  145.     def faster(self):
  146.         hooks.notify('digsby.updater.fast_mode.enable')
  147.  
  148.     
  149.     def slower(self):
  150.         hooks.notify('digsby.updater.fast_mode.disable')
  151.  
  152.     
  153.     def allow_slower(self):
  154.         if self.allow_cancel() and self.updater is not None:
  155.             pass
  156.         return self.updater.fast_mode
  157.  
  158.     
  159.     def allow_faster(self):
  160.         if self.allow_cancel() and self.updater is not None:
  161.             pass
  162.         return not (self.updater.fast_mode)
  163.  
  164.  
  165.  
  166. def up():
  167.     if not common.pref('digsby.updater.use_transfer_window', type = bool, default = False):
  168.         return None
  169.     p = common.profile()
  170.     up = UpdateProgress(p)
  171.     return up
  172.  
  173.  
  174. def _insert_up(up):
  175.     if up.updater is not None or up.state in up.states.TransferringStates:
  176.         p = common.profile()
  177.         if up not in p.xfers:
  178.             log.info('putting UpdateProgress in profile.xfers')
  179.             p.xfers.insert(0, up)
  180.         
  181.     
  182.  
  183.  
  184. def on_file_check_start(updater):
  185.     u = up()
  186.     if u is None:
  187.         return None
  188.     u.on_file_check_start(updater)
  189.     _insert_up(u)
  190.  
  191.  
  192. def on_file_checked(file):
  193.     u = up()
  194.     if u is None:
  195.         return None
  196.     u.on_file_checked(file)
  197.     _insert_up(u)
  198.  
  199.  
  200. def on_file_check_complete(updater):
  201.     u = up()
  202.     if u is None:
  203.         return None
  204.     u.on_file_check_complete(updater)
  205.     _insert_up(u)
  206.  
  207.  
  208. def on_file_download_complete(file):
  209.     u = up()
  210.     if u is None:
  211.         return None
  212.     u.on_file_download_complete(file)
  213.     _insert_up(u)
  214.  
  215.  
  216. def on_update_download_start(files_to_download):
  217.     u = up()
  218.     if u is None:
  219.         return None
  220.     u.on_update_download_start(files_to_download)
  221.     _insert_up(u)
  222.  
  223.  
  224. def on_update_download_complete(downloaded_files):
  225.     u = up()
  226.     if u is None:
  227.         return None
  228.     u.on_update_download_complete(downloaded_files)
  229.     _insert_up(u)
  230.  
  231.  
  232. def on_cancel_update():
  233.     u = up()
  234.     if u is None:
  235.         return None
  236.     u.on_cancel()
  237.  
  238.  
  239. def on_update_failed():
  240.     u = up()
  241.     if u is None:
  242.         return None
  243.     u.on_update_failed()
  244.  
  245.