home *** CD-ROM | disk | FTP | other *** search
/ Clickx 47 / Clickx 47.iso / assets / software / Miro_Installer.exe / Miro_Downloader.exe / dl_daemon / command.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2008-01-10  |  10.1 KB  |  274 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.5)
  3.  
  4. import time
  5. import random
  6. import socket
  7. import eventloop
  8. import logging
  9. DAEMONIC_THREAD_TIMEOUT = 2
  10.  
  11. class Command:
  12.     
  13.     def __init__(self, daemon, *args, **kws):
  14.         self.id = 'cmd%08d' % random.randint(0, 99999999)
  15.         self.orig = True
  16.         self.args = args
  17.         self.kws = kws
  18.         self.daemon = daemon
  19.  
  20.     
  21.     def setDaemon(self, daemon):
  22.         self.daemon = daemon
  23.  
  24.     
  25.     def send(self, callback = None):
  26.         if self.daemon.shutdown:
  27.             return None
  28.         
  29.         (None, eventloop.addIdle)((lambda : self.daemon.send(self, callback)), 'sending command %s' % repr(self))
  30.  
  31.     
  32.     def setReturnValue(self, ret):
  33.         self.orig = False
  34.         self.ret = ret
  35.  
  36.     
  37.     def getReturnValue(self):
  38.         return self.ret
  39.  
  40.     
  41.     def action(self):
  42.         logging.warning('no action defined for command %s', self.id)
  43.  
  44.     
  45.     def __getstate__(self):
  46.         out = {
  47.             'id': self.id,
  48.             'args': self.args,
  49.             'kws': self.kws,
  50.             'orig': self.orig }
  51.         
  52.         try:
  53.             out['ret'] = self.ret
  54.         except AttributeError:
  55.             pass
  56.  
  57.         return out
  58.  
  59.     
  60.     def __setstate__(self, data):
  61.         self.id = data['id']
  62.         self.kws = data['kws']
  63.         self.args = data['args']
  64.         self.orig = data['orig']
  65.         
  66.         try:
  67.             self.ret = data['ret']
  68.         except KeyError:
  69.             pass
  70.  
  71.  
  72.  
  73.  
  74. class FindHTTPAuthCommand(Command):
  75.     
  76.     def action(self):
  77.         import httpauth
  78.         id = self.args[0]
  79.         args = self.args[1:]
  80.         
  81.         def callback(authHeader):
  82.             c = GotHTTPAuthCommand(self.daemon, id, authHeader)
  83.             c.send()
  84.  
  85.         httpauth.findHTTPAuth(callback, *args)
  86.  
  87.  
  88.  
  89. class AskForHTTPAuthCommand(Command):
  90.     
  91.     def action(self):
  92.         import httpauth
  93.         id = self.args[0]
  94.         args = self.args[1:]
  95.         
  96.         def callback(authHeader):
  97.             c = GotHTTPAuthCommand(self.daemon, id, authHeader)
  98.             c.send()
  99.  
  100.         httpauth.askForHTTPAuth(callback, *args)
  101.  
  102.  
  103.  
  104. class UpdateDownloadStatus(Command):
  105.     
  106.     def action(self):
  107.         RemoteDownloader = RemoteDownloader
  108.         import downloader
  109.         return RemoteDownloader.updateStatus(*self.args, **self.kws)
  110.  
  111.  
  112.  
  113. class BatchUpdateDownloadStatus(Command):
  114.     
  115.     def action(self):
  116.         RemoteDownloader = RemoteDownloader
  117.         import downloader
  118.         for status in self.args[0]:
  119.             RemoteDownloader.updateStatus(status)
  120.         
  121.  
  122.  
  123.  
  124. class DownloaderErrorCommand(Command):
  125.     
  126.     def action(self):
  127.         import util
  128.         util.failed('In Downloader process', details = self.args[0])
  129.  
  130.  
  131.  
  132. class ShutDownResponseCommand(Command):
  133.     
  134.     def action(self):
  135.         self.daemon.shutdownResponse()
  136.  
  137.  
  138.  
  139. class InitialConfigCommand(Command):
  140.     
  141.     def action(self):
  142.         import config
  143.         download = download
  144.         import dl_daemon
  145.         config.setDictionary(*self.args, **self.kws)
  146.         download.configReceived()
  147.  
  148.  
  149.  
  150. class UpdateConfigCommand(Command):
  151.     
  152.     def action(self):
  153.         import config
  154.         config.updateDictionary(*self.args, **self.kws)
  155.  
  156.  
  157.  
  158. class StartNewDownloadCommand(Command):
  159.     
  160.     def action(self):
  161.         download = download
  162.         import dl_daemon
  163.         return download.startNewDownload(*self.args, **self.kws)
  164.  
  165.  
  166.  
  167. class StartDownloadCommand(Command):
  168.     
  169.     def action(self):
  170.         download = download
  171.         import dl_daemon
  172.         return download.startDownload(*self.args, **self.kws)
  173.  
  174.  
  175.  
  176. class PauseDownloadCommand(Command):
  177.     
  178.     def action(self):
  179.         download = download
  180.         import dl_daemon
  181.         return download.pauseDownload(*self.args, **self.kws)
  182.  
  183.  
  184.  
  185. class StopDownloadCommand(Command):
  186.     
  187.     def action(self):
  188.         download = download
  189.         import dl_daemon
  190.         return download.stopDownload(*self.args, **self.kws)
  191.  
  192.  
  193.  
  194. class StopUploadCommand(Command):
  195.     
  196.     def action(self):
  197.         download = download
  198.         import dl_daemon
  199.         return download.stopUpload(*self.args, **self.kws)
  200.  
  201.  
  202.  
  203. class GetDownloadStatusCommand(Command):
  204.     
  205.     def action(self):
  206.         download = download
  207.         import dl_daemon
  208.         return download.getDownloadStatus(*self.args, **self.kws)
  209.  
  210.  
  211.  
  212. class RestoreDownloaderCommand(Command):
  213.     
  214.     def action(self):
  215.         download = download
  216.         import dl_daemon
  217.         return download.restoreDownloader(*self.args, **self.kws)
  218.  
  219.  
  220.  
  221. class MigrateDownloadCommand(Command):
  222.     
  223.     def action(self):
  224.         download = download
  225.         import dl_daemon
  226.         return download.migrateDownload(*self.args, **self.kws)
  227.  
  228.  
  229.  
  230. class GotHTTPAuthCommand(Command):
  231.     
  232.     def action(self):
  233.         (id, authHeader) = self.args
  234.         import httpauth
  235.         httpauth.handleHTTPAuthResponse(id, authHeader)
  236.  
  237.  
  238.  
  239. class ShutDownCommand(Command):
  240.     
  241.     def response_sent(self):
  242.         import eventloop
  243.         eventloop.quit()
  244.         logging.info('Shutdown complete')
  245.  
  246.     
  247.     def action(self):
  248.         starttime = time.time()
  249.         download = download
  250.         import dl_daemon
  251.         download.shutDown()
  252.         import threading
  253.         eventloop.threadPoolQuit()
  254.         for thread in threading.enumerate():
  255.             if thread != threading.currentThread() and not thread.isDaemon():
  256.                 thread.join()
  257.                 continue
  258.         
  259.         endtime = starttime + DAEMONIC_THREAD_TIMEOUT
  260.         for thread in threading.enumerate():
  261.             if thread != threading.currentThread():
  262.                 timeout = endtime - time.time()
  263.                 if timeout <= 0:
  264.                     break
  265.                 
  266.                 thread.join(timeout)
  267.                 continue
  268.         
  269.         c = ShutDownResponseCommand(self.daemon)
  270.         c.send(callback = self.response_sent)
  271.         self.daemon.shutdown = True
  272.  
  273.  
  274.