/usr/share/hplip/installer/dcheck.py is in hplip-data 3.16.3+repack0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 | # -*- 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 os
import os.path
import re
import sys
from subprocess import Popen, PIPE
import codecs
# Local
from base.g import *
from base import utils, services
from base.sixext import to_bytes_utf8
ver1_pat = re.compile("""(\d+\.\d+\.\d+)""", re.IGNORECASE)
ver_pat = re.compile("""(\d+.\d+)""", re.IGNORECASE)
PID = 0
CMDLINE = 1
ld_output = ''
#ps_output = ''
mod_output = ''
def update_ld_output():
# For library checks
global ld_output
status, ld_output = utils.run('%s -p' % os.path.join(utils.which('ldconfig'), 'ldconfig'), log_output=False)
if status != 0:
log.debug("ldconfig failed.")
def check_tool(cmd, min_ver=0.0):
log.debug("Checking: %s (min ver=%f)" % (cmd, min_ver))
status, output = utils.run(cmd)
if status != 0:
log.debug("Not found!")
return False
else:
if min_ver:
try:
line = output.splitlines()[0]
except IndexError:
line = ''
log.debug(line)
match_obj = ver_pat.search(line)
try:
ver = match_obj.group(1)
except AttributeError:
ver = ''
try:
v_f = float(ver)
except ValueError:
return False
else:
log.debug("Ver=%f Min ver=%f" % (v_f, min_ver))
if v_f < min_ver:
log.debug("Found, but newer version required.")
return v_f >= min_ver
else:
log.debug("Found.")
return True
def check_lib(lib, min_ver=0):
log.debug("Checking for library '%s'..." % lib)
if ld_output.find(lib) >= 0:
log.debug("Found.")
#if min_ver:
# pass
#else:
return True
else:
log.debug("Not found.")
return False
def check_file(f, dir="/usr/include"):
log.debug("Searching for file '%s' in '%s'..." % (f, dir))
for w in utils.walkFiles(dir, recurse=True, abs_paths=True, return_folders=False, pattern=f):
log.debug("File found at '%s'" % w)
return True
log.debug("File not found.")
return False
def locate_files(f, dir):
log.debug("Searching for file(s) '%s' in '%s'..." % (f, dir))
found = []
for w in utils.walkFiles(dir, recurse=True, abs_paths=True, return_folders=False, pattern=f):
log.debug(w)
found.append(w)
if found:
log.debug("Found files: %s" % found)
else:
log.debug("No files not found.")
return found
def locate_file_contains(f, dir, s):
"""
Find a list of files located in a directory
that contain a specified sub-string.
"""
log.debug("Searching for file(s) '%s' in '%s' that contain '%s'..." % (f, dir, s))
found = []
for w in utils.walkFiles(dir, recurse=True, abs_paths=True, return_folders=False, pattern=f):
if check_file_contains(w, s):
log.debug(w)
found.append(w)
if found:
log.debug("Found files: %s" % found)
else:
log.debug("No files not found.")
return found
def check_file_contains(f, s):
log.debug("Checking file '%s' for contents '%s'..." % (f, s))
try:
if os.path.exists(f):
s = to_bytes_utf8(s)
for a in open(f, 'rb'):
update_spinner()
if s in a:
log.debug("'%s' found in file '%s'." % (s.replace(b'\n', b''), f))
return True
log.debug("Contents not found.")
return False
finally:
cleanup_spinner()
def check_ps(process_list):
if process_list is not None:
log.debug("Searching for '%s' in running processes..." % process_list)
try:
for p in process_list:
update_spinner()
status,process = utils.Is_Process_Running(p)
if status is True:
for p in process:
log.debug("Found: %s (%s)" % (process[p], p))
return True
log.debug("Not found")
return False
finally:
cleanup_spinner()
def get_ps_pid(process_name_list):
processes_list = {}
if process_name_list is not None:
log.debug("Searching for '%s' in running processes..." % process_name_list)
try:
for p in process_name_list:
update_spinner()
status,processes = utils.Is_Process_Running(p)
if status is True:
log.debug("Found: %d processes" % len(processes))
for pid in processes:
processes_list[pid] =processes[pid]
else:
log.debug("Not found")
finally:
cleanup_spinner()
return processes_list
def check_lsmod(module):
global mod_output
if not mod_output:
lsmod = utils.which('lsmod')
status, mod_output = utils.run(os.path.join(lsmod, 'lsmod'), log_output=False)
return mod_output.find(module) >= 0
def check_version(inst_ver_str, min_ver_str='0.0'):
log.debug("Checking: installed ver=%s min ver=%s" % (inst_ver_str, min_ver_str))
min_ver = 0
if min_ver_str != '-':
match_obj=ver_pat.search(min_ver_str)
try:
ver = match_obj.group(1)
except AttributeError:
ver = ''
try:
min_ver = float(ver)
except ValueError:
min_ver = 0
inst_ver = 0
if inst_ver_str != '-':
match_obj=ver_pat.search(inst_ver_str)
try:
ver = match_obj.group(1)
except AttributeError:
ver = ''
try:
inst_ver = float(ver)
except ValueError:
inst_ver = 0
if inst_ver < min_ver:
log.debug("Found, but newer version required.")
return False
else:
log.debug("Found.")
return True
def get_version(cmd,def_ver='-'):
log.debug("Checking: %s" % (cmd))
status, output = utils.run(cmd)
if status != 0:
log.debug("Not found!")
return def_ver
else:
try:
line = output.splitlines()[0]
except IndexError:
line = ''
log.debug(line)
match_obj = ver1_pat.search(line)
try:
ver = match_obj.group(1)
except AttributeError:
match_obj = ver_pat.search(line)
try:
ver = match_obj.group(1)
except AttributeError:
return def_ver
else:
return ver
else:
return ver
def get_python_dbus_ver():
try:
import dbus
dbus_version ="-"
try:
dbus_version = dbus.__version__
except AttributeError:
try:
dbus_version = '.'.join([str(x) for x in dbus.version])
except AttributeError:
dbus_version = '-'
except ImportError:
dbus_version = '-'
return dbus_version
def get_pyQt4_version():
log.debug("Checking PyQt 4.x version...")
ver ='-'
# PyQt 4
try:
import PyQt4
except ImportError:
ver='-'
else:
from PyQt4 import QtCore
ver = QtCore.PYQT_VERSION_STR
return ver
def get_reportlab_version():
try:
log.debug("Trying to import 'reportlab'...")
import reportlab
ver = str(reportlab.Version)
except ImportError:
return '-'
else:
return ver
def get_pyQt_version():
log.debug("Checking PyQt 3.x version...")
# PyQt 3
try:
import qt
except ImportError:
return '-'
else:
#check version of PyQt
try:
pyqtVersion = qt.PYQT_VERSION_STR
except AttributeError:
pyqtVersion = qt.PYQT_VERSION
while pyqtVersion.count('.') < 2:
pyqtVersion += '.0'
return pyqtVersion
def get_xsane_version():
installed_ver='-'
try:
p1 = Popen(["xsane", "--version","2",">","/dev/null"], stdout=PIPE)
except:
output =None
else:
output=p1.communicate()[0].decode('utf-8')
if output:
xsane_ver_pat =re.compile('''xsane-(\d{1,}\.\d{1,}).*''')
xsane_ver_info = output.splitlines()[0]
if xsane_ver_pat.search(xsane_ver_info):
installed_ver = xsane_ver_pat.search(xsane_ver_info).group(1)
return installed_ver
def get_pil_version():
try:
from PIL import Image
except ImportError:
return '-'
else:
return Image.VERSION
def get_libpthread_version():
try:
import sys, ctypes, ctypes.util
except ImportError:
return '-'
else:
# LIBC = ctypes.CDLL(ctypes.util.find_library('c'), use_errno=True)
LIBC = ctypes.CDLL(ctypes.util.find_library('c'),ctypes.DEFAULT_MODE,None, True)
LIBC.gnu_get_libc_version.restype = ctypes.c_char_p
return LIBC.gnu_get_libc_version()
def get_python_xml_version():
try:
import xml.parsers.expat
except ImportError:
return '-'
else:
return '.'.join([str(x) for x in xml.parsers.expat.version_info])
def get_HPLIP_version():
return prop.version
def get_libusb_version():
if sys_conf.get('configure', 'libusb01-build', 'no') == "yes":
return get_version('libusb-config --version')
else:
return '1.0'
|