Radix cross Linux

The main Radix cross Linux repository contains the build scripts of packages, which have the most complete and common functionality for desktop machines

452 Commits   2 Branches   1 Tag
    93         kx #!/usr/bin/python
    93         kx # -*- coding: utf-8 -*-
    93         kx #
    93         kx # (c) Copyright 2011-2015 HP Development Company, L.P.
    93         kx #
    93         kx # This program is free software; you can redistribute it and/or modify
    93         kx # it under the terms of the GNU General Public License as published by
    93         kx # the Free Software Foundation; either version 2 of the License, or
    93         kx # (at your option) any later version.
    93         kx #
    93         kx # This program is distributed in the hope that it will be useful,
    93         kx # but WITHOUT ANY WARRANTY; without even the implied warranty of
    93         kx # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    93         kx # GNU General Public License for more details.
    93         kx #
    93         kx # You should have received a copy of the GNU General Public License
    93         kx # along with this program; if not, write to the Free Software
    93         kx # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
    93         kx #
    93         kx # Author: Amarnath Chitumalla
    93         kx #
    93         kx from __future__ import print_function
    93         kx __version__ = '1.0'
    93         kx __title__ = 'HPLIP upgrade latest version'
    93         kx __mod__ = 'hp-upgrade'
    93         kx __doc__ = "HPLIP installer to upgrade to latest version."
    93         kx 
    93         kx # Std Lib
    93         kx import getopt, os, sys, re, time, datetime
    93         kx 
    93         kx # Local
    93         kx from base.g import *
    93         kx from base.strings import *
    93         kx from base import utils, tui, module, os_utils, services, validation
    93         kx from installer.core_install import *
    93         kx from base.sixext.moves import input
    93         kx 
    93         kx 
    93         kx USAGE = [(__doc__, "", "name", True),
    93         kx          ("Usage: %s [OPTIONS]" % __mod__, "", "summary", True),
    93         kx          utils.USAGE_SPACE,
    93         kx          utils.USAGE_MODE,
    93         kx          ("Run in interactive mode:", "-i or --interactive (Default)", "option", False),
    93         kx #         ("Run in graphical UI mode:", "-u or --gui (future use)", "option", False),
    93         kx          utils.USAGE_SPACE,
    93         kx          utils.USAGE_OPTIONS,
    93         kx          utils.USAGE_HELP,
    93         kx          utils.USAGE_LOGGING1, utils.USAGE_LOGGING2, utils.USAGE_LOGGING3,
    93         kx          ("Check for update and notify:","--notify","option",False),
    93         kx          ("Check only available version:","--check","option",False),
    93         kx #         ("Non-interactive mode:","-n(Without asking permissions)(future use)","option",False),
    93         kx          ("Specify the path to the .run file on local system:","-p<path>","option", False),
    93         kx          ("Download HPLIP package location:","-d<path> (default location ~/Downloads)","option", False),
    93         kx          ("Override existing HPLIP installation even if latest vesrion is installed:","-o","option",False),
    93         kx #         ("Take options from the file instead of command line:","-f<file> (future use)","option",False)
    93         kx         ]
    93         kx 
    93         kx mode = INTERACTIVE_MODE
    93         kx EXISTING_PACKAGE_PATH=None
    93         kx PATH_TO_DOWNLOAD_INSTALLER=os.path.expanduser('~/Downloads')
    93         kx FORCE_INSTALL=False
    93         kx CHECKING_ONLY=False
    93         kx NOTIFY=False
    93         kx HPLIP_VERSION_INFO_SOURCEFORGE_SITE ="http://hplip.sourceforge.net/hplip_web.conf"
    93         kx HPLIP_WEB_SITE ="http://hplipopensource.com/hplip-web/index.html"
    93         kx HPLIP_PACKAGE_SITE = "http://sourceforge.net/projects/hplip/files/hplip"
    93         kx IS_QUIET_MODE = False
    93         kx DONOT_CLOSE_TERMINAL = False
    93         kx CURRENT_WORKING_DIR = ''
    93         kx 
    93         kx def hold_terminal():
    93         kx     if DONOT_CLOSE_TERMINAL:
    93         kx         log.info("\n\nPlease close this terminal manually. ")
    93         kx         try:
    93         kx             while 1:
    93         kx                 pass
    93         kx         except KeyboardInterrupt:
    93         kx             pass
    93         kx 
    93         kx 
    93         kx def usage(typ='text'):
    93         kx     if typ == 'text':
    93         kx         utils.log_title(__title__, __version__)
    93         kx 
    93         kx     utils.format_text(USAGE, typ, __title__, __mod__, __version__)
    93         kx     hold_terminal()
    93         kx     sys.exit(0)
    93         kx 
    93         kx def clean_exit(code=0, waitTerminal=True):
    93         kx     if not NOTIFY and not CHECKING_ONLY and not IS_QUIET_MODE:
    93         kx         log.info("")
    93         kx         log.info("Done.")
    93         kx     change_spinner_state(True)
    93         kx     mod.unlockInstance()
    93         kx     hold_terminal()
    93         kx     sys.exit(code)
    93         kx 
    93         kx 
    93         kx def parse_HPLIP_version(hplip_version_file, pat):
    93         kx     ver = "0.0.0"
    93         kx     if not os.path.exists(hplip_version_file):
    93         kx         return ver
    93         kx 
    93         kx     try:
    93         kx         fp= open(hplip_version_file, 'r')
    93         kx     except IOError:
    93         kx         log.error("Failed to get hplip version since %s file is not found."%hplip_version_file)
    93         kx         return ver
    93         kx     data = fp.read()
    93         kx     for line in data.splitlines():
    93         kx         if pat.search(line):
    93         kx             ver = pat.search(line).group(1)
    93         kx             break
    93         kx 
    93         kx     log.debug("Latest HPLIP version = %s." % ver)
    93         kx     return ver
    93         kx 
    93         kx 
    93         kx def get_hplip_version_from_sourceforge():
    93         kx     HPLIP_latest_ver="0.0.0"
    93         kx 
    93         kx     # get HPLIP version info from hplip_web.conf file
    93         kx     sts, HPLIP_Ver_file = utils.download_from_network(HPLIP_VERSION_INFO_SOURCEFORGE_SITE)
    93         kx     if sts == 0:
    93         kx         hplip_version_conf = ConfigBase(HPLIP_Ver_file)
    93         kx         HPLIP_latest_ver = hplip_version_conf.get("HPLIP","Latest_version","0.0.0")
    93         kx         os.unlink(HPLIP_Ver_file)
    93         kx 
    93         kx     return HPLIP_latest_ver
    93         kx 
    93         kx 
    93         kx def get_hplip_version_from_hplipopensource():
    93         kx     HPLIP_latest_ver="0.0.0"
    93         kx     pat = re.compile(r"""The current version of the HPLIP solution is version (\d{1,}\.\d{1,}\.\d{1,}[a-z]{0,})\. \(.*""")
    93         kx     sts, HPLIP_Ver_file = utils.download_from_network(HPLIP_WEB_SITE)
    93         kx     if sts == 0:
    93         kx         HPLIP_latest_ver = parse_HPLIP_version(HPLIP_Ver_file, pat)
    93         kx         os.unlink(HPLIP_Ver_file)
    93         kx 
    93         kx     return HPLIP_latest_ver
    93         kx 
    93         kx 
    93         kx def get_latest_hplip_version():
    93         kx     HPLIP_latest_ver = get_hplip_version_from_sourceforge()
    93         kx 
    93         kx     if HPLIP_latest_ver == "0.0.0":     ## if failed to connect the sourceforge site, then check HPLIP site.
    93         kx         HPLIP_latest_ver = get_hplip_version_from_hplipopensource()
    93         kx                            
    93         kx     return HPLIP_latest_ver
    93         kx 
    93         kx 
    93         kx def digital_signature_fail_confirmation(msg):
    93         kx     log.error(log.bold(msg))
    93         kx     ok,choice = tui.enter_choice("Do you want continue without Digital Signature verification (y=yes, n=no*):", ['y','n'],'n')
    93         kx     if not ok or choice == 'n':
    93         kx        return False
    93         kx     else:
    93         kx         return True
    93         kx 
    93         kx 
    93         kx def download_hplip_installer(path_to_download, hplip_version):
    93         kx     url="%s/%s/hplip-%s.run" %(HPLIP_PACKAGE_SITE, hplip_version, hplip_version)
    93         kx     hplip_package = "%s/hplip-%s.run" %(path_to_download, hplip_version)
    93         kx 
    93         kx     log.info("Downloading hplip-%s.run file..... Please wait. "%hplip_version )
    93         kx     sts,download_file = utils.download_from_network(url, hplip_package, True)
    93         kx     log.info("")
    93         kx 
    93         kx     if not os.path.exists(hplip_package):
    93         kx         log.error("Failed to download %s file."%hplip_package)
    93         kx         return '',''
    93         kx 
    93         kx     log.info("Downloading hplip-%s.run.asc file..... Please wait. "%hplip_version )
    93         kx     hplip_digsig =  hplip_package+".asc"
    93         kx     url = url +".asc"
    93         kx     sts,download_file = utils.download_from_network(url, hplip_digsig)
    93         kx     log.info("")
    93         kx 
    93         kx     if not os.path.exists(hplip_digsig):
    93         kx         log.error("Failed to download %s file."%hplip_package)
    93         kx         return hplip_package, ''
    93         kx 
    93         kx     return hplip_package, hplip_digsig
    93         kx 
    93         kx 
    93         kx ###################### Main ###############
    93         kx log.set_module(__mod__)
    93         kx try:
    93         kx     mod = module.Module(__mod__, __title__, __version__, __doc__, USAGE,
    93         kx                     (INTERACTIVE_MODE, GUI_MODE),
    93         kx                     (UI_TOOLKIT_QT3, UI_TOOLKIT_QT4, UI_TOOLKIT_QT5), True)
    93         kx 
    93         kx     opts, device_uri, printer_name, mode, ui_toolkit, loc = \
    93         kx                mod.parseStdOpts('hl:gniup:d:of:sw', ['notify','check','help', 'help-rest', 'help-man', 'help-desc', 'interactive', 'gui', 'lang=','logging=', 'debug'],
    93         kx                      handle_device_printer=False)
    93         kx 
    93         kx 
    93         kx 
    93         kx except getopt.GetoptError as e:
    93         kx     log.error(e.msg)
    93         kx     usage()
    93         kx 
    93         kx if os.geteuid() == 0:
    93         kx     log.error("%s %s"  %(__mod__, queryString(ERROR_RUNNING_AS_ROOT)))
    93         kx     clean_exit(1)
    93         kx 
    93         kx if os.getenv("HPLIP_DEBUG"):
    93         kx     log.set_level('debug')
    93         kx 
    93         kx for o, a in opts:
    93         kx     if o in ('-h', '--help'):
    93         kx         usage()
    93         kx 
    93         kx     elif o == '--help-rest':
    93         kx         usage('rest')
    93         kx 
    93         kx     elif o == '--help-man':
    93         kx         usage('man')
    93         kx 
    93         kx     elif o in ('-q', '--lang'):
    93         kx         language = a.lower()
    93         kx 
    93         kx     elif o == '--help-desc':
    93         kx         print(__doc__, end=' ')
    93         kx         clean_exit(0,False)
    93         kx 
    93         kx     elif o in ('-l', '--logging'):
    93         kx         log_level = a.lower().strip()
    93         kx         if not log.set_level(log_level):
    93         kx             usage()
    93         kx 
    93         kx     elif o in ('-g', '--debug'):
    93         kx         log.set_level('debug')
    93         kx 
    93         kx     elif o == '-n':
    93         kx         mode = NON_INTERACTIVE_MODE
    93         kx         log.info("NON_INTERACTIVE mode is not yet supported.")
    93         kx         usage()
    93         kx         clean_exit(0,False)
    93         kx 
    93         kx     elif o == '-p':
    93         kx         EXISTING_PACKAGE_PATH=a
    93         kx 
    93         kx     elif o == '-d':
    93         kx         PATH_TO_DOWNLOAD_INSTALLER=a
    93         kx 
    93         kx     elif o == '-o':
    93         kx         FORCE_INSTALL = True
    93         kx 
    93         kx     elif o in ('-u', '--gui'):
    93         kx         log.info("GUI is not yet supported.")
    93         kx         usage()
    93         kx         clean_exit(0, False)
    93         kx     elif o == '--check':
    93         kx         CHECKING_ONLY = True
    93         kx     elif o == '--notify':
    93         kx         NOTIFY = True
    93         kx     elif o == '-s':
    93         kx         IS_QUIET_MODE = True
    93         kx     elif o == '-f':
    93         kx         log.info("Option from file is not yet supported")
    93         kx         usage()
    93         kx         clean_exit(0, False)
    93         kx     elif o == '-w':
    93         kx         DONOT_CLOSE_TERMINAL = True
    93         kx 
    93         kx if not NOTIFY and not CHECKING_ONLY and not IS_QUIET_MODE:
    93         kx     mod.quiet= False
    93         kx     mod.showTitle()
    93         kx 
    93         kx if NOTIFY or CHECKING_ONLY:
    93         kx     mod.lockInstance('check',True)
    93         kx else:
    93         kx     mod.lockInstance('upgrade',True)
    93         kx 
    93         kx log_file = os.path.normpath('%s/hp-upgrade.log'%prop.user_dir)
    93         kx 
    93         kx if os.path.exists(log_file):
    93         kx     try:
    93         kx         os.remove(log_file)
    93         kx     except OSError:
    93         kx         pass
    93         kx 
    93         kx log.set_logfile(log_file)
    93         kx log.set_where(log.LOG_TO_CONSOLE_AND_FILE)
    93         kx 
    93         kx 
    93         kx log.debug("Upgrade log saved in: %s" % log.bold(log_file))
    93         kx log.debug("")
    93         kx try:
    93         kx     change_spinner_state(False)
    93         kx     core =  CoreInstall(MODE_CHECK)
    93         kx 
    93         kx     # To reenable upgrade in Radix (although it probably won't work), delete the following 3 lines:
    93         kx     log.info("HPLIP upgrade function is disabled in Radix.")
    93         kx     log.info("Not attempting to download upgrades.")
    93         kx     clean_exit(0)
    93         kx 
    93         kx     if not utils.check_network_connection():
    93         kx         log.error("Either Internet is not working or Wget is not installed.")
    93         kx         clean_exit(1)
    93         kx 
    93         kx     installed_version=sys_conf.get("hplip","version","0.0.0")
    93         kx     log.debug("HPLIP previous installed version =%s." %installed_version)
    93         kx 
    93         kx     HPLIP_latest_ver = get_latest_hplip_version()
    93         kx 
    93         kx     if HPLIP_latest_ver == "0.0.0":
    93         kx         log.error("Failed to get latest version of HPLIP.")
    93         kx         clean_exit(1)
    93         kx 
    93         kx     user_conf.set('upgrade','latest_available_version',HPLIP_latest_ver)
    93         kx     if CHECKING_ONLY is True:
    93         kx         log.debug("Available HPLIP version =%s."%HPLIP_latest_ver)
    93         kx 
    93         kx     elif NOTIFY is True:
    93         kx         if not utils.Is_HPLIP_older_version(installed_version, HPLIP_latest_ver):
    93         kx             log.debug("Latest version of HPLIP is already installed.")
    93         kx 
    93         kx         else:
    93         kx             msg = "Latest version of HPLIP-%s is available."%HPLIP_latest_ver
    93         kx             if core.is_auto_installer_support():
    93         kx                 distro_type= 1
    93         kx             else:
    93         kx                 distro_type= 2
    93         kx 
    93         kx             if ui_toolkit == 'qt3':
    93         kx                 if not utils.canEnterGUIMode():
    93         kx                     log.error("%s requires GUI support. Is Qt3 Installed?.. Exiting." % __mod__)
    93         kx                     clean_exit(1)
    93         kx 
    93         kx                 try:
    93         kx                     from qt import *
    93         kx                     from ui.upgradeform import UpgradeForm
    93         kx                 except ImportError:
    93         kx                     log.error("Unable to load Qt3 support. Is it installed? ")
    93         kx                     clean_exit(1)
    93         kx 
    93         kx                 # create the main application object
    93         kx                 app = QApplication(sys.argv)
    93         kx                 QObject.connect(app, SIGNAL("lastWindowClosed()"), app, SLOT("quit()"))
    93         kx                 dialog = UpgradeForm(None, "",0,0,distro_type, msg)
    93         kx                 dialog.show()
    93         kx 
    93         kx                 log.debug("Starting GUI loop...")
    93         kx                 app.exec_loop()
    93         kx 
    93         kx             else: #qt4
    93         kx                 if not utils.canEnterGUIMode4():
    93         kx                     log.error("%s requires GUI support . Is Qt4 installed?.. Exiting." % __mod__)
    93         kx                     clean_exit(1)
    93         kx 
    93         kx                 try:
    93         kx                     from PyQt4.QtGui import QApplication, QMessageBox
    93         kx                     from ui4.upgradedialog import UpgradeDialog
    93         kx                 except ImportError:
    93         kx                     log.error("Unable to load Qt4 support. Is it installed?")
    93         kx                     clean_exit(1)
    93         kx 
    93         kx                 app = QApplication(sys.argv)
    93         kx                 dialog = UpgradeDialog(None, distro_type, msg)
    93         kx 
    93         kx                 dialog.show()
    93         kx                 log.debug("Starting GUI loop...")
    93         kx                 app.exec_()
    93         kx 
    93         kx     else:
    93         kx         if FORCE_INSTALL is False:
    93         kx             if utils.Is_HPLIP_older_version(installed_version, HPLIP_latest_ver):
    93         kx                 if IS_QUIET_MODE:
    93         kx                     log.info("Newer version of HPLIP-%s is available."%HPLIP_latest_ver)
    93         kx                 ok,choice = tui.enter_choice("Press 'y' to continue to upgrade HPLIP-%s (y=yes*, n=no):"%HPLIP_latest_ver, ['y','n'],'y')
    93         kx                 if not ok or choice == 'n':
    93         kx                     log.info("Recommended to install latest version of HPLIP-%s"%HPLIP_latest_ver)
    93         kx                     clean_exit(0, False)
    93         kx             else:
    93         kx                 log.info("Latest version of HPLIP is already installed.")
    93         kx                 clean_exit(0,False)
    93         kx 
    93         kx         # check distro information.
    93         kx         if not core.is_auto_installer_support():
    93         kx             log.info("Please install HPLIP manually as mentioned in 'http://hplipopensource.com/hplip-web/install/manual/index.html' site")
    93         kx             clean_exit(0)
    93         kx 
    93         kx         if not services.close_running_hp_processes():
    93         kx             clean_exit(1)
    93         kx 
    93         kx         if EXISTING_PACKAGE_PATH:
    93         kx             downloaded_file = "%s/hplip-%s.run"%(EXISTING_PACKAGE_PATH, HPLIP_latest_ver)
    93         kx             digsig_file = "%s/hplip-%s.run.asc"%(EXISTING_PACKAGE_PATH, HPLIP_latest_ver)
    93         kx             PATH_TO_DOWNLOAD_INSTALLER = EXISTING_PACKAGE_PATH
    93         kx         else:
    93         kx             log.debug("\n Calling download_hplip_installer(...) \n")
    93         kx             log.debug("\n System Time : %s \n"%datetime.datetime.now().time().isoformat())
    93         kx 
    93         kx             if not os.path.exists(PATH_TO_DOWNLOAD_INSTALLER):
    93         kx                 log.error(log.bold("No such file or directory%s"%PATH_TO_DOWNLOAD_INSTALLER))
    93         kx                 download_path = input(log.bold("Please specify the path to download. Press 'q' to quit:"))
    93         kx                 if download_path == 'q':
    93         kx                     log.info("User selected to quit.")
    93         kx                     clean_exit(1)            
    93         kx                 elif not os.path.exists(download_path):
    93         kx                     log.error(log.bold("Specified path does not exist. Exiting...%s\n"%download_path)) 
    93         kx                     clean_exit(1)
    93         kx                 elif not os.access(download_path, os.R_OK | os.W_OK):
    93         kx                     log.error(log.bold("Specified path do not have enough permissions Exiting...%s\n"%download_path)) 
    93         kx                     clean_exit(1)          
    93         kx                 else:
    93         kx                     PATH_TO_DOWNLOAD_INSTALLER = download_path
    93         kx             downloaded_file, digsig_file = download_hplip_installer(PATH_TO_DOWNLOAD_INSTALLER, HPLIP_latest_ver)
    93         kx 
    93         kx 
    93         kx         gpg_obj = validation.GPG_Verification()
    93         kx         digsig_sts, error_str = gpg_obj.validate(downloaded_file, digsig_file)
    93         kx 
    93         kx         if digsig_sts != ERROR_SUCCESS:
    93         kx             if digsig_sts in  (ERROR_UNABLE_TO_RECV_KEYS, ERROR_DIGITAL_SIGN_NOT_FOUND, ERROR_DIGITAL_SIGN_BAD):
    93         kx                 if not digital_signature_fail_confirmation(error_str):
    93         kx                     clean_exit(1)
    93         kx             else:
    93         kx                 log.error(error_str)
    93         kx                 clean_exit(1)
    93         kx 
    93         kx 
    93         kx         CURRENT_WORKING_DIR = os.getcwd()
    93         kx         os.chdir(PATH_TO_DOWNLOAD_INSTALLER)
    93         kx 
    93         kx         # Installing hplip run.
    93         kx         cmd = "sh %s" %(downloaded_file)
    93         kx         log.debug("Upgrading  %s" % downloaded_file)
    93         kx 
    93         kx         sts = os_utils.execute(cmd)
    93         kx         os.chdir(CURRENT_WORKING_DIR)
    93         kx 
    93         kx         if sts == 0:
    93         kx             log.info(log.bold("Upgrade is Completed."))
    93         kx         else:
    93         kx             log.info(log.bold("Upgrade Failed or Skipped. status: %s"%sts))
    93         kx 
    93         kx     change_spinner_state(True)
    93         kx     mod.unlockInstance()
    93         kx     hold_terminal()
    93         kx 
    93         kx except KeyboardInterrupt:
    93         kx     if CURRENT_WORKING_DIR:
    93         kx         os.chdir(CURRENT_WORKING_DIR)
    93         kx 
    93         kx     if not IS_QUIET_MODE:
    93         kx         log.error("User exit")
    93         kx 
    93         kx     clean_exit(1)
    93         kx