home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / hplip / plugin.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  9.6 KB  |  239 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. __version__ = '2.1'
  5. __mod__ = 'hp-plugin'
  6. __title__ = 'Plugin Download and Install Utility'
  7. __doc__ = ''
  8. import sys
  9. import getopt
  10. import time
  11. import os.path as os
  12. import re
  13. import os
  14. import gzip
  15. from base.g import *
  16. from base import device, utils, tui, module
  17. from prnt import cups
  18. pm = None
  19.  
  20. def plugin_download_callback(c, s, t):
  21.     pm.update(int(100 * c * s / t), utils.format_bytes(c * s))
  22.  
  23.  
  24. def plugin_install_callback(s):
  25.     print s
  26.  
  27. USAGE = [
  28.     (__doc__, '', 'name', True),
  29.     ('Usage: %s [MODE] [OPTIONS]' % __mod__, '', 'summary', True),
  30.     utils.USAGE_MODE,
  31.     utils.USAGE_GUI_MODE,
  32.     utils.USAGE_INTERACTIVE_MODE,
  33.     ('Installation for required printer mode:', '--required (Qt4 only)', 'option', False),
  34.     ('Installation for optional printer mode:', '--optional (Qt4 only)', 'option', False),
  35.     utils.USAGE_LANGUAGE,
  36.     utils.USAGE_OPTIONS,
  37.     ('Specify the path to the plugin file:', '-p <path> or --path=<path> or --plugin=<path>', 'option', False),
  38.     utils.USAGE_LOGGING1,
  39.     utils.USAGE_LOGGING2,
  40.     utils.USAGE_LOGGING3,
  41.     utils.USAGE_HELP,
  42.     utils.USAGE_SPACE,
  43.     utils.USAGE_SEEALSO,
  44.     ('hp-setup', '', 'seealso', False),
  45.     ('hp-firmware', '', 'seealso', False)]
  46. mod = module.Module(__mod__, __title__, __version__, __doc__, USAGE, (INTERACTIVE_MODE, GUI_MODE), (UI_TOOLKIT_QT3, UI_TOOLKIT_QT4), True)
  47. (opts, device_uri, printer_name, mode, ui_toolkit, loc) = mod.parseStdOpts('p:', [
  48.     'path=',
  49.     'plugin=',
  50.     'plug-in=',
  51.     'generic',
  52.     'optional',
  53.     'required'], handle_device_printer = False)
  54. plugin_path = None
  55. install_mode = PLUGIN_NONE
  56. for o, a in opts:
  57.     if o in ('-p', '--path', '--plugin', '--plug-in'):
  58.         plugin_path = os.path.normpath(os.path.abspath(os.path.expanduser(a)))
  59.         continue
  60.     if o == '--required':
  61.         install_mode = PLUGIN_REQUIRED
  62.         if ui_toolkit == 'qt3':
  63.             log.warn('--required switch ignored.')
  64.         
  65.     ui_toolkit == 'qt3'
  66.     if o == '--optional':
  67.         install_mode = PLUGIN_OPTIONAL
  68.         if ui_toolkit == 'qt3':
  69.             log.warn('--optional switch ignored.')
  70.         
  71.     ui_toolkit == 'qt3'
  72.  
  73. version = prop.installed_version
  74. plugin_filename = 'hplip-%s-plugin.run' % version
  75. if plugin_path is not None:
  76.     if not os.path.exists(plugin_path):
  77.         log.error("Plug-in path '%s' not found." % plugin_path)
  78.         sys.exit(1)
  79.     
  80.     if os.path.isdir(plugin_path):
  81.         plugin_path = os.path.join(plugin_path, 'hplip-%s-plugin.run' % version)
  82.         if not os.path.exists(plugin_path):
  83.             log.error("Plug-in path '%s' not found." % plugin_path)
  84.             sys.exit(1)
  85.         
  86.     
  87.     if os.path.basename(plugin_path) != plugin_filename:
  88.         log.error("Plug-in filename must be '%s'." % plugin_filename)
  89.         sys.exit(1)
  90.     
  91.     size = os.stat(plugin_path)[6]
  92.     checksum = ''
  93.     timestamp = 0
  94.     plugin_path = 'file://' + plugin_path
  95.     log.debug('Plugin path=%s (%d)' % (plugin_path, size))
  96.  
  97. if mode == GUI_MODE:
  98.     if ui_toolkit == 'qt3':
  99.         if not utils.canEnterGUIMode():
  100.             log.error('%s requires GUI support (try running with --qt4). Try using interactive (-i) mode.' % __mod__)
  101.             sys.exit(1)
  102.         
  103.     elif not utils.canEnterGUIMode4():
  104.         log.error('%s requires GUI support (try running with --qt3). Try using interactive (-i) mode.' % __mod__)
  105.         sys.exit(1)
  106.     
  107.  
  108. if mode == GUI_MODE:
  109.     pass
  110. None if ui_toolkit == 'qt3' else None<EXCEPTION MATCH>KeyboardInterrupt
  111.  
  112. try:
  113.     if not os.geteuid() == 0:
  114.         log.error('You must be root to run this utility.')
  115.         sys.exit(1)
  116.     
  117.     log.info("(Note: Defaults for each question are maked with a '*'. Press <enter> to accept the default.)")
  118.     log.info('')
  119.     from installer import core_install
  120.     core = core_install.CoreInstall()
  121.     core.set_plugin_version()
  122.     tui.header('PLUG-IN INSTALLATION FOR HPLIP %s' % version)
  123.     if core.check_for_plugin() and plugin_path is None:
  124.         log.info('The driver plugin for HPLIP %s appears to already be installed.' % version)
  125.         (cont, ans) = tui.enter_yes_no('Do you wish to download and re-install the plug-in?')
  126.         if not cont or not ans:
  127.             sys.exit(0)
  128.         
  129.     
  130.     if plugin_path is None:
  131.         table = tui.Formatter(header = ('Option', 'Description'), min_widths = (10, 50))
  132.         table.add(('d', 'Download plug-in from HP (recomended)'))
  133.         table.add(('p', 'Specify a path to the plug-in (advanced)'))
  134.         table.add(('q', 'Quit hp-plugin (skip installation)'))
  135.         table.output()
  136.         (cont, ans) = tui.enter_choice('\nEnter option (d=download*, p=specify path, q=quit) ? ', [
  137.             'd',
  138.             'p'], 'd')
  139.         if not cont:
  140.             sys.exit(0)
  141.         
  142.         if ans == 'd':
  143.             plugin_conf_url = core.get_plugin_conf_url()
  144.             if plugin_conf_url.startswith('file://'):
  145.                 tui.header('COPY CONFIGURATION')
  146.             else:
  147.                 tui.header('DOWNLOAD CONFIGURATION')
  148.                 log.info('Checking for network connection...')
  149.                 ok = core.check_network_connection()
  150.                 if not ok:
  151.                     log.error('Network connection not detected.')
  152.                     sys.exit(1)
  153.                 
  154.             log.info('Downloading configuration file from: %s' % plugin_conf_url)
  155.             pm = tui.ProgressMeter('Downloading configuration:')
  156.             (plugin_path, size, checksum, timestamp, ok) = core.get_plugin_info(plugin_conf_url, plugin_download_callback)
  157.             print 
  158.             if not plugin_path.startswith('http://') and not plugin_path.startswith('file://'):
  159.                 plugin_path = 'file://' + plugin_path
  160.             
  161.         else:
  162.             while True:
  163.                 plugin_path = raw_input(log.bold("Enter the path to the 'hplip-%s-plugin.run' file (q=quit) : " % version)).strip()
  164.                 if plugin_path.strip().lower() == 'q':
  165.                     sys.exit(1)
  166.                 
  167.                 if not plugin_path.startswith('http://'):
  168.                     plugin_path = os.path.normpath(os.path.abspath(os.path.expanduser(plugin_path)))
  169.                     if not os.path.exists(plugin_path):
  170.                         log.error("Plug-in path '%s' not found." % plugin_path)
  171.                         continue
  172.                     
  173.                     if os.path.isdir(plugin_path):
  174.                         plugin_path = os.path.join(plugin_path, plugin_filename)
  175.                         if not os.path.exists(plugin_path):
  176.                             log.error("Plug-in path '%s' not found." % plugin_path)
  177.                             continue
  178.                         
  179.                     
  180.                     if os.path.basename(plugin_path) != plugin_filename:
  181.                         log.error("Plug-in filename must be '%s'." % plugin_filename)
  182.                         continue
  183.                     
  184.                     size = os.stat(plugin_path)[6]
  185.                     checksum = ''
  186.                     timestamp = 0
  187.                     plugin_path = 'file://' + plugin_path
  188.                 
  189.                 break
  190.     
  191.     if plugin_path.startswith('file://'):
  192.         tui.header('COPY PLUGIN')
  193.     else:
  194.         tui.header('DOWNLOAD PLUGIN')
  195.         log.info('Checking for network connection...')
  196.         ok = core.check_network_connection()
  197.         if not ok:
  198.             log.error('Network connection not detected.')
  199.             sys.exit(1)
  200.         
  201.     log.info('Downloading plug-in from: %s' % plugin_path)
  202.     pm = tui.ProgressMeter('Downloading plug-in:')
  203.     (ok, local_plugin) = core.download_plugin(plugin_path, size, checksum, timestamp, plugin_download_callback)
  204.     print 
  205.     if not ok:
  206.         log.error('Plug-in download failed: %s' % local_plugin)
  207.         sys.exit(1)
  208.     
  209.     tui.header('INSTALLING PLUG-IN')
  210.     core.run_plugin(mode, plugin_install_callback)
  211.     cups_devices = device.getSupportedCUPSDevices([
  212.         'hp'])
  213.     title = False
  214.     for dev in cups_devices:
  215.         mq = device.queryModelByURI(dev)
  216.         if mq.get('fw-download', 0):
  217.             if not title:
  218.                 tui.header('DOWNLOADING FIRMWARE')
  219.                 title = True
  220.             
  221.             log.info(log.bold('\nDownloading firmware to device %s...' % dev))
  222.             
  223.             try:
  224.                 d = device.Device(dev)
  225.             except Error:
  226.                 log.error('Error opening device. Exiting.')
  227.                 sys.exit(1)
  228.  
  229.             if d.downloadFirmware():
  230.                 log.info('Firmware download successful.\n')
  231.             
  232.             d.close()
  233.             continue
  234. except KeyboardInterrupt:
  235.     log.error('User exit')
  236.  
  237. log.info('')
  238. log.info('Done.')
  239.