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
24 __title__ = 'Device Information Utility'
26 __doc__ = "Query a printer for static model information, dynamic status information, and CUPS printer queue settings."
36 from base import device, status, utils, tui, module
42 devid_mode = '--id' in sys.argv # hack
47 mod = module.Module(__mod__, __title__, __version__, __doc__, None,
48 (INTERACTIVE_MODE, GUI_MODE), (UI_TOOLKIT_QT4,),
51 mod.setUsage(module.USAGE_FLAG_DEVICE_ARGS,
52 extra_options=[("Device ID mode:", "--id (prints device ID only and exits.) (interactive (-i) mode only.)", "option", False),
53 ("Allow device URIs of uninstalled printers:", "-x (interactive (-i) mode only.)", "option", False)
55 see_also_list=['hp-toolbox'])
57 opts, device_uri, printer_name, mode, ui_toolkit, lang = \
58 mod.parseStdOpts('x', ['id'])
67 mode = NON_INTERACTIVE_MODE
70 if not utils.canEnterGUIMode4():
71 log.error("%s -u/--gui requires Qt4 GUI support. Entering interactive mode." % __mod__)
72 mode = INTERACTIVE_MODE
77 device_uri = mod.getDeviceUri(device_uri, printer_name, restrict_to_installed_devices=restrict)
79 if mode in (INTERACTIVE_MODE, NON_INTERACTIVE_MODE):
81 d = device.Device(device_uri, printer_name)
83 log.error("Unexpected error. Exiting.")
88 log.info(log.bold(d.device_uri))
96 log.error("Error opening device (%s)." % e.msg)
100 formatter = utils.TextFormatter(
102 {'width': 28, 'margin' : 2},
103 {'width': 58, 'margin' : 2},
110 print(d.dq['deviceid'])
113 log.error("Device ID not available.")
115 dq_keys = d.dq.keys()
118 log.info(log.bold("Device Parameters (dynamic data):"))
119 log.info(log.bold(formatter.compose(("Parameter", "Value(s)"))))
120 log.info(formatter.compose(('-'*28, '-'*58)))
123 log.info(formatter.compose((key, str(d.dq[key]))))
125 log.info(log.bold("\nModel Parameters (static data):"))
126 log.info(log.bold(formatter.compose(("Parameter", "Value(s)"))))
127 log.info(formatter.compose(('-'*28, '-'*58)))
129 mq_keys = d.mq.keys()
133 log.info(formatter.compose((key, str(d.mq[key]))))
136 formatter = utils.TextFormatter(
138 {'width': 20, 'margin' : 2}, # date/time
139 {'width': 5, 'margin' : 2}, # code
140 {'width': 40, 'margin' : 2}, # desc
141 {'width': 8, 'margin' : 2}, # user
142 {'width': 8, 'margin' : 2}, # job id
146 log.info(log.bold("\nStatus History (most recent first):"))
147 log.info(log.bold(formatter.compose(("Date/Time", "Code", "Status Description", "User", "Job ID"))))
148 log.info(formatter.compose(('-'*20, '-'*5, '-'*40, '-'*8, '-'*8)))
150 hq = d.queryHistory()
153 desc = device.queryString(h.event_code)
154 log.info(formatter.compose((time.strftime("%x %H:%M:%S", time.localtime(h.timedate)),
155 str(h.event_code), desc, h.username, str(h.job_id))))
163 from PyQt4.QtGui import QApplication
164 from ui4.infodialog import InfoDialog
166 log.error("Unable to load Qt4 support. Is it installed?")
170 app = QApplication(sys.argv)
172 dlg = InfoDialog(None, device_uri)
175 log.debug("Starting GUI loop...")
177 except KeyboardInterrupt:
181 except KeyboardInterrupt:
182 log.error("User exit")