Commit a1938dae authored by Didier Raboud's avatar Didier Raboud

Imported Upstream version 2.8.6

parent 7ba580c5

Too many changes to show.

To preserve performance only 1000 of 1000+ files are displayed.

This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -176,7 +176,14 @@ try:
elif o in ('-p', '--printer'):
if a.startswith('*'):
printer_name = cups.getDefault()
printer_name = cups.getDefaultPrinter()
log.debug(printer_name)
if printer_name is not None:
log.info("Using CUPS default printer: %s" % printer_name)
else:
log.error("CUPS default printer is not set.")
else:
printer_name = a
......@@ -208,7 +215,7 @@ try:
utils.log_title(__title__, __version__)
if os.getuid() == 0:
log.error("hp-align should not be run as root.")
log.warn("hp-align should not be run as root.")
if not device_uri and not printer_name:
try:
......
......@@ -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
......
......@@ -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))
......
......@@ -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()
......
......@@ -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
......