49
48
("Check only available version:","--check","option",False),
50
49
("Non-interactive mode:","-n(Without asking permissions)(future use)","option",False),
51
50
("Download Path to install from local system:","-p<path>","option", False),
52
("Download HPLIP package location:","-d<path> (default location ~/.hplip/)","option", False),
51
("Download HPLIP package location:","-d<path> (default location ~/Downloads)","option", False),
53
52
("Override existing HPLIP installation even if latest vesrion is installed:","-o","option",False),
54
53
("Take options from the file instead of command line:","-f<file> (future use)","option",False)
56
mode = INTERACTIVE_MODE
57
EXISTING_PACKAGE_PATH=None
58
PATH_TO_DOWNLOAD_INSTALLER=os.path.expanduser('~/Downloads')
62
HPLIP_VERSION_INFO_SOURCEFORGE_SITE ="http://hplip.sourceforge.net/hplip_web.conf"
63
HPLIP_WEB_SITE ="http://hplipopensource.com/hplip-web/index.html"
64
HPLIP_PACKAGE_SITE = "http://sourceforge.net/projects/hplip/files/hplip"
66
DONOT_CLOSE_TERMINAL = False
67
CURRENT_WORKING_DIR = ''
58
70
def hold_terminal():
59
71
if DONOT_CLOSE_TERMINAL:
60
72
log.info("\n\nPlease close this terminal manually. ")
64
77
except KeyboardInterrupt:
120
def get_hplip_version_from_sourceforge():
121
HPLIP_latest_ver="0.0.0"
123
# get HPLIP version info from hplip_web.conf file
124
sts, HPLIP_Ver_file = utils.download_from_network(HPLIP_VERSION_INFO_SOURCEFORGE_SITE)
126
hplip_version_conf = ConfigBase(HPLIP_Ver_file)
127
HPLIP_latest_ver = hplip_version_conf.get("HPLIP","Latest_version","0.0.0")
128
os.unlink(HPLIP_Ver_file)
130
return HPLIP_latest_ver
133
def get_hplip_version_from_hplipopensource():
134
HPLIP_latest_ver="0.0.0"
135
pat = re.compile(r"""The current version of the HPLIP solution is version (\d{1,}\.\d{1,}\.\d{1,}[a-z]{0,})\. \(.*""")
136
sts, HPLIP_Ver_file = utils.download_from_network(HPLIP_WEB_SITE)
138
HPLIP_latest_ver = parse_HPLIP_version(HPLIP_Ver_file, pat)
139
os.unlink(HPLIP_Ver_file)
141
return HPLIP_latest_ver
144
def get_latest_hplip_version():
145
HPLIP_latest_ver = get_hplip_version_from_sourceforge()
147
if HPLIP_latest_ver == "0.0.0": ## if failed to connect the sourceforge site, then check HPLIP site.
148
HPLIP_latest_ver = get_hplip_version_from_hplipopensource()
150
return HPLIP_latest_ver
153
def digital_signature_fail_confirmation(msg):
154
log.error(log.bold(msg))
155
ok,choice = tui.enter_choice("Do you want continue without Digital Signature verification (y=yes, n=no*):", ['y','n'],'n')
156
if not ok or choice == 'n':
162
def download_hplip_installer(path_to_download, hplip_version):
163
url="%s/%s/hplip-%s.run" %(HPLIP_PACKAGE_SITE, hplip_version, hplip_version)
164
hplip_package = "%s/hplip-%s.run" %(path_to_download, hplip_version)
166
log.info("Downloading hplip-%s.run file..... Please wait. "%hplip_version )
167
sts,download_file = utils.download_from_network(url, hplip_package, True)
170
if not os.path.exists(hplip_package):
171
log.error("Failed to download %s file."%hplip_package)
174
log.info("Downloading hplip-%s.run.asc file..... Please wait. "%hplip_version )
175
hplip_digsig = hplip_package+".asc"
177
sts,download_file = utils.download_from_network(url, hplip_digsig)
180
if not os.path.exists(hplip_digsig):
181
log.error("Failed to download %s file."%hplip_package)
182
return hplip_package, ''
184
return hplip_package, hplip_digsig
187
###################### Main ###############
105
188
log.set_module(__mod__)
107
mode = INTERACTIVE_MODE
110
TEMP_DIR=prop.user_dir
114
HPLIP_VERSION_INFO_SITE ="http://hplip.sourceforge.net/hplip_web.conf"
115
HPLIP_WEB_SITE ="http://hplipopensource.com/hplip-web/index.html"
116
IS_QUIET_MODE = False
117
DONOT_CLOSE_TERMINAL = False
118
CURRENT_WORKING_DIR = ''
120
190
mod = module.Module(__mod__, __title__, __version__, __doc__, USAGE,
121
191
(INTERACTIVE_MODE, GUI_MODE),
219
287
core = CoreInstall(MODE_CHECK)
220
288
if not utils.check_network_connection():
221
289
log.error("Either Internet is not working or Wget is not installed.")
224
292
installed_version=sys_conf.get("hplip","version","0.0.0")
225
293
log.debug("HPLIP previous installed version =%s." %installed_version)
229
HPLIP_latest_ver="0.0.0"
230
# get HPLIP version info from hplip_web.conf file
231
sts, HPLIP_Ver_file = utils.download_from_network(HPLIP_VERSION_INFO_SITE)
233
hplip_version_conf = ConfigBase(HPLIP_Ver_file)
234
HPLIP_latest_ver = hplip_version_conf.get("HPLIP","Latest_version","0.0.0")
236
# get HPLIP version info from hplip site
237
if HPLIP_latest_ver == "0.0.0": ## if failed to connect the sourceforge site, then check HPLIP site.
238
pat = re.compile(r"""The current version of the HPLIP solution is version (\d{1,}\.\d{1,}\.\d{1,}[a-z]{0,})\. \(.*""")
239
sts, HPLIP_Ver_file = utils.download_from_network(HPLIP_WEB_SITE)
241
HPLIP_latest_ver = parse_HPLIP_version(HPLIP_Ver_file, pat)
243
os.unlink(HPLIP_Ver_file)
295
HPLIP_latest_ver = get_latest_hplip_version()
244
297
if HPLIP_latest_ver == "0.0.0":
245
298
log.error("Failed to get latest version of HPLIP.")
301
user_conf.set('upgrade','latest_available_version',HPLIP_latest_ver)
249
302
if CHECKING_ONLY is True:
250
user_conf.set('upgrade','latest_available_version',HPLIP_latest_ver)
251
303
log.debug("Available HPLIP version =%s."%HPLIP_latest_ver)
252
305
elif NOTIFY is True:
253
user_conf.set('upgrade','latest_available_version',HPLIP_latest_ver)
254
306
if not utils.Is_HPLIP_older_version(installed_version, HPLIP_latest_ver):
255
307
log.debug("Latest version of HPLIP is already installed.")
258
310
msg = "Latest version of HPLIP-%s is available."%HPLIP_latest_ver
259
311
if core.is_auto_installer_support():
265
316
if ui_toolkit == 'qt3':
266
317
if not utils.canEnterGUIMode():
267
318
log.error("%s requires GUI support. Is Qt3 Installed?.. Exiting." % __mod__)
323
371
log.info("Please install HPLIP manually as mentioned in 'http://hplipopensource.com/hplip-web/install/manual/index.html' site")
326
# check systray is running?
327
status,output = utils.Is_Process_Running('hp-systray')
329
ok,choice = tui.enter_choice("\nSome HPLIP applications are running. Press 'y' to close applications or press 'n' to quit upgrade(y=yes*, n=no):",['y','n'],'y')
330
if not ok or choice =='n':
331
log.info("Manually close HPLIP applications and run hp-upgrade again.")
337
from dbus import SystemBus, lowlevel
339
log.error("Unable to load DBus.")
343
args = ['', '', EVENT_SYSTEMTRAY_EXIT, prop.username, 0, '', '']
344
msg = lowlevel.SignalMessage('/', 'com.hplip.StatusService', 'Event')
345
msg.append(signature='ssisiss', *args)
346
log.debug("Sending close message to hp-systray ...")
347
SystemBus().send_message(msg)
350
log.error("Failed to send DBus message to hp-systray/hp-toolbox.")
354
toolbox_status,output = utils.Is_Process_Running('hp-toolbox')
356
if toolbox_status is True:
357
log.error("Failed to close either HP-Toolbox/HP-Systray. Manually close and run hp-upgrade again.")
361
if HPLIP_PATH is not None:
362
if os.path.exists(HPLIP_PATH):
363
download_file = HPLIP_PATH
365
log.error("%s file is not present. Downloading from Net..." %HPLIP_PATH)
368
if HPLIP_PATH is None:
369
url="http://sourceforge.net/projects/hplip/files/hplip/%s/hplip-%s.run/download" %(HPLIP_latest_ver, HPLIP_latest_ver)
372
download_file = "%s/hplip-%s.run" %(TEMP_DIR,HPLIP_latest_ver)
373
log.info("Downloading hplip-%s.run file..... Please wait. "%HPLIP_latest_ver )
374
sts,download_file = utils.download_from_network(url, download_file, True)
376
if not os.path.exists(download_file):
377
log.error("Failed to download %s file."%download_file)
374
if not services.close_running_hp_processes():
377
if EXISTING_PACKAGE_PATH:
378
downloaded_file = "%s/hplip-%s.run"%(EXISTING_PACKAGE_PATH, HPLIP_latest_ver)
379
digsig_file = "%s/hplip-%s.run.asc"%(EXISTING_PACKAGE_PATH, HPLIP_latest_ver)
380
PATH_TO_DOWNLOAD_INSTALLER = EXISTING_PACKAGE_PATH
382
downloaded_file, digsig_file = download_hplip_installer(PATH_TO_DOWNLOAD_INSTALLER, HPLIP_latest_ver)
384
PasswordObj = password.Password(INTERACTIVE_MODE)
385
PasswordObj.clearPassword()
387
gpg_obj = validation.GPG_Verification()
389
digsig_sts = validation.DIGSIG_ERROR_GPG_CMD_NOT_FOUND
391
digsig_sts = gpg_obj.validate(downloaded_file, digsig_file, PasswordObj)
393
if digsig_sts != validation.DIGSIG_ERROR_NONE:
394
if digsig_sts in (validation.DIGSIG_ERROR_INCORRECT_PASSWORD, validation.DIGSIG_ERROR_FILE_NOT_FOUND):
397
elif digsig_sts == validation.DIGSIG_ERROR_DIGITAL_SIGN_NOT_FOUND:
398
if not digital_signature_fail_confirmation("Digital signature file not found or failed to download. Unable to validate the installer file."):
401
elif digsig_sts == validation.DIGSIG_ERROR_GPG_CMD_NOT_FOUND:
402
if not digital_signature_fail_confirmation("GPG command not found. Unable to validate the installer file."):
405
elif digsig_sts in (validation.DIGSIG_ERROR_DIGITAL_SIGN_BAD, validation.DIGSIG_ERROR_UNABLE_TO_RECV_KEYS):
406
if not digital_signature_fail_confirmation("File does not match its digital signature. File may have been corrupted or altered"):
410
log.error("Failed to validate digital signature. Unknow error: %s"%digsig_sts)
379
413
CURRENT_WORKING_DIR = os.getcwd()
414
os.chdir(PATH_TO_DOWNLOAD_INSTALLER)
381
416
# Installing hplip run.
382
cmd = "sh %s" %(download_file)
383
log.debug("Upgrading %s" % download_file)
417
cmd = "sh %s" %(downloaded_file)
418
log.debug("Upgrading %s" % downloaded_file)
384
420
sts = os_utils.execute(cmd)
385
421
os.chdir(CURRENT_WORKING_DIR)
386
if not NOTIFY and not CHECKING_ONLY:
388
424
log.info(log.bold("Upgrade is Completed."))
390
log.info(log.bold("Upgrade Failed or Skipped."))
426
log.info(log.bold("Upgrade Failed or Skipped. status: %s"%sts))
392
428
change_spinner_state(True)
393
429
mod.unlockInstance()
396
# log.info("HPLIP upgrade is completed")
397
432
except KeyboardInterrupt:
398
change_spinner_state(True)
400
433
if CURRENT_WORKING_DIR:
401
434
os.chdir(CURRENT_WORKING_DIR)
402
436
if not IS_QUIET_MODE:
403
437
log.error("User exit")