2 # -*- coding: utf-8 -*-
4 # (c) Copyright 2003-2009 Hewlett-Packard Development Company, L.P.
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.
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.
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
20 # Author: Don Welch, Sarbeswar Meher
24 __title__ = 'Firmware Download Utility'
25 __mod__ = 'hp-firmware'
26 __doc__ = "Download firmware to a device that requires downloaded firmware to function. (Note: Most printers do not require the use of this utility)."
38 from base import device, status, utils, tui, module
43 mod = module.Module(__mod__, __title__, __version__, __doc__, None,
44 (INTERACTIVE_MODE, GUI_MODE, NON_INTERACTIVE_MODE),
45 (UI_TOOLKIT_QT4, UI_TOOLKIT_QT3), True, True)
47 mod.setUsage(module.USAGE_FLAG_DEVICE_ARGS,
49 ("Use USB IDs to specify printer:", "-s bbb:ddd, where bbb is the USB bus ID and ddd is the USB device ID. The ':' and all leading zeroes must be present.", "option", False),
50 ("Seconds to delay before download:", "-y<secs> or --delay=<secs> (float value, e.g. 0.5)", "option", False)],
51 see_also_list=['hp-plugin', 'hp-toolbox'])
53 opts, device_uri, printer_name, mode, ui_toolkit, lang = \
54 mod.parseStdOpts('y:s:', ['delay='])
68 usb_bus_id, usb_device_id = a.split(":", 1)
69 log.debug("USB bus ID: %s" % usb_bus_id)
70 log.debug("USB device ID: %s" % usb_device_id)
72 log.error("Invalid USB IDs: %s" % a)
75 if len(usb_bus_id) != 3 or len(usb_device_id) != 3:
76 log.error("Invalid USB IDs '%s'. Must be the format: bbb.ddd" % a)
80 mode = NON_INTERACTIVE_MODE
82 elif o in ('-y', '--delay'):
86 log.error("Invalid delay value. Must be numeric (float) value. Setting delay to 0.0")
89 mode = NON_INTERACTIVE_MODE
92 if ui_toolkit == 'qt4':
93 if not utils.canEnterGUIMode4():
94 log.error("%s -u/--gui requires Qt4 GUI support. Entering interactive mode." % __mod__)
95 mode = INTERACTIVE_MODE
97 elif ui_toolkit == 'qt3':
98 if not utils.canEnterGUIMode():
99 log.error("%s -u/--gui requires Qt3 GUI support. Entering interactive mode." % __mod__)
100 mode = INTERACTIVE_MODE
102 if mode in (GUI_MODE, INTERACTIVE_MODE):
106 if ui_toolkit == 'qt4':
108 from PyQt4.QtGui import QApplication
109 from ui4.firmwaredialog import FirmwareDialog
111 log.error("Unable to load Qt4 support. Is it installed?")
114 if ui_toolkit == 'qt3':
117 from ui.firmwaredialog import FirmwareDialog
119 log.error("Unable to load Qt3 support. Is it installed?")
125 device_uri = mod.getDeviceUri(device_uri, printer_name,
126 filter={'fw-download': (operator.gt, 0)})
129 app = QApplication(sys.argv)
131 dialog = FirmwareDialog(None, device_uri)
134 log.debug("Starting GUI loop...")
135 if ui_toolkit == 'qt4':
137 elif ui_toolkit == 'qt3':
139 except KeyboardInterrupt:
146 if usb_bus_node is not None:
147 log.debug("USB bus node: %s" % usb_bus_node)
148 device_uri, sane_uri, fax_uri = device.makeURI(usb_bus_node, 1)
151 log.error("Invalid USB Device ID or USB bus ID. No device found.")
155 device_uri = mod.getDeviceUri(device_uri, printer_name,
156 filter={'fw-download': (operator.gt, 0)})
159 d = device.Device(device_uri, printer_name)
161 log.error("Error opening device. Exiting.")
172 log.error("Error opening device (%s). Exiting." % e.msg)
175 fw_download = d.mq.get('fw-download', 0)
178 if d.downloadFirmware(usb_bus_id, usb_device_id):
184 log.error("Firmware download failed.")
188 log.error("Device %s does not support or require firmware download." % device_uri)
194 except KeyboardInterrupt:
195 log.error("User exit")