2
# -*- coding: utf-8 -*-
4
# (c) Copyright 2011-2014 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: Suma Byrappa, Amarnath Chitumalla
25
__title__ = 'AutoConfig Utility for Plug-in Installation'
26
__mod__ = 'hp-check-plugin'
27
__doc__ = "Auto config utility for HPLIP supported multifunction Devices for installing proprietary plug-ins."
40
from base import utils, device, tui, module, pkit
41
from installer import core_install
44
# Temp values for testing; May not be needed
48
LOG_FILE = "/var/log/hp/hplip_ac.log"
49
DBUS_SERVICE='com.hplip.StatusService'
53
# Send dbus event to hpssd on dbus system bus
54
def send_message(device_uri, printer_name, event_code, username, job_id, title, pipe_name=''):
55
log.debug("send_message() entered")
56
args = [device_uri, printer_name, event_code, username, job_id, title, pipe_name]
57
msg = lowlevel.SignalMessage('/', DBUS_SERVICE, 'Event')
58
msg.append(signature='ssisiss', *args)
60
SystemBus().send_message(msg)
61
log.debug("send_message() returning")
64
def install_Plugin(systray_running_status, run_directly=False):
66
if not utils.canEnterGUIMode4():
67
log.error("%s requires GUI support . Is Qt4 installed?" % __mod__)
71
from PyQt4.QtGui import QApplication, QMessageBox
72
from ui4.plugindiagnose import PluginDiagnose
73
from installer import core_install
75
log.error("Unable to load Qt4 support. Is it installed?")
78
app = QApplication(sys.argv)
79
plugin = PLUGIN_REQUIRED
80
plugin_reason = PLUGIN_REASON_NONE
81
ok, sudo_ok = pkit.run_plugin_command(plugin == PLUGIN_REQUIRED, plugin_reason)
82
if not ok or not sudo_ok:
83
log.error("Failed to install plug-in.")
84
elif systray_running_status:
85
send_message( device_uri, "", EVENT_AUTO_CONFIGURE, username, 0, "AutoConfig")
86
log.debug("Event EVENT_AUTO_CONFIGURE sent to hp-systray to invoke hp-plugin")
88
log.error("Run hp-systray manually and re-plugin printer")
89
#TBD: needs to run hp-plugin in silent mode. or needs to show error UI to user.
92
#Installs/Uploads the firmware to device once plugin installation is completed.
93
def install_firmware(Plugin_Installation_Completed, USB_param):
94
#timeout check for plugin installation
95
sleep_timeout = 6000 # 10 mins time out
96
while Plugin_Installation_Completed is False and sleep_timeout != 0:
97
time.sleep(0.3) #0.3 sec delay
98
sleep_timeout = sleep_timeout -3
100
ps_plugin,output = utils.Is_Process_Running('hp-plugin')
101
ps_diagnose_plugin,output = utils.Is_Process_Running('hp-diagnose_plugin')
103
if ps_plugin is False and ps_diagnose_plugin is False:
104
Plugin_Installation_Completed = True
105
if core.check_for_plugin() == PLUGIN_INSTALLED:
108
log.error("Failed to download firmware required files. manually run hp-plugin command in terminal fisrt")
113
if USB_param is not None:
114
options += " -y3 %s"%(USB_param)
115
if log_level is 'debug':
118
cmd= execmd + options
119
log.info("Starting Firmware installation.")
120
log.debug("Running command : %s " %cmd)
121
Status, out=utils.run(cmd)
124
# log.info("Installed firmware ")
126
# log.error("Failed to install firmware = %s" %Status)
130
USAGE = [(__doc__, "", "name", True),
131
("Usage: %s [OPTIONS] [USB bus:device]" % __mod__, "", "summary", True),
133
("Install Plug-in through HP System Tray:", "-m (Default)", "option", False),
134
("Install Plug-in through hp-plugin:", "-p", "option", False),
135
("Download firmware into the device:", "-f", "option", False),
137
utils.USAGE_LOGGING1, utils.USAGE_LOGGING2, utils.USAGE_LOGGING3,
138
utils.USAGE_EXAMPLES,
139
("Install plugin:", "$%s 001:002"%(__mod__), "example", False),
140
("Install plugin and firmware:", "$%s -f 001:002"%(__mod__), "example", False),
142
("-m and -p options can't be used together. ","","note",False),
146
def usage(typ='text'):
148
utils.log_title(__title__, __version__)
150
utils.format_text(USAGE, typ, __title__, __mod__, __version__)
158
from dbus import SystemBus, lowlevel
160
log.error("hp-check-plugin Tool requires dBus and python-dbus")
163
mod = module.Module(__mod__, __title__, __version__, __doc__, USAGE, (INTERACTIVE_MODE, GUI_MODE), (UI_TOOLKIT_QT3, UI_TOOLKIT_QT4), run_as_root_ok=True, quiet=True)
164
opts, device_uri, printer_name, mode, ui_toolkit, loc = \
165
mod.parseStdOpts('l:hHuUmMfFpPgG',['gui','help', 'help-rest', 'help-man', 'help-desc','logging='],handle_device_printer=False)
167
except getopt.GetoptError, e:
172
if os.getenv("HPLIP_DEBUG"):
173
log.set_level('debug')
176
Systray_Msg_Enabled = False
177
Plugin_option_Enabled = False
178
Firmware_Option_Enabled = False
180
Is_Plugin_Already_Installed = False
183
if o in ('-h','-H', '--help'):
186
elif o == '--help-rest':
189
elif o == '--help-man':
192
elif o in ('-u', '-U','--gui'):
193
# currenlty only GUI mode is supported. hence not reading this option
196
# elif o in ('-i', '-I', '--interactive'):
197
# #this is future use
200
elif o == '--help-desc':
204
elif o in ('-l', '--logging'):
205
log_level = a.lower().strip()
207
elif o in('-g', '-G'):
210
elif o in ('-m', '-M'):
211
Systray_Msg_Enabled = True
213
elif o in ('-p', '-P'):
214
Plugin_option_Enabled = True
216
elif o in ('-F','-f'):
217
Firmware_Option_Enabled = True
219
if not log.set_level (log_level):
227
LOG_FILE = os.path.normpath(LOG_FILE)
228
log.info(log.bold("Saving output in log file: %s" % LOG_FILE))
229
if os.path.exists(LOG_FILE):
232
log.set_logfile(LOG_FILE)
233
log.set_where(log.LOG_TO_CONSOLE_AND_FILE)
234
cmd="chmod 664 "+LOG_FILE
235
sts,output = utils.run(cmd)
237
log.warn("Failed to change log file permissions: %s" %output)
239
cmd="chgrp lp "+LOG_FILE
240
sts,output = utils.run(cmd)
242
log.warn("Failed to change log file group permissions: %s" %output)
244
log.debug(" hp-check-plugin started")
246
if Plugin_option_Enabled and Systray_Msg_Enabled:
247
log.error("Both -m and -p options can't be used together.")
251
log.debug("param=%s" % param)
257
device_uri, sane_uri, fax_uri = device.makeURI(param)
259
log.error("This is not a valid device")
262
log.debug("\nSetting up device: %s\n" % device_uri)
263
#Query model and checks Plugin information.
264
mq = device.queryModelByURI(device_uri)
265
if not mq or mq.get('support-type', SUPPORT_TYPE_NONE) == SUPPORT_TYPE_NONE:
266
log.error("Unsupported printer model.")
269
plugin = mq.get('plugin', PLUGIN_NONE)
270
if plugin == PLUGIN_NONE:
271
log.debug("This is not a plugin device.")
274
if not Plugin_option_Enabled:
275
Systray_Msg_Enabled = True
277
# checking whether HP-systray is running or not. Invokes, if systray is not running
278
status,output = utils.Is_Process_Running('hp-systray')
280
Systray_Is_Running=False
281
log.info("hp-systray is not running.")
283
log.error(" hp-systray must be running.\n Run \'hp-systray &\' in a terminal. ")
285
log.info("Starting hp-systray service")
286
child_pid = os.fork()
288
Systray_Is_Running=True
289
status,output =utils.run('hp-systray &', True, None, 1, False)
291
log.error("Failed to start \'hp-systray\' service. Manually run \'hp-sysray &\' from terminal as non-root user.")
292
Systray_Is_Running=False
296
Systray_Is_Running=True
299
Systray_Is_Running=True
300
log.debug("hp-systray service is running\n")
302
core = core_install.CoreInstall()
303
core.set_plugin_version()
304
plugin_sts = core.check_for_plugin()
305
if plugin_sts == PLUGIN_INSTALLED:
306
log.info("Device Plugin is already installed")
307
Is_Plugin_Already_Installed = True
308
elif plugin_sts == PLUGIN_VERSION_MISMATCH:
309
log.info("HP Device Plug-in version mismatch or some files are corrupted")
311
log.info("HP Device Plug-in is not found.")
313
if Systray_Msg_Enabled:
314
if not Is_Plugin_Already_Installed:
315
install_Plugin( Systray_Is_Running)
317
elif Plugin_option_Enabled:
318
if not Is_Plugin_Already_Installed:
319
install_Plugin (Systray_Is_Running, True) # needs to run hp-plugin without usig systray
321
if Firmware_Option_Enabled:
322
if Is_Plugin_Already_Installed is False:
323
Plugin_Installation_Completed = False
325
Plugin_Installation_Completed = True
327
install_firmware(Plugin_Installation_Completed,param)