home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / lib / hplip / firmware < prev    next >
Encoding:
Text File  |  2007-04-04  |  4.2 KB  |  168 lines

  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # (c) Copyright 2003-2007 Hewlett-Packard Development Company, L.P.
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 2 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the Free Software
  18. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  19. #
  20. # Author: Don Welch
  21. #
  22.  
  23. __version__ = '0.1'
  24. __title__ = 'Firmware Download Utility'
  25. __doc__ = "Download firmware to a device."
  26.  
  27. # Std Lib
  28. import sys, getopt, gzip
  29.  
  30. # Local
  31. from base.g import *
  32. from base import device, status, utils
  33. from prnt import cups
  34.  
  35. USAGE = [(__doc__, "", "name", True),
  36.          ("Usage: hp-firmware [PRINTER|DEVICE-URI] [OPTIONS]", "", "summary", True),
  37.          utils.USAGE_ARGS,
  38.          utils.USAGE_DEVICE,
  39.          utils.USAGE_PRINTER,
  40.          utils.USAGE_SPACE,
  41.          utils.USAGE_OPTIONS,
  42.          utils.USAGE_BUS1, utils.USAGE_BUS2,
  43.          utils.USAGE_LOGGING1, utils.USAGE_LOGGING2, utils.USAGE_LOGGING3,
  44.          utils.USAGE_HELP,
  45.          utils.USAGE_SPACE,
  46.          utils.USAGE_NOTES,
  47.          utils.USAGE_STD_NOTES1, utils.USAGE_STD_NOTES2, 
  48.          utils.USAGE_SEEALSO,
  49.          ("hp-toolbox", "", "seealso", False),
  50.  
  51.          ]
  52.  
  53. def usage(typ='text'):
  54.     if typ == 'text':
  55.         utils.log_title(__title__, __version__)
  56.  
  57.     utils.format_text(USAGE, typ, __title__, 'hp-info', __version__)
  58.     sys.exit(0)
  59.  
  60.  
  61. log.set_module('hp-info')
  62.  
  63.  
  64. try:
  65.     opts, args = getopt.getopt(sys.argv[1:], 'p:d:hl:b:g',
  66.         ['printer=', 'device=', 'help', 'help-rest', 'help-man', 
  67.          'help-desc', 'logging=', 'bus='])
  68.  
  69. except getopt.GetoptError:
  70.     usage()
  71.  
  72. printer_name = None
  73. device_uri = None
  74. log_level = logger.DEFAULT_LOG_LEVEL
  75. bus = "cups,par,usb"
  76.  
  77. if os.getenv("HPLIP_DEBUG"):
  78.     log.set_level('debug')
  79.  
  80. for o, a in opts:
  81.     if o in ('-h', '--help'):
  82.         usage()
  83.  
  84.     elif o == '--help-rest':
  85.         usage('rest')
  86.  
  87.     elif o == '--help-man':
  88.         usage('man')
  89.  
  90.     elif o == '--help-desc':
  91.         print __doc__,
  92.         sys.exit(0)
  93.  
  94.     elif o in ('-p', '--printer'):
  95.         if a.startswith('*'):
  96.             printer_name = cups.getDefault()
  97.             log.info("Using CUPS default printer: %s" % printer_name)
  98.             log.debug(printer_name)
  99.         else:
  100.             printer_name = a
  101.  
  102.     elif o in ('-d', '--device'):
  103.         device_uri = a
  104.  
  105.     elif o in ('-b', '--bus'):
  106.         bus = a.lower().strip()
  107.         if not device.validateBusList(bus):
  108.             usage()
  109.  
  110.     elif o in ('-l', '--logging'):
  111.         log_level = a.lower().strip()
  112.         if not log.set_level(log_level):
  113.             usage()
  114.  
  115.     elif o == '-g':
  116.         log.set_level('debug')
  117.  
  118.  
  119. if device_uri and printer_name:
  120.     log.error("You may not specify both a printer (-p) and a device (-d).")
  121.     usage()
  122.  
  123. utils.log_title(__title__, __version__)
  124.  
  125. if not device_uri and not printer_name:
  126.     try:
  127.         device_uri = device.getInteractiveDeviceURI(bus)
  128.         if device_uri is None:
  129.             sys.exit(1)
  130.     except Error:
  131.         log.error("Error occured during interactive mode. Exiting.")
  132.         sys.exit(1)
  133.  
  134. try:
  135.     d = device.Device(device_uri, printer_name)
  136. except Error:
  137.     log.error("Error opening device. Exiting.")
  138.     sys.exit(1)
  139.  
  140. if d.device_uri is None and printer_name:
  141.     log.error("Printer '%s' not found." % printer_name)
  142.     sys.exit(1)
  143.  
  144. if d.device_uri is None and device_uri:
  145.     log.error("Malformed/invalid device-uri: %s" % device_uri)
  146.     sys.exit(1)
  147.  
  148. user_cfg.last_used.device_uri = d.device_uri
  149.     
  150. try:
  151.     d.open()
  152.     d.queryModel()
  153. except Error, e:
  154.     log.error("Error opening device (%s). Exiting." % e.msg)
  155.     sys.exit(1)
  156.  
  157. fw_download = d.mq.get('fw-download', 0)
  158.  
  159. if fw_download:
  160.     if d.downloadFirmware():
  161.         log.info("Done.")
  162. else:
  163.     log.error("Device does not support or require firmware download.")
  164.  
  165.  
  166. d.close()
  167. sys.exit(0)
  168.