1
# -*- coding: utf-8 -*-
3
# (c) Copyright 2003-2015 HP Development Company, L.P.
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
__title__ = 'Plugin Installer'
24
__doc__ = "Self-installs the HPLIP plugin."
25
__mod__ = "hplip-plugin-install"
36
import ConfigParser as configparser
42
#if os.geteuid() == 0:
43
# print("hp-plugin should not be run as root/superuser. Exiting.")
46
def startGUIInstall():
52
exec_str = sys.executable
53
passwordObj = password.Password(mode)
54
cmd = "%s installPlugin.py"%exec_str
55
cmd = passwordObj.getAuthCmd()%cmd
56
status, output = utils.run(cmd, passwordObj)
60
print("Plugin installation failed")
64
config_file = '/etc/hp/hplip.conf'
65
if os.path.exists(config_file):
66
config = configparser.ConfigParser()
67
config.read(config_file)
69
home_dir = config.get('dirs', 'home')
71
print("Error setting home directory: home= under [dirs] in %s not found. Is HPLIP installed?" % config_file)
74
print("Error setting home directory: %s not found. Is HPLIP installed?" % config_file)
77
if not home_dir or not os.path.exists(home_dir):
78
print("Error setting home directory: Home directory %s not found. Is HPLIP installed?" % home_dir)
80
sys.path.insert(0, home_dir)
84
from base.codes import *
85
from base import utils, tui, module
87
print("Error importing HPLIP modules. Is HPLIP installed?")
90
mod = module.Module(__mod__, __title__, __version__, __doc__, None,
91
(INTERACTIVE_MODE, GUI_MODE),
92
(UI_TOOLKIT_QT3, UI_TOOLKIT_QT4, UI_TOOLKIT_QT5), True)
96
opts, device_uri, printer_name, mode, ui_toolkit, loc = \
97
mod.parseStdOpts('c:v:p',
98
['count=', 'pkit-version='],
99
handle_device_printer=False)
103
user_pkit_version = None
106
if o in ('-c', '--count'):
112
elif o in ('-v', '--version'):
115
elif o in ('--pkit-version'):
117
user_pkit_version = int(a)
119
log.error("-v or --version require an integer argument")
121
if user_pkit_version < 0 or user_pkit_version > 1:
122
log.error("invalid PolicyKit version...use 0 or 1")
125
pkit_installed = False
128
version = open("version.txt", "r").read().strip()
130
version_mismatch = version != prop.installed_version
133
log.error("Plug-in version mismatch:")
134
log.error(" Plug-in version: %s" % version)
135
log.error(" Installed HPLIP version: %s" % prop.installed_version)
136
log.error(" Installed HPLIP version and plug-in version must match.")
140
log.info("Plug-in version: %s" % version)
141
log.info("Installed HPLIP version: %s" % prop.installed_version)
143
log.info("Number of files to install: %d" % num_files)
146
PKIT = utils.to_bool(sys_conf.get('configure', 'policy-kit'))
148
from base.pkit import *
149
pkit_version = policykit_version()
151
if not user_pkit_version is None:
152
pkit_version = user_pkit_version
153
log.debug("pkit_version %d" % pkit_version)
155
pkit = PolicyKit(pkit_version)
156
pkit_installed = True
157
except dbus.DBusException:
158
pkit_installed = False
160
log.error("Unable to load pkit...is HPLIP installed?")
163
pkit_installed = False
164
log.debug("pkit_installed %s" % pkit_installed)
166
if mode == INTERACTIVE_MODE:
169
log.info(log.bold("You must agree to the license terms before installing the plug-in:"))
172
license_f = open("license.txt", "r")
174
for line1 in license_f:
176
for line2 in tui.format_paragraph(line1):
179
ok, ans = tui.enter_yes_no("\nDo you accept the license terms for the plug-in")
181
if not ok or not ans:
182
log.error("License agreement not accepted. Exiting.")
185
if not installPlugin():
186
log.error("Plugin installation failed")
190
if ui_toolkit == 'qt3':
194
from ui.pluginlicenseform import PluginLicenseForm
196
log.error("Unable to load Qt3 support. Is it installed?")
199
app = QApplication(sys.argv)
200
QObject.connect(app, SIGNAL("lastWindowClosed()"), app, SLOT("quit()"))
204
QMessageBox.critical(None,
205
"HP Device Manager - Plug-in Installer",
206
"Plug-in version mismatch. Installed HPLIP version (%s) and plug-in version (%s) must match." % (prop.installed_version, version))
208
# QMessageBox.NoButton)
209
# QMessageBox.NoButton)
213
dlg = PluginLicenseForm(open("license.txt", "r").read())
215
if dlg.exec_loop() == QDialog.Accepted:
218
log.debug("Plug-in installation failed.")
222
log.error("License agreement not accepted. Exiting.")
225
elif ui_toolkit == "qt4": # qt4
228
from PyQt4.QtGui import *
229
from PyQt4.QtCore import *
230
from ui4.pluginlicensedialog import PluginLicenseDialog
232
log.error("Unable to load Qt4 support. Is it installed? Try running with -i or --qt3 instead.")
234
elif ui_toolkit == "qt5":
236
log.note("Using PyQt5")
237
from PyQt5.QtGui import *
238
from PyQt5.QtCore import *
239
from PyQt5.QtWidgets import *
240
from ui5.pluginlicensedialog import PluginLicenseDialog
242
log.error("Unable to load Qt5 support. Is it installed? Try running with -i or --qt3 instead.")
246
app = QApplication(sys.argv)
249
QMessageBox.critical(None,
250
"HP Device Manager - Plug-in Installer",
251
"Plug-in version mismatch. Installed HPLIP version (%s) and plug-in version (%s) must match." % (prop.installed_version, version))
253
#QMessageBox.NoButton,
254
#QMessageBox.NoButton)
258
dlg = PluginLicenseDialog(None, open("license.txt", "r").read())
260
if dlg.exec_() == QDialog.Accepted:
263
log.debug("Plug-in installation failed")
266
# changing permission for hplip.state
267
cmd="chmod 644 /var/lib/hp/hplip.state"
271
log.error("License agreement not accepted. Exiting.")