summaryrefslogtreecommitdiff
path: root/base
diff options
context:
space:
mode:
authorDidier Raboud <odyx@debian.org>2016-01-04 16:46:34 +0100
committerDidier Raboud <odyx@debian.org>2016-01-04 16:46:34 +0100
commita1938dae45b2a247f56886d4d2b867e552830238 (patch)
treebf2e2a899129eb429da7ebf01b20b80b05a9c3ca /base
parent7ba580c5353f4c535bdabbe620b625a0db7fa2d9 (diff)
Imported Upstream version 2.8.6
Diffstat (limited to 'base')
-rw-r--r--base/codes.py7
-rw-r--r--base/device.py78
-rw-r--r--base/ldif.py2
-rw-r--r--base/logger.py11
-rw-r--r--base/models.py159
-rw-r--r--base/status.py2
-rw-r--r--base/tui.py18
-rw-r--r--base/utils.py2
8 files changed, 222 insertions, 57 deletions
diff --git a/base/codes.py b/base/codes.py
index 0f7ed9188..478a1fc96 100644
--- a/base/codes.py
+++ b/base/codes.py
@@ -578,6 +578,7 @@ SUPPORT_TYPE_HPIJS = 1
SUPPORT_TYPE_HPLIP = 2
# fax-types
+FAX_TYPE_NOT_SUPPORTED = -1
FAX_TYPE_NONE = 0
FAX_TYPE_BLACK_SEND_EARLY_OPEN = 1 # newer models
FAX_TYPE_BLACK_SEND_LATE_OPEN = 2 # older models
@@ -590,6 +591,7 @@ PCARD_TYPE_MLC = 1
PCARD_TYPE_USB_MASS_STORAGE = 2
# scan-types
+SCAN_TYPE_NOT_SUPPORTED = -1
SCAN_TYPE_NONE = 0
SCAN_TYPE_SCL = 1
SCAN_TYPE_PML = 2
@@ -603,6 +605,7 @@ SCAN_STYLE_FLATBED = 1
SCAN_STYLE_SCROLLFED = 2
# copy-types
+COPY_TYPE_NOT_SUPPORTED = -1
COPY_TYPE_NONE = 0
COPY_TYPE_DEVICE = 1 # LaserJet MFP PML
COPY_TYPE_SCAN_TO_PRINT = 2
@@ -647,7 +650,7 @@ IO_SUPPORT_NETWORK = 0x4
IO_SUPPORT_WIRELESS = 0x8
IO_SUPPORT_BLUETOOTH = 0x10
-# New more user friendly model categories
+# User friendly model categories
MODEL_TYPE2_UNSUPPORTED = 0
MODEL_TYPE2_DESKJET = 1
MODEL_TYPE2_DESKJET_AIO = 2
@@ -661,7 +664,7 @@ MODEL_TYPE2_EDGELINE = 9
MODEL_TYPE2_APOLLO = 10
MODEL_TYPE2_SCANJET = 11 # not supported
MODEL_TYPE2_DESIGNJET = 12 # not supported
-MODEL_TYPE2_OTHER = 13 # No specific "sub-brand" (e.g., 910)
+MODEL_TYPE2_OTHER = 13 # No specific "sub-brand" (e.g., 910, cp1610)
# 'io-mode' and 'io-mfp-mode'
IO_MODE_UNI = 0
diff --git a/base/device.py b/base/device.py
index 05349bb4f..3c25afd0f 100644
--- a/base/device.py
+++ b/base/device.py
@@ -162,8 +162,8 @@ def init_dbus():
log.warn("Unable to start hp-systray")
return False, None
- log.debug("Running hp-systray: %s" % path)
- os.spawnvp(os.P_NOWAIT, path, [])
+ log.debug("Running hp-systray: %s --force-startup" % path)
+ os.spawnlp(os.P_NOWAIT, path, 'hp-systray', '--force-startup')
log.debug("Waiting for hp-systray to start...")
time.sleep(1)
@@ -298,7 +298,7 @@ def makeURI(param, port=1):
def queryModelByModel(model):
- model = normalizeModelName(model).lower()
+ model = models.normalizeModelName(model).lower()
return model_dat[model]
def queryModelByURI(device_uri):
@@ -467,7 +467,7 @@ def probeDevices(bus=DEFAULT_PROBE_BUS, timeout=10,
if dev is not None and dev != '0':
device_id = parseDeviceID(dev)
- model = normalizeModelName(device_id.get('MDL', '?UNKNOWN?'))
+ model = models.normalizeModelName(device_id.get('MDL', '?UNKNOWN?'))
if num_ports_on_jd == 1:
device_uri = 'hp:/net/%s?ip=%s' % (model, ip)
@@ -668,7 +668,7 @@ def parseDeviceURI(device_uri):
m = pat_deviceuri.match(device_uri)
if m is None:
- log.debug("Device URI %s is invalid/unknown")
+ log.debug("Device URI %s is invalid/unknown" % device_uri)
raise Error(ERROR_INVALID_DEVICE_URI)
back_end = m.group(1).lower() or ''
@@ -676,7 +676,7 @@ def parseDeviceURI(device_uri):
bus = m.group(2).lower() or ''
if bus not in ('usb', 'net', 'bt', 'fw', 'par'):
- log.debug("Device URI %s is invalid/unknown")
+ log.debug("Device URI %s is invalid/unknown" % device_uri)
raise Error(ERROR_INVALID_DEVICE_URI)
model = m.group(3) or ''
@@ -845,38 +845,38 @@ AGENT_levels = {AGENT_LEVEL_TRIGGER_MAY_BE_LOW : 'low',
}
-MODEL_UI_REPLACEMENTS = {'laserjet' : 'LaserJet',
- 'psc' : 'PSC',
- 'officejet' : 'Officejet',
- 'deskjet' : 'Deskjet',
- 'hp' : 'HP',
- 'business' : 'Business',
- 'inkjet' : 'Inkjet',
- 'photosmart' : 'Photosmart',
- 'color' : 'Color',
- 'series' : 'series',
- 'printer' : 'Printer',
- 'mfp' : 'MFP',
- 'mopier' : 'Mopier',
- 'pro' : 'Pro',
- }
-
-
-def normalizeModelUIName(model):
- if not model.lower().startswith('hp'):
- z = 'HP ' + model.replace('_', ' ')
- else:
- z = model.replace('_', ' ')
-
- y = []
- for x in z.split():
- xx = x.lower()
- y.append(MODEL_UI_REPLACEMENTS.get(xx, xx))
-
- return ' '.join(y)
+##MODEL_UI_REPLACEMENTS = {'laserjet' : 'LaserJet',
+## 'psc' : 'PSC',
+## 'officejet' : 'Officejet',
+## 'deskjet' : 'Deskjet',
+## 'hp' : 'HP',
+## 'business' : 'Business',
+## 'inkjet' : 'Inkjet',
+## 'photosmart' : 'Photosmart',
+## 'color' : 'Color',
+## 'series' : 'series',
+## 'printer' : 'Printer',
+## 'mfp' : 'MFP',
+## 'mopier' : 'Mopier',
+## 'pro' : 'Pro',
+## }
+
+
+##def normalizeModelUIName(model):
+## if not model.lower().startswith('hp'):
+## z = 'HP ' + model.replace('_', ' ')
+## else:
+## z = model.replace('_', ' ')
+##
+## y = []
+## for x in z.split():
+## xx = x.lower()
+## y.append(models.MODEL_UI_REPLACEMENTS.get(xx, xx))
+##
+## return ' '.join(y)
-def normalizeModelName(model):
- return utils.xstrip(model.replace(' ', '_').replace('__', '_').replace('~','').replace('/', '_'), '_')
+##def normalizeModelName(model):
+## return utils.xstrip(model.replace(' ', '_').replace('__', '_').replace('~','').replace('/', '_'), '_')
def isLocal(bus):
@@ -943,8 +943,8 @@ class Device(object):
log.debug("URI: backend=%s, is_hp=%s, bus=%s, model=%s, serial=%s, dev=%s, host=%s, port=%d" % \
(self.back_end, self.is_hp, self.bus, self.model, self.serial, self.dev_file, self.host, self.port))
- self.model_ui = normalizeModelUIName(self.model)
- self.model = normalizeModelName(self.model)
+ self.model_ui = models.normalizeModelUIName(self.model)
+ self.model = models.normalizeModelName(self.model)
log.debug("Model/UI model: %s/%s" % (self.model, self.model_ui))
diff --git a/base/ldif.py b/base/ldif.py
index 7608d4128..a3b8eb2d5 100644
--- a/base/ldif.py
+++ b/base/ldif.py
@@ -391,7 +391,7 @@ class LDIFParser:
while attr_type is not None and attr_value is not None:
attr_type = attr_type.lower()
- print "--->", repr(attr_type), repr(attr_value)
+ log.debug("%s ---> %s" % (repr(attr_type), repr(attr_value)))
if not attr_type or not attr_value:
attr_type, attr_value = self._parseAttrTypeandValue()
diff --git a/base/logger.py b/base/logger.py
index 588c0208f..869a7a665 100644
--- a/base/logger.py
+++ b/base/logger.py
@@ -37,6 +37,7 @@ DEFAULT_LOG_LEVEL = 'info'
class Logger(object):
LOG_LEVEL_NONE = 99
+ #LOG_LEVEL_INFO = 50
LOG_LEVEL_FATAL = 40
LOG_LEVEL_ERROR = 30
LOG_LEVEL_WARN = 20
@@ -98,7 +99,7 @@ class Logger(object):
def __init__(self, module='', level=LOG_LEVEL_INFO, where=LOG_TO_CONSOLE_AND_FILE,
log_datetime=False, log_file=None):
- self.set_level(level)
+
self._where = where
self._log_file = log_file
self._log_file_f = None
@@ -107,9 +108,10 @@ class Logger(object):
self.module = module
self.pid = os.getpid()
self.fmt = True
-
+ self.set_level(level)
+
def set_level(self, level):
- if isinstance(level,str):
+ if isinstance(level, str):
level = level.lower()
if level in Logger.logging_levels.keys():
self._level = Logger.logging_levels.get(level, Logger.LOG_LEVEL_INFO)
@@ -118,10 +120,11 @@ class Logger(object):
self.error("Invalid logging level: %s" % level)
return False
- elif isinstance(level,int):
+ elif isinstance(level, int):
if Logger.LOG_LEVEL_DEBUG3 <= level <= Logger.LOG_LEVEL_FATAL:
self._level = level
else:
+ self._level = Logger.LOG_LEVEL_ERROR
self.error("Invalid logging level: %d" % level)
return False
diff --git a/base/models.py b/base/models.py
index 2f4a4537d..071040697 100644
--- a/base/models.py
+++ b/base/models.py
@@ -26,6 +26,8 @@ import os.path
import re
import glob
+pat_prod_num = re.compile("""(\d+)""", re.I)
+
TYPE_UNKNOWN = 0
TYPE_STRING = 1
TYPE_STR = 1
@@ -35,6 +37,156 @@ TYPE_INT = 4
TYPE_HEX = 5
TYPE_BITFIELD = 6
+TECH_CLASSES = [
+ "Undefined",
+ "Postscript",
+ "DJGenericVIP",
+ #"PSB9100", not used on HPLIP
+ "LJMono",
+ "LJColor",
+ "LJFastRaster",
+ "LJJetReady",
+ "DJ350",
+ #"DJ400", not used on HPLIP
+ "DJ540",
+ "DJ600",
+ "DJ6xx",
+ "DJ6xxPhoto",
+ "DJ630",
+ #"DJ660", not used in HPLIP
+ "DJ8xx",
+ "DJ8x5",
+ "DJ850",
+ "DJ890",
+ "DJ9xx",
+ "DJ9xxVIP",
+ "DJ3600",
+ "DJ3320",
+ "DJ4100",
+ "AP2xxx",
+ "AP21xx",
+ "AP2560",
+ "PSP100",
+ "PSP470",
+ "LJZjsMono",
+ "LJZjsColor",
+ "LJm1005",
+ "QuickConnect",
+ "DJ55xx",
+ "OJProKx50",
+]
+
+TECH_CLASSES.sort()
+
+TECH_CLASS_PDLS = {
+ #"Undefined" : '?',
+ "Postscript" : 'ps',
+ "DJGenericVIP" : 'pcl3',
+ #"PSB9100" : 'pcl3',
+ "LJMono" : 'pcl3',
+ "LJColor" : 'pcl3',
+ "LJFastRaster" : 'pclxl',
+ "LJJetReady" : 'pclxl',
+ "DJ350" : 'pcl3',
+ #"DJ400" : 'pcl3',
+ "DJ540" : 'pcl3',
+ "DJ600" : 'pcl3',
+ "DJ6xx" : 'pcl3',
+ "DJ6xxPhoto" : 'pcl3',
+ "DJ630" : 'pcl3',
+ #"DJ660" : 'pcl3',
+ "DJ8xx" : 'pcl3',
+ "DJ8x5" : 'pcl3',
+ "DJ850" : 'pcl3',
+ "DJ890" : 'pcl3',
+ "DJ9xx" : 'pcl3',
+ "DJ9xxVIP" : 'pcl3',
+ "DJ3600" : 'lidil',
+ "DJ3320" : 'lidil',
+ "DJ4100" : 'lidil',
+ "AP2xxx" : 'pcl3',
+ "AP21xx" : 'pcl3',
+ "AP2560" : 'pcl3',
+ "PSP100" : 'pcl3',
+ "PSP470" : 'pcl3',
+ "LJZjsMono" : 'zjs',
+ "LJZjsColor" : 'zjs',
+ "LJm1005" : 'zxstream',
+ "QuickConnect" : 'jpeg',
+ "DJ55xx" : 'pcl3',
+ "OJProKx50" : 'pcl3',
+}
+
+
+TECH_SUBCLASSES = [
+ "LargeFormatSuperB",
+ "LargeFormatA3",
+ "CoverMedia", # 3425
+ "FullBleed",
+ "Duplex",
+ "Normal",
+ "Apollo2000",
+ "Apollo2200",
+ "Apollo2500",
+ "NoPhotoMode",
+ "NoPhotoBestHiresModes",
+ "No1200dpiNoSensor",
+ "NoFullBleed",
+ "4x6FullBleed",
+ "300dpiOnly", # LaserJet 4L
+ "GrayscaleOnly", # DJ540
+]
+
+TECH_SUBCLASSES.sort()
+
+
+# Items will be capitalized unless in this dict
+MODEL_UI_REPLACEMENTS = {'laserjet' : 'LaserJet',
+ 'psc' : 'PSC',
+ 'officejet' : 'Officejet',
+ 'deskjet' : 'Deskjet',
+ 'hp' : 'HP',
+ 'business' : 'Business',
+ 'inkjet' : 'Inkjet',
+ 'photosmart' : 'Photosmart',
+ 'color' : 'Color',
+ 'series' : 'series',
+ 'printer' : 'Printer',
+ 'mfp' : 'MFP',
+ 'mopier' : 'Mopier',
+ 'pro' : 'Pro',
+ 'apollo' : 'Apollo',
+ }
+
+
+def normalizeModelUIName(model):
+ ml = model.lower().strip()
+
+ if 'apollo' in ml:
+ z = ml.replace('_', ' ')
+ else:
+ if ml.startswith("hp"):
+ z = ml[3:].replace('_', ' ')
+ else:
+ z = ml.replace('_', ' ')
+
+ y = []
+ for x in z.split():
+ if pat_prod_num.search(x): # don't cap items like cp1700dn
+ y.append(x)
+ else:
+ y.append(MODEL_UI_REPLACEMENTS.get(x, x.capitalize()))
+
+ if 'apollo' in ml:
+ return ' '.join(y)
+ else:
+ return "HP " + ' '.join(y)
+
+
+def normalizeModelName(model):
+ return utils.xstrip(model.replace(' ', '_').replace('__', '_').replace('~','').replace('/', '_'), '_')
+
+
class ModelData:
def __init__(self, root_path=None):
if root_path is None:
@@ -65,7 +217,6 @@ class ModelData:
'panel-check-type' : TYPE_INT,
'pcard-type' : TYPE_INT,
'plugin' : TYPE_INT,
- 'plugin-library' : TYPE_STR,
'power-settings': TYPE_INT,
'pq-diag-type' : TYPE_INT,
'r-type' : TYPE_INT,
@@ -77,7 +228,8 @@ class ModelData:
'support-released' : TYPE_BOOL,
'support-type' : TYPE_INT,
'support-ver' : TYPE_STR,
- 'tech-class' : TYPE_STR,
+ 'tech-class' : TYPE_LIST,
+ 'tech-subclass' : TYPE_LIST,
'tech-type' : TYPE_INT,
'usb-pid' : TYPE_HEX,
'usb-vid' : TYPE_HEX,
@@ -203,6 +355,9 @@ class ModelData:
#value = utils.to_bool(value)
value = int(value)
+ elif typ == TYPE_LIST:
+ value = [x for x in value.split(',') if x]
+
cache[read_section][key] = value
fd.close()
diff --git a/base/status.py b/base/status.py
index 0661a9f83..5f82c9e99 100644
--- a/base/status.py
+++ b/base/status.py
@@ -740,7 +740,7 @@ def BatteryCheck(dev, status_block, battery_check):
status_block['agents'].append({
'kind' : AGENT_KIND_INT_BATTERY,
'type' : AGENT_TYPE_UNSPECIFIED,
- 'health' : AGENT_HEALTH_UNKNOWN,
+ 'health' : AGENT_HEALTH_OK,
'level' : battery_level,
'level-trigger' : AGENT_LEVEL_TRIGGER_SUFFICIENT_0,
})
diff --git a/base/tui.py b/base/tui.py
index d86cd206e..dcffac289 100644
--- a/base/tui.py
+++ b/base/tui.py
@@ -36,7 +36,7 @@ def enter_yes_no(question, default_value='y', choice_prompt=None):
else:
default_value = False
- assert default_value in [True, False]
+ #assert default_value in [True, False]
if choice_prompt is None:
if default_value:
@@ -103,7 +103,7 @@ def enter_choice(question, choices, default_value=None):
else:
return True, default_value
- print user_input
+ #print user_input
if user_input == 'q':
return False, user_input
@@ -278,23 +278,24 @@ class Formatter(object):
col_widths = []
formats = []
- for m1, m2, m3, m4 in zip(self.min_widths, min_calc_widths, self.max_widths, max_calc_widths):
+ for m1, m2, m3, m4 in zip(self.min_widths, min_calc_widths,
+ self.max_widths, max_calc_widths):
col_width = max(max(m1, m2), min(m3, m4))
col_widths.append(col_width)
formats.append({'width': col_width, 'margin': self.margin})
formatter = utils.TextFormatter(tuple(formats))
- print formatter.compose(self.header)
+ log.info(formatter.compose(self.header))
sep = []
for c in col_widths:
sep.append('-'*c)
- print formatter.compose(tuple(sep))
+ log.info(formatter.compose(tuple(sep)))
for r in self.rows:
- print formatter.compose(r)
+ log.info(formatter.compose(r))
else:
log.error("No data rows")
@@ -327,7 +328,10 @@ def format_paragraph(paragraph, width=None, alignment=ALIGN_LEFT):
result = []
#import string
words = paragraph.split() #string.split(paragraph)
- current, words = words[0], words[1:]
+ try:
+ current, words = words[0], words[1:]
+ except IndexError:
+ return [paragraph]
for word in words:
increment = 1 + len(word)
diff --git a/base/utils.py b/base/utils.py
index 4d72477ba..64df0e53f 100644
--- a/base/utils.py
+++ b/base/utils.py
@@ -1257,7 +1257,7 @@ def run(cmd, log_output=True, password_func=get_password, timeout=1):
except Exception, e:
- print "Exception", e
+ log.error("Exception: %s" % e)
cleanup_spinner()
child.close()