#!/usr/bin/python3 # -*- coding: utf-8 -*- # # (c) Copyright 2003-2015 HP Development Company, L.P. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # Author: Don Welch # # Std Lib import sys import os import os.path import re import time import grp import pwd import tarfile import stat import glob import hashlib def get_checksum(s): return hashlib.sha256(s).hexdigest() # Local from base.g import * from base.codes import * from base import utils, tui, password, services, os_utils from .dcheck import * DISTRO_UNKNOWN = 0 DISTRO_VER_UNKNOWN = '0.0' MODE_INSTALLER = 0 # hplip-install/hp-setup MODE_CHECK = 1 # hp-check MODE_CREATE_DOCS = 2 # create_docs TYPE_STRING = 1 TYPE_LIST = 2 TYPE_BOOL = 3 TYPE_INT = 4 DEPENDENCY_RUN_TIME = 1 DEPENDENCY_COMPILE_TIME = 2 DEPENDENCY_RUN_AND_COMPILE_TIME = 3 DEPENDENCY_REQUIRED_INDEX = 0 DEPENDENCY_DISPLAY_INDEX = 2 # Mapping from patterns to probability contribution of pattern # Example code from David Mertz' Text Processing in Python. # Released in the Public Domain. err_pats = {r'(?is).*?(404|403).*?ERROR.*?': 0.95, r'(?is).*?ERROR.*?(404|403).*?': 0.95, r'(?is)ERROR': 0.30, r'(?is).*?ERROR.*?': 0.10, r'(?is)': 0.80, r'(?is)': 0.80, r'(?is).*?File Not Found.*?': 0.80, r'(?is).*?Not Found.*?': 0.40, r'(?is)': 0.10, r'(?is)

.*?(404|403).*?

': 0.15, r'(?is)': 0.10, r'(?is)

.*?not found.*?

': 0.15, r'(?is)': 0.10, r'(?is)': 0.10, r'(?is)': 0.10, r'(?is)': 0.10, r'(?i)does not exist': 0.10, } # Note:- If new utility is added, add same utility here to uninstall properly. BINS_LIST = ['hpijs', 'hp-align', 'hp-colorcal', 'hp-faxsetup', 'hp-linefeedcal', 'hp-pkservice', 'hp-printsettings', 'hp-sendfax', 'hp-timedate', 'hp-check', 'hp-devicesettings', 'hp-firmware', 'hp-makecopies', 'hp-plugin', 'hp-probe', 'hp-setup', 'hp-toolbox', 'hp-check-plugin', 'hp-diagnose_plugin', 'hp-info', 'hp-makeuri', 'hp-pqdiag', 'hp-query', 'hp-systray', 'hp-unload', 'hp-clean', 'hp-fab', 'hp-levels', 'hp-print', 'hp-scan', 'hp-testpage', 'hp-wificonfig', 'hp-upgrade', 'hplip-info', 'hp-check-upgrade', 'hp-config_usb_printer', 'hp-diagnose_queues', 'hp-devicesetup', 'hp-doctor', 'hp-logcapture'] LIBS_LIST = ['libhpmud.*', 'libhpip.*', 'sane/libsane-hpaio.*', 'cups/backend/hp', 'cups/backend/hpfax', 'cups/filter/hpcac','sane/libsane-hp2000S1*', 'libjpeg*', 'cups/filter/hpps', 'cups/filter/pstotiff', 'cups/filter/hpcups', 'cups/filter/hpcupsfax', 'cups/filter/hplipjs'] HPLIP_EXT_LIST = ['cupsext.so', 'cupsext.la', 'scanext.so', 'scanext.la', 'hpmudext.so', 'hpmudext.la', 'pcardext.so', 'pcardext.la'] FILES_LIST = ['/usr/share/cups/drv/hp/', '/usr/local/share/ppd/HP/', '/usr/local/share/cups/drv/hp/', '/usr/share/applications/hplip.desktop', '/usr/share/applications/hp-uiscan.desktop', '/etc/xdg/autostart/hplip-systray.desktop', '/etc/hp/hplip.conf', '/usr/share/doc/hplip-*', '/usr/lib/systemd/system/hplip-printer*.service'] RULES_LIST = ['56-hpmud.rules', '56-hpmud_sysfs.rules', '40-hplip.rules', '56-hpmud_support.rules', '56-hpmud_support_sysfs.rules', '55-hpmud.rules','S99-2000S1.rules', '55-hpmud_sysfs.rules', '56-hpmud_add_printer.rules', '56-hpmud_add_printer_sysfs.rules', '86-hpmud-hp_*.rules', '86-hpmud_plugin.rules', '86-hpmud_plugin_sysfs.rules'] HPLIP_LIST = ['*.py', '*.pyc', 'base', 'copier', 'data', 'installer', 'pcard', 'ui4', 'ui', 'fax/*.py', 'fax/*.pyc', 'fax/pstotiff.convs', 'fax/pstotiff.types', 'fax/pstotiff', 'prnt/*.py', 'prnt/*.pyc', 'scan/*.py', 'scan/*.pyc'] PLUGIN_LIST = ['fax/plugins/', 'prnt/plugins/', 'scan/plugins/'] PLUGIN_STATE = ['/var/lib/hp/hplip.state'] # end OK_PROCESS_LIST = ['adept-notifier', 'adept_notifier', 'yum-updatesd', ] CONFIGURE_ERRORS = {1: "General/unknown error", 2: "libusb not found", 3: "cups-devel not found", 4: "libnetsnmp not found", 5: "netsnmp-devel not found", 6: "python-devel not found", 7: "pthread-devel not found", 8: "ppdev-devel not found", 9: "libcups not found", 10: "libm not found", 11: "libusb-devel not found", 12: "sane-backends-devel not found", 13: "libdbus not found", 14: "dbus-devel not found", 15: "fax requires dbus support", 102: "libjpeg not found", 103: "jpeg-devel not found", 104: "libdi not found", } EXTERNALDEP = 1 GENERALDEP = 2 COMPILEDEP = 3 PYEXT = 4 SCANCONF = 5 JPEG_STR = "libjpeg - JPEG library" LIBTOOL_STR = "libtool - Library building support services" CUPS_STR = "CUPS - Common Unix Printing System" CUPS_DEV_STR = "CUPS devel- Common Unix Printing System development files" CUPS_IMG_STR = "CUPS image - CUPS image development files" GCC_STR = "gcc - GNU Project C and C++ Compiler" MAKE_STR = "make - GNU make utility to maintain groups of programs" THREAD_STR = "libpthread - POSIX threads library" GS_STR = "GhostScript - PostScript and PDF language interpreter and previewer" USB_STR = "libusb - USB library" CUPS_DDK_STR = "CUPS DDK - CUPS driver development kit" SANE_STR = "SANE - Scanning library" SANE_DEV_STR = "SANE - Scanning library development files" XSANE_STR = "xsane - Graphical scanner frontend for SANE" SCANIMAGE_STR = "scanimage - Shell scanning program" DBUS_STR = "DBus - Message bus system" POLKIT_STR = "PolicyKit - Administrative policy framework" SNMP_DEV_STR = "libnetsnmp-devel - SNMP networking library development files" CRYPTO_STR = "libcrypto - OpenSSL cryptographic library" NETWORK_STR = "network -wget" AVAHI_STR = "avahi-utils" PYTHON_STR = "Python 2.2 or greater - Python programming language" PYNTF_STR = "Python libnotify - Python bindings for the libnotify Desktop notifications" QT4DBUS_STR = "PyQt 4 DBus - DBus Support for PyQt4" QT4_STR = "PyQt 4- Qt interface for Python (for Qt version 4.x)" QT5DBUS_STR = "PyQt 5 DBus - DBus Support for PyQt5" QT5_STR = "PyQt 5- Qt interface for Python (for Qt version 4.x)" PYDBUS_STR = "Python DBus - Python bindings for DBus" PYXML_STR = "Python XML libraries" PY_DEV_STR = "Python devel - Python development files" PIL_STR = "PIL - Python Imaging Library (required for commandline scanning with hp-scan)" PIP_STR = "PIP - preferred installer program" TESS_STR = "Tesseract - Tesseract library for python" TESSEROCR_STR = "Tesserocr - Optical-character-recognition tesseract library for python" IMUTILS_STR = "Imutils - A series of basic image processing functions" OPENCV_STR = "Opencv - opencv library for python" ZBAR_STR = "ZBAR -zbar library for python" LEPTO_STR = "leptonica - leptonica library for python" #SETUPTOOLS_STR = "setuptools - library designed to facilitate packaging Python projects" PYPDF2_STR = "pypdf2 - pdf library for python" REPORTLAB_STR = "Reportlab - PDF library for Python" CUPSEXT_STR = 'CUPS-Extension' HPMUDEXT_STR = 'IO-Extension' HPAIO_STR = 'HPLIP-SANE-Backend' SCANEXT_STR = 'Scan-SANE-Extension' QT_STR = "Python-Qt" EPM_STR = "Build Debian Package" AUTOMAKE_STR = "Build Driver" LIB_AVAHI="libavahi-dev" APPARMOR_DIR = "/etc/apparmor.d" SELINUX_DIR = "/etc/selinux/targeted/policy/policy*" SEC_DICT = {"AppArmor": (APPARMOR_DIR, ["/etc/apparmor.d/usr.share.hplip", "/etc/apparmor.d/abstractions/hplip"]), "SELinux": (SELINUX_DIR, ["/etc/selinux/targeted/modules/active/modules/hplip.pp"]) } try: from functools import update_wrapper except ImportError: # using Python version < 2.5 def trace(f): def newf(*args, **kw): log.debug("TRACE: func=%s(), args=%s, kwargs=%s" % (f.__name__, args, kw)) return f(*args, **kw) newf.__name__ = f.__name__ newf.__dict__.update(f.__dict__) newf.__doc__ = f.__doc__ newf.__module__ = f.__module__ return newf else: # using Python 2.5+ def trace(f): def newf(*args, **kw): log.debug("TRACE: func=%s(), args=%s, kwargs=%s" % (f.__name__, args, kw)) return f(*args, **kw) return update_wrapper(newf, f) class CoreInstall(object): def __init__(self, mode=MODE_INSTALLER, ui_mode=INTERACTIVE_MODE, ui_toolkit='qt4'): os.umask(0o022) self.mode = mode self.ui_mode = ui_mode self.passwordObj = password.Password(ui_mode) self.version_description, self.version_public, self.version_internal = '', '', '' self.bitness = 32 self.endian = utils.LITTLE_ENDIAN self.distro, self.distro_name, self.distro_version = DISTRO_UNKNOWN, '', DISTRO_VER_UNKNOWN self.distro_version_supported = False self.install_location = '/usr' self.hplip_present = False self.have_dependencies = {} self.native_cups = True self.ppd_dir = None self.drv_dir = None self.distros = {} self.ui_toolkit = ui_toolkit self.enable = None self.disable = None self.reload_dbus = False self.security_package = "" self.FIELD_TYPES = { 'distros': TYPE_LIST, 'index': TYPE_INT, 'versions': TYPE_LIST, 'display_name': TYPE_STRING, 'alt_names': TYPE_LIST, 'display': TYPE_BOOL, 'notes': TYPE_STRING, 'package_mgrs': TYPE_LIST, 'package_mgr_cmd': TYPE_STRING, 'pre_install_cmd': TYPE_LIST, 'pre_depend_cmd': TYPE_LIST, 'post_depend_cmd': TYPE_LIST, 'scanjet_depend_cmd': TYPE_LIST, 'scanjet_py3_depend_cmd': TYPE_LIST, 'hpoj_remove_cmd': TYPE_STRING, 'hplip_remove_cmd': TYPE_STRING, 'su_sudo': TYPE_STRING, 'ppd_install': TYPE_STRING, 'udev_mode_fix': TYPE_BOOL, 'ppd_dir': TYPE_STRING, 'drv_dir': TYPE_STRING, 'fix_ppd_symlink': TYPE_BOOL, 'code_name': TYPE_STRING, 'supported': TYPE_BOOL, # Supported by installer 'release_date': TYPE_STRING, 'packages': TYPE_LIST, 'commands': TYPE_LIST, 'same_as_version': TYPE_STRING, 'scan_supported': TYPE_BOOL, 'fax_supported': TYPE_BOOL, 'pcard_supported': TYPE_BOOL, 'network_supported': TYPE_BOOL, 'parallel_supported': TYPE_BOOL, 'usb_supported': TYPE_BOOL, 'packaged_version': TYPE_STRING, # Version of HPLIP pre-packaged in distro 'cups_path_with_bitness': TYPE_BOOL, 'ui_toolkit': TYPE_STRING, # qt3 or qt4 [or gtk] or none 'policykit': TYPE_BOOL, 'libusb01': TYPE_BOOL, 'udev_sysfs_rule': TYPE_BOOL, 'native_cups': TYPE_BOOL, 'package_available': TYPE_BOOL, 'package_arch': TYPE_LIST, 'open_mdns_port': TYPE_LIST, # command to use to open mdns multicast port 5353 'libdir_path': TYPE_STRING, 'hp_libs_remove_cmd': TYPE_STRING, } # components # 'name': ('description', [