def __init__(self, Mode = INTERACTIVE_MODE): self.__password ="" self.__passwordValidated = False self.__mode = Mode self.__readAuthType() #self.__authType self.__expectList =[] if not utils.to_bool(sys_conf.get('configure','qt4', '0')) and utils.to_bool(sys_conf.get('configure','qt3', '0')): self.__ui_toolkit = 'qt3' else: self.__ui_toolkit = 'qt4' for s in utils.EXPECT_WORD_LIST: try: p = re.compile(s, re.I) except TypeError: self.__expectList.append(s) else: self.__expectList.append(p)
def run_plugin_command(required=True, plugin_reason=PLUGIN_REASON_NONE, Mode=GUI_MODE): su_sudo = None need_sudo = True if utils.to_bool(sys_conf.get("configure", "policy-kit")): try: obj = PolicyKit() su_sudo = "%s" need_sudo = False log.debug("Using PolicyKit for authentication") except dbus.DBusException, ex: log.error("PolicyKit NOT installed when configured for use. [%s]" % ex)
def run_plugin_command(required=True, plugin_reason=PLUGIN_REASON_NONE): su_sudo = None need_sudo = True name = None version = None if utils.to_bool(sys_conf.get('configure', 'policy-kit')): try: obj = PolicyKit() su_sudo = "%s" need_sudo = False log.debug("Using PolicyKit for authentication") except dbus.DBusException, ex: log.error("PolicyKit NOT installed when configured for use")
def convert_data(self, key, value, typ=None): if typ is None: typ = self.get_data_type(key) if typ in (TYPE_BITFIELD, TYPE_INT): try: value = int(value) except (ValueError, TypeError): log.error("Invalid value in .dat file: %s=%s" % (key, value)) value = 0 elif typ == TYPE_BOOL: value = utils.to_bool(value) elif typ == TYPE_LIST: value = [x for x in value.split(',') if x] elif typ == TYPE_DATE: # mm/dd/yyyy if datetime_avail: # ...don't use datetime.strptime(), wasn't avail. until 2.5 match = self.date.search(value) if match is not None: month = int(match.group(1)) day = int(match.group(2)) year = int(match.group(3)) value = datetime.date(year, month, day) elif typ == TYPE_HEX: try: value = int(value, 16) except (ValueError, TypeError): log.error("Invalid hex value in .dat file: %s=%s" % (key, value)) value = 0 return value
plugin_path = 'file://' + plugin_path log.debug("Plugin path=%s (%d)" % (plugin_path, size)) if mode == GUI_MODE: if ui_toolkit == 'qt3': if not utils.canEnterGUIMode(): log.error("%s requires GUI support (try running with --qt4). Try using interactive (-i) mode." % __mod__) sys.exit(1) else: if not utils.canEnterGUIMode4(): log.error("%s requires GUI support (try running with --qt3). Try using interactive (-i) mode." % __mod__) sys.exit(1) PKIT = utils.to_bool(sys_conf.get('configure', 'policy-kit')) if PKIT: try: from base.pkit import * try: pkit = PolicyKit() pkit_installed = True except dbus.DBusException, ex: log.error("PolicyKit support requires DBUS or PolicyKit support files missing") pkit_installed = False except: log.error("Unable to load pkit...is HPLIP installed?") pkit_installed = False else: pkit_installed = False
elif o == "-g": log.set_level("debug") elif o in ("-h", "--help"): usage() elif o == "--help-rest": usage("rest") elif o == "--help-man": usage("man") if len(args) == 0: cups11 = utils.to_bool(sys_conf.get("configure", "cups11", "0")) try: probed_devices = device.probeDevices(["usb", "par"], filter={"fax-type": (operator.gt, 0)}) except Error: sys.exit(CUPS_BACKEND_FAILED) good_devices = 0 for uri in probed_devices: try: back_end, is_hp, bus, model, serial, dev_file, host, zc, port = device.parseDeviceURI(uri) except Error: continue mq = device.queryModelByModel(model)
def addItem(self, group, option, text, typ, value, choices, default, read_only=False, suffix=""): widget, control = None, None if typ == cups.PPD_UI_BOOLEAN: # () On (*) Off widget widget = self.getWidget() layout = QGridLayout(widget, 1, 1, 5, 10, "layout") default = int(utils.to_bool(str(default))) value = int(utils.to_bool(str(value))) textLabel1 = QLabel(widget, "textLabel1") layout.addWidget(textLabel1, 0, 0) buttonGroup = OptionButtonGroup(widget, "buttonGroup", group, option, default) buttonGroup.setLineWidth(0) buttonGroup.setColumnLayout(0,Qt.Vertical) buttonGroup.layout().setSpacing(1) buttonGroup.layout().setMargin(5) buttonGroupLayout = QHBoxLayout(buttonGroup.layout()) buttonGroupLayout.setAlignment(Qt.AlignTop) defaultPushButton = DefaultPushButton(widget,"defaultPushButton", group, option, choices, default, buttonGroup, typ) buttonGroup.setDefaultPushbutton(defaultPushButton) layout.addWidget(defaultPushButton, 0, 3) spacer1 = QSpacerItem(20, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) layout.addItem(spacer1, 0, 1) onRadioButton = QRadioButton(buttonGroup,"onRadioButton") buttonGroup.insert(onRadioButton, 1) buttonGroupLayout.addWidget(onRadioButton) offRadioButton = QRadioButton(buttonGroup,"offRadioButton") buttonGroup.insert(offRadioButton, 0) buttonGroupLayout.addWidget(offRadioButton) layout.addWidget(buttonGroup, 0, 2) textLabel1.setText(text) onRadioButton.setText(self.__tr("On")) offRadioButton.setText(self.__tr("Off")) if value == default: defaultPushButton.setEnabled(False) self.connect(defaultPushButton, SIGNAL("clicked()"), self.defaultPushButton_clicked) self.connect(buttonGroup, SIGNAL("clicked(int)"), self.optionButtonGroup_clicked) x = self.__tr('Off') if default: x = self.__tr('On') if value: buttonGroup.setButton(1) else: buttonGroup.setButton(0) if read_only: onRadioButton.setEnabled(False) offRadioButton.setEnabled(False) defaultPushButton.setEnabled(False) else: QToolTip.add(defaultPushButton, self.__tr('Set to default value of "%1".').arg(x)) defaultPushButton.setText("Default") elif typ == cups.PPD_UI_PICKONE: # Combo box widget widget = self.getWidget() layout1 = QHBoxLayout(widget,5,10,"layout1") textLabel1 = QLabel(widget,"textLabel1") layout1.addWidget(textLabel1) spacer1 = QSpacerItem(20, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) layout1.addItem(spacer1) optionComboBox = OptionComboBox(0, widget, "optionComboBox", group, option, choices, default) layout1.addWidget(optionComboBox) defaultPushButton = DefaultPushButton(widget,"defaultPushButton", group, option, choices, default, optionComboBox, typ) optionComboBox.setDefaultPushbutton(defaultPushButton) layout1.addWidget(defaultPushButton) textLabel1.setText(text) defaultPushButton.setText("Default") x, y = None, None for c, t in choices: d = c.lower() if value is not None and d == value.lower(): x = t if d == default.lower(): y = t optionComboBox.insertItem(t) if x is not None: optionComboBox.setCurrentText(x) if value is not None and value.lower() == default.lower(): defaultPushButton.setEnabled(False) self.linkPrintoutModeAndQuality(option, value) if read_only: optionComboBox.setEnabled(False) defaultPushButton.setEnabled(False) elif y is not None: QToolTip.add(defaultPushButton, self.__tr('Set to default value of "%1".').arg(y)) self.connect(defaultPushButton, SIGNAL("clicked()"), self.defaultPushButton_clicked) self.connect(optionComboBox, SIGNAL("activated(const QString&)"), self.optionComboBox_activated) self.connect(optionComboBox, SIGNAL("activated(const QString &)"), self.ComboBox_indexChanged) control = optionComboBox elif typ == cups.UI_SPINNER: # Spinner widget widget = self.getWidget() layout1 = QHBoxLayout(widget,5,10, "layout1") textLabel1 = QLabel(widget, "textLabel1") layout1.addWidget(textLabel1) spacer1 = QSpacerItem(20, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) layout1.addItem(spacer1) optionSpinBox = OptionSpinBox(widget,"optionSpinBox", group, option, default) layout1.addWidget(optionSpinBox) defaultPushButton = DefaultPushButton(widget, "defaultPushButton", group, option, choices, default, optionSpinBox, typ) optionSpinBox.setDefaultPushbutton(defaultPushButton) layout1.addWidget(defaultPushButton) min, max = choices optionSpinBox.setMinValue(min) optionSpinBox.setMaxValue(max) optionSpinBox.setValue(value) if suffix: optionSpinBox.setSuffix(suffix) textLabel1.setText(text) defaultPushButton.setText("Default") self.connect(optionSpinBox, SIGNAL("valueChanged(int)"), self.optionSpinBox_valueChanged) self.connect(defaultPushButton, SIGNAL("clicked()"), self.defaultPushButton_clicked) if value == default: defaultPushButton.setEnabled(False) if read_only: self.optionSpinBox.setEnabled(False) self.defaultPushButton.setEnabled() else: QToolTip.add(defaultPushButton, self.__tr('Set to default value of "%1".').arg(default)) elif typ == cups.UI_BANNER_JOB_SHEETS: # Job sheets widget widget = self.getWidget() layout1 = QGridLayout(widget,1,1,5,10,"layout1") startComboBox = OptionComboBox(0, widget, "startComboBox", group, "start", choices, default, typ) layout1.addWidget(startComboBox,0,3) startTextLabel = QLabel(widget,"startTextLabel") layout1.addWidget(startTextLabel,0,2) endTextLabel = QLabel(widget,"endTextLabel") layout1.addWidget(endTextLabel,0,4) endComboBox = OptionComboBox(0, widget, "endComboBox", group, "end", choices, default, typ, startComboBox) layout1.addWidget(endComboBox,0,5) startComboBox.setOther(endComboBox) defaultPushButton = DefaultPushButton(widget, "defaultPushButton", group, option, choices, default, (startComboBox, endComboBox), typ) layout1.addWidget(defaultPushButton,0,6) startComboBox.setDefaultPushbutton(defaultPushButton) endComboBox.setDefaultPushbutton(defaultPushButton) textLabel1 = QLabel(widget,"textLabel1") layout1.addWidget(textLabel1,0,0) spacer1 = QSpacerItem(20,20,QSizePolicy.Expanding,QSizePolicy.Minimum) layout1.addItem(spacer1,0,1) textLabel1.setText(text) defaultPushButton.setText("Default") startTextLabel.setText(self.__tr("Start:")) endTextLabel.setText(self.__tr("End:")) s, e, y, z = None, None, None, None for c, t in choices: d = c.lower() if value is not None: if d == value[0].lower(): s = t if d == value[1].lower(): e = t if d == default[0].lower(): y = t if d == default[1].lower(): z = t startComboBox.insertItem(t) endComboBox.insertItem(t) if s is not None: startComboBox.setCurrentText(s) if e is not None: endComboBox.setCurrentText(e) if value is not None and \ value[0].lower() == default[0].lower() and \ value[1].lower() == default[1].lower(): defaultPushButton.setEnabled(False) if y is not None and z is not None: QToolTip.add(defaultPushButton, self.__tr('Set to default value of "Start: %1, End: %2".').arg(y).arg(z)) self.connect(startComboBox, SIGNAL("activated(const QString&)"), self.optionComboBox_activated) self.connect(endComboBox, SIGNAL("activated(const QString&)"), self.optionComboBox_activated) self.connect(defaultPushButton, SIGNAL("clicked()"), self.defaultPushButton_clicked) elif typ == cups.PPD_UI_PICKMANY: log.error("Unrecognized type: pickmany") elif typ == cups.UI_UNITS_SPINNER: widget = self.getWidget() layout1 = QHBoxLayout(widget,5,10,"layout1") textLabel1 = QLabel(widget,"textLabel1") layout1.addWidget(textLabel1) spacer1 = QSpacerItem(20,20,QSizePolicy.Expanding,QSizePolicy.Minimum) layout1.addItem(spacer1) lineEdit1 = QLineEdit(widget,"lineEdit1") layout1.addWidget(lineEdit1) comboBox1 = QComboBox(0,widget,"comboBox1") layout1.addWidget(comboBox1) defaultPushButton = QPushButton(widget,"defaultPushButton") layout1.addWidget(defaultPushButton) textLabel1.setText(text) defaultPushButton.setText("Default") elif typ == cups.UI_INFO: widget = self.getWidget() layout1 = QHBoxLayout(widget,5,10,"layout1") textPropName = QLabel(widget,"textPropName") layout1.addWidget(textPropName) textPropName.setText(text) spacer1 = QSpacerItem(20,20,QSizePolicy.Expanding,QSizePolicy.Minimum) layout1.addItem(spacer1) if text == 'Print Quality': self.PQValueLabel = QLabel(widget,"textPropValue") layout1.addWidget(self.PQValueLabel) self.PQValueLabel.setText(value) elif text == 'Color Input / Black Render': self.PQColorInputLabel = QLabel(widget,"textPropValue") layout1.addWidget(self.PQColorInputLabel) self.PQColorInputLabel.setText(value) else: textPropValue = QLabel(widget,"textPropValue") layout1.addWidget(textPropValue) textPropValue.setText(value) else: log.error("Invalid UI value: %s/%s" % (group, option)) if widget is not None: self.addWidget(widget, "o:"+option, control) return widget
def fillControls(self): QApplication.setOverrideCursor(QApplication.waitCursor) ScrollView.fillControls(self) self.loading = True cups.resetOptions() cups.openPPD(self.cur_printer) cur_outputmode = "" #if 1: try: if 1: #try: current_options = dict(cups.getOptions()) if not self.cur_device.device_type == DEVICE_TYPE_FAX: self.addGroupHeading("basic", self.__tr("Basic")) log.debug("Group: Basic") # Basic # PageSize (in PPD section) # orientation-requested # sides # outputorder # Collate current = current_options.get('orientation-requested', '3') self.addItem("basic", "orientation-requested", self.__tr("Page Orientation"), cups.PPD_UI_PICKONE, current, [('3', self.__tr('Portrait')), ('4', self.__tr('Landscape')), ('5', self.__tr('Reverse landscape')), ('6', self.__tr('Reverse portrait'))], '3') log.debug("Option: orientation-requested") log.debug("Current value: %s" % current) duplexer = self.cur_device.dq.get('duplexer', 0) log.debug("Duplexer = %d" % duplexer) if duplexer: current = current_options.get('sides', 'one-sided') self.addItem("basic", "sides", self.__tr("Duplex (Print on both sides of the page)"), cups.PPD_UI_PICKONE, current, [('one-sided',self.__tr('Single sided')), ('two-sided-long-edge', self.__tr('Two sided (long edge)')), ('two-sided-short-edge', self.__tr('Two sided (short edge)'))], 'one-sided') log.debug("Option: sides") log.debug("Current value: %s" % current) current = current_options.get('outputorder', 'normal') self.addItem("basic", "outputorder", self.__tr("Output Order (Print last page first)"), cups.PPD_UI_PICKONE, current, [('normal', self.__tr('Normal (Print first page first)')), ('reverse', self.__tr('Reversed (Print last page first)'))], 'normal') log.debug("Option: outputorder") log.debug("Current value: %s" % current) current = utils.to_bool(current_options.get('Collate', '0')) self.addItem("basic", "Collate", self.__tr("Collate (Group together multiple copies)"), cups.PPD_UI_BOOLEAN, current, [], 0) log.debug("Option: Collate") log.debug("Current value: %s" % current) groups = cups.getGroupList() for g in groups: log.debug("Group: %s" % repr(g)) if 'jobretention' in g.lower(): log.debug("HPJobRetention skipped.") continue text, num_subgroups = cups.getGroup(g) read_only = 'install' in g.lower() try: text = text.decode('utf-8') except UnicodeDecodeError: pass if g.lower() == 'printoutmode': text = self.__tr("Quality") self.addGroupHeading(g, text, read_only) log.debug(" Text: %s" % repr(text)) log.debug("Num subgroups: %d" % num_subgroups) options = cups.getOptionList(g) for o in options: log.debug(" Option: %s" % repr(o)) if 'pageregion' in o.lower(): log.debug("Page Region skipped.") continue option_text, defchoice, conflicted, ui = cups.getOption(g, o) try: option_text = option_text.decode('utf-8') except UnicodeDecodeError: pass if o.lower() == 'quality': option_text = self.__tr("Quality") log.debug(" Text: %s" % repr(option_text)) log.debug(" Defchoice: %s" % repr(defchoice)) choices = cups.getChoiceList(g, o) value = None choice_data = [] for c in choices: log.debug(" Choice: %s" % repr(c)) # TODO: Add custom paper size controls if 'pagesize' in o.lower() and 'custom' in c.lower(): log.debug("Skipped.") continue choice_text, marked = cups.getChoice(g, o, c) try: choice_text = choice_text.decode('utf-8') except UnicodeDecodeError: pass log.debug(" Text: %s" % repr(choice_text)) if marked: value = c choice_data.append((c, choice_text)) if o.lower() == 'outputmode': if value is not None: cur_outputmode = value else: cur_outputmode = defchoice self.addItem(g, o, option_text, ui, value, choice_data, defchoice, read_only) ## if 'pagesize' in o.lower(): # and 'custom' in c.lower(): ## current = 0.0 ## width_widget = self.addItem("custom", "custom-width", self.__tr("Custom Paper Width"), cups.UI_UNITS_SPINNER, ## current, (0.0, 0.0), 0.0) ## ## current = 0.0 ## height_widget = self.addItem("custom", "custom-height", self.__tr("Custom Paper Height"), cups.UI_UNITS_SPINNER, ## current, (0.0, 0.0), 0.0) ## ## if value.lower() == 'custom': ## pass # N-Up # number-up # number-up-layout # page-border self.addGroupHeading("nup", self.__tr("N-Up (Multiple document pages per printed page)")) log.debug("Group: N-Up") current = current_options.get('number-up', '1') self.addItem("nup", "number-up", self.__tr("Pages per Sheet"), cups.PPD_UI_PICKONE, current, [('1', self.__tr('1 page per sheet')), ('2', self.__tr('2 pages per sheet')), ('4', self.__tr('4 pages per sheet'))], '1') log.debug(" Option: number-up") log.debug(" Current value: %s" % current) current = current_options.get('number-up-layout', 'lrtb') self.addItem("nup", "number-up-layout", self.__tr("Layout"), cups.PPD_UI_PICKONE, current, [('btlr', self.__tr('Bottom to top, left to right')), ('btrl', self.__tr('Bottom to top, right to left')), ('lrbt', self.__tr('Left to right, bottom to top')), ('lrtb', self.__tr('Left to right, top to bottom')), ('rlbt', self.__tr('Right to left, bottom to top')), ('rltb', self.__tr('Right to left, top to bottom')), ('tblr', self.__tr('Top to bottom, left to right')), ('tbrl', self.__tr('Top to bottom, right to left')) ], 'lrtb') log.debug(" Option: number-up-layout") log.debug(" Current value: %s" % current) current = current_options.get('page-border', 'none') self.addItem("nup", "page-border", self.__tr("Printed Border Around Each Page"), cups.PPD_UI_PICKONE, current, [('double', self.__tr("Two thin borders")), ("double-thick", self.__tr("Two thick borders")), ("none", self.__tr("No border")), ("single", self.__tr("One thin border")), ("single-thick", self.__tr("One thick border"))], 'none') log.debug(" Option: page-border") log.debug(" Current value: %s" % current) # Adjustment # brightness # gamma if not self.cur_device.device_type == DEVICE_TYPE_FAX: self.addGroupHeading("adjustment", self.__tr("Printout Appearance")) current = int(current_options.get('brightness', 100)) log.debug(" Option: brightness") log.debug(" Current value: %s" % current) self.addItem("adjustment", "brightness", self.__tr("Brightness"), cups.UI_SPINNER, current, (0, 200), 100, suffix=" %") current = int(current_options.get('gamma', 1000)) log.debug(" Option: gamma") log.debug(" Current value: %s" % current) self.addItem("adjustment", "gamma", self.__tr("Gamma"), cups.UI_SPINNER, current, (1, 10000), 1000) # Margins (pts) # page-left # page-right # page-top # page-bottom ## if 0: ## # TODO: cupsPPDPageSize() fails on LaserJets. How do we get margins in this case? Defaults? ## # PPD file for LJs has a HWMargin entry... ## page, page_width, page_len, left, bottom, right, top = cups.getPPDPageSize() ## ## right = page_width - right ## top = page_len - top ## ## self.addGroupHeading("margins", self.__tr("Margins")) ## current_top = current_options.get('page-top', 0) # pts ## current_bottom = current_options.get('page-bottom', 0) # pts ## current_left = current_options.get('page-left', 0) # pts ## current_right = current_options.get('page-right', 0) # pts ## ## log.debug(" Option: page-top") ## log.debug(" Current value: %s" % current_top) ## ## self.addItem("margins", "page-top", self.__tr("Top margin"), ## cups.UI_UNITS_SPINNER, current_top, ## (0, page_len), top) ## ## self.addItem("margins", "page-bottom", self.__tr("Bottom margin"), ## cups.UI_UNITS_SPINNER, current_bottom, ## (0, page_len), bottom) ## ## self.addItem("margins", "page-left", self.__tr("Right margin"), ## cups.UI_UNITS_SPINNER, current_left, ## (0, page_width), left) ## ## self.addItem("margins", "page-right", self.__tr("Left margin"), ## cups.UI_UNITS_SPINNER, current_right, ## (0, page_width), right) # Image Printing # position # natural-scaling # saturation # hue self.addGroupHeading("image", self.__tr("Image Printing")) current = utils.to_bool(current_options.get('fitplot', 'false')) self.addItem("image", "fitplot", self.__tr("Fit to Page"), cups.PPD_UI_BOOLEAN, current, [], 0) current = current_options.get('position', 'center') self.addItem("image", "position", self.__tr("Position on Page"), cups.PPD_UI_PICKONE, current, [('center', self.__tr('Centered')), ('top', self.__tr('Top')), ('left', self.__tr('Left')), ('right', self.__tr('Right')), ('top-left', self.__tr('Top left')), ('top-right', self.__tr('Top right')), ('bottom', self.__tr('Bottom')), ('bottom-left', self.__tr('Bottom left')), ('bottom-right', self.__tr('Bottom right'))], 'center') log.debug(" Option: position") log.debug(" Current value: %s" % current) if not self.cur_device.device_type == DEVICE_TYPE_FAX: current = int(current_options.get('saturation', 100)) log.debug(" Option: saturation") log.debug(" Current value: %s" % current) self.addItem("image", "saturation", self.__tr("Saturation"), cups.UI_SPINNER, current, (0, 200), 100, suffix=" %") current = int(current_options.get('hue', 0)) log.debug(" Option: hue") log.debug(" Current value: %s" % current) self.addItem("image", "hue", self.__tr("Hue (color shift/rotation)"), cups.UI_SPINNER, current, (-100, 100), 0) current = int(current_options.get('natural-scaling', 100)) log.debug(" Option: natural-scaling") log.debug(" Current value: %s" % current) self.addItem("image", "natural-scaling", self.__tr('"Natural" Scaling (relative to image)'), cups.UI_SPINNER, current, (1, 800), 100, suffix=" %") current = int(current_options.get('scaling', 100)) log.debug(" Option: scaling") log.debug(" Current value: %s" % current) self.addItem("image", "scaling", self.__tr("Scaling (relative to page)"), cups.UI_SPINNER, current, (1, 800), 100, suffix=" %") # Misc # PrettyPrint # job-sheets # mirror self.addGroupHeading("misc", self.__tr("Miscellaneous")) log.debug("Group: Misc") current = utils.to_bool(current_options.get('prettyprint', '0')) self.addItem("misc", "prettyprint", self.__tr('"Pretty Print" Text Documents (Add headers and formatting)'), cups.PPD_UI_BOOLEAN, current, [], 0) log.debug(" Option: prettyprint") log.debug(" Current value: %s" % current) if not self.cur_device.device_type == DEVICE_TYPE_FAX: current = current_options.get('job-sheets', 'none').split(',') try: start = current[0] except IndexError: start = 'none' try: end = current[1] except IndexError: end = 'none' # TODO: Look for locally installed banner pages beyond the default CUPS ones? self.addItem("misc", "job-sheets", self.__tr("Banner Pages"), cups.UI_BANNER_JOB_SHEETS, (start, end), [("none", self.__tr("No banner page")), ('classified', self.__tr("Classified")), ('confidential', self.__tr("Confidential")), ('secret', self.__tr("Secret")), ('standard', self.__tr("Standard")), ('topsecret', self.__tr("Top secret")), ('unclassified', self.__tr("Unclassified"))], ('none', 'none')) log.debug(" Option: job-sheets") log.debug(" Current value: %s,%s" % (start, end)) current = utils.to_bool(current_options.get('mirror', '0')) self.addItem("misc", "mirror", self.__tr('Mirror Printing'), cups.PPD_UI_BOOLEAN, current, [], 0) log.debug(" Option: mirror") log.debug(" Current value: %s" % current) #Summary #color input #quality quality_attr_name = "OutputModeDPI" cur_outputmode_dpi = cups.findPPDAttribute(quality_attr_name, cur_outputmode) if cur_outputmode_dpi is not None: log.debug("Adding Group: Summary outputmode is : %s" % cur_outputmode) log.debug("Adding Group: Summary outputmode dpi is : %s" % str (cur_outputmode_dpi)) self.addGroupHeading("summry", self.__tr("Summary")) self.addItem("summry", "colorinput", self.__tr('Color Input / Black Render'), cups.UI_INFO, cur_outputmode_dpi, [], 0) self.addItem("summry", "quality", self.__tr('Print Quality'), cups.UI_INFO, cur_outputmode, [], 0) self.job_storage_avail = 0 #self.cur_device.mq['job-storage'] == JOB_STORAGE_ENABLE #print current_options if self.job_storage_avail: self.addGroupHeading("jobstorage", self.__tr("Job Storage and Secure Printing")) self.addJobStorage(current_options) #except Exception, e: #log.exception() # pass finally: cups.closePPD() self.loading = False QApplication.restoreOverrideCursor()
except (IOError, OSError), e: log.info("Plugins are not installed. Could not access file: %s" % e.strerror) else: log.info(output) log.info() log.info(log.bold("Current contents of '~/.hplip/hplip.conf' file:")) try: output = file(os.path.expanduser('~/.hplip/hplip.conf'), 'r').read() except (IOError, OSError), e: log.warn("Could not access file: %s" % e.strerror) self.num_warns += 1 else: log.info(output) scanning_enabled = utils.to_bool(sys_conf.get('configure', 'scanner-build', '0')) log.info(" %-20s %-20s %-10s %-10s %-10s %-10s %s"%( "<Package-name>", " <Package-Desc>", "<Required/Optional>", "<Min-Version>","<Installed-Version>", "<Status>", "<Comment>")) for s in self.hplip_dependencies: if s == EXTERNALDEP: if time_flag == DEPENDENCY_RUN_AND_COMPILE_TIME or time_flag == DEPENDENCY_RUN_TIME: tui.header(" External Dependencies") else: continue elif s == GENERALDEP: if time_flag == DEPENDENCY_RUN_AND_COMPILE_TIME or time_flag == DEPENDENCY_RUN_TIME: tui.header(" General Dependencies") else: continue elif s == COMPILEDEP: if time_flag == DEPENDENCY_RUN_AND_COMPILE_TIME or time_flag == DEPENDENCY_COMPILE_TIME: tui.header(" Compile Time Dependencies") else: continue elif s == PYEXT: tui.header(" Python Extentions")
mod.parseStdOpts('v:', ["version="]) user_pkit_version = None for o, a in opts: if o in ('-v', '--version'): try: user_pkit_version = int(a) except: log.error("-v or --version require an integer argument") sys.exit(1) if user_pkit_version < 0 or user_pkit_version > 1: log.error("invalid PolicyKit version...use 0 or 1") sys.exit(1) PKIT = utils.to_bool(sys_conf.get('configure', 'policy-kit')) if PKIT: try: from base.pkit import * pkit_version = policykit_version() if not user_pkit_version is None: pkit_version = user_pkit_version try: from dbus.mainloop.glib import DBusGMainLoop except ImportError: log.error("PolicyKit requires dbus") sys.exit(1) except: log.error("Unable to load pkit...is HPLIP installed?") sys.exit(1) else:
except (IOError, OSError), e: log.info("Plugins are not installed. Could not access file: %s" % e.strerror) else: log.info(output) log.info() log.info(log.bold("Current contents of '~/.hplip/hplip.conf' file:")) try: output = file(os.path.expanduser("~/.hplip/hplip.conf"), "r").read() except (IOError, OSError), e: log.warn("Could not access file: %s" % e.strerror) self.num_warns += 1 else: log.info(output) scanning_enabled = utils.to_bool(sys_conf.get("configure", "scanner-build", "0")) log.info( " %-20s %-20s %-10s %-10s %-10s %-10s %s" % ( "<Package-name>", " <Package-Desc>", "<Required/Optional>", "<Min-Version>", "<Installed-Version>", "<Status>", "<Comment>", ) ) for s in self.hplip_dependencies: if s == EXTERNALDEP: if time_flag == DEPENDENCY_RUN_AND_COMPILE_TIME or time_flag == DEPENDENCY_RUN_TIME:
mq = device.queryModelByURI(device_uri) if not mq or mq.get('support-type', SUPPORT_TYPE_NONE) == SUPPORT_TYPE_NONE: log.error("Unsupported printer model.") sys.exit(1) if mq.get('fax-type', FAX_TYPE_NONE) in (FAX_TYPE_NONE, FAX_TYPE_NOT_SUPPORTED) and setup_fax: #log.warning("Cannot setup fax - device does not have fax feature.") setup_fax = False # ******************************* PLUGIN norm_model = models.normalizeModelName(model).lower() plugin = mq.get('plugin', PLUGIN_NONE) plugin_installed = utils.to_bool(sys_state.get('plugin', 'installed', '0')) if ignore_plugin_check is False and plugin > PLUGIN_NONE and not plugin_installed: tui.header("PLUG-IN INSTALLATION") hp_plugin = utils.which('hp-plugin') if hp_plugin: if prop.gui_build: os.system("hp-plugin -i") else: os.system("hp-plugin") ppds = cups.getSystemPPDs() default_model = utils.xstrip(model.replace('series', '').replace('Series', ''), '_')
def validate(self,time_flag=DEPENDENCY_RUN_AND_COMPILE_TIME, is_quiet_mode= False): ############ Variables ####################### self.cups_ddk_not_req = False self.hpmudext_avail = False self.ui_toolkit = sys_conf.get('configure','ui-toolkit') org_log_location = log.get_where() if is_quiet_mode: log.set_where(log.LOG_TO_FILE) IS_LIBUSB01_ENABLED = sys_conf.get('configure', 'libusb01-build', 'no') vrs =self.core.get_distro_data('versions_list') supported_distro_vrs= self.core.distro_version if self.core.distro_version not in vrs and len(vrs): supported_distro_vrs= vrs[len(vrs)-1] log.warn(log.bold("%s-%s version is not supported. Using %s-%s versions dependencies to verify and install..." \ %(self.core.distro_name, self.core.distro_version, self.core.distro_name, supported_distro_vrs))) tui.header("SYSTEM INFO") Sts, Kernel_info =utils.run("uname -r -v -o") Sts, Host_info =utils.run("uname -n") Sts, Proc_info =utils.run("uname -r -v -o") log.info(" Kernel: %s Host: %s Proc: %s Distribution: %s %s"\ %(Kernel_info,Host_info,Proc_info,self.core.distro_name, self.core.distro_version)) log.info(" Bitness: %s bit\n"%utils.getBitness()) tui.header("HPLIP CONFIGURATION") v = sys_conf.get('hplip', 'version') if v: home = sys_conf.get('dirs', 'home') log.info("HPLIP-Version: HPLIP %s" %v) log.info("HPLIP-Home: %s" %home) if self.core.is_auto_installer_support(): log.info("HPLIP-Installation: Auto installation is supported for %s distro %s version " %(self.core.distro_name, self.core.distro_version)) else: log.warn("HPLIP-Installation: Auto installation is not supported for %s distro %s version " %(self.core.distro_name, self.core.distro_version)) log.info() log.info(log.bold("Current contents of '/etc/hp/hplip.conf' file:")) try: output = open('/etc/hp/hplip.conf', 'r').read() except (IOError, OSError) as e: log.error("Could not access file: %s. Check HPLIP installation." % e.strerror) self.num_errors += 1 else: log.info(output) log.info() log.info(log.bold("Current contents of '/var/lib/hp/hplip.state' file:")) try: output = open(os.path.expanduser('/var/lib/hp/hplip.state'), 'r').read() except (IOError, OSError) as e: log.info("Plugins are not installed. Could not access file: %s" % e.strerror) else: log.info(output) log.info() log.info(log.bold("Current contents of '~/.hplip/hplip.conf' file:")) try: output = open(os.path.expanduser('~/.hplip/hplip.conf'), 'r').read() except (IOError, OSError) as e: log.warn("Could not access file: %s" % e.strerror) self.num_warns += 1 else: log.info(output) self.scanning_enabled = utils.to_bool(sys_conf.get('configure', 'scanner-build', '0')) log.info(" %-20s %-20s %-10s %-10s %-10s %-10s %s"%( "<Package-name>", " <Package-Desc>", "<Required/Optional>", "<Min-Version>","<Installed-Version>", "<Status>", "<Comment>")) self.core.dependencies.update(self.core.hplip_dependencies) if time_flag == DEPENDENCY_RUN_AND_COMPILE_TIME or time_flag == DEPENDENCY_RUN_TIME: dep_dict = { "External Dependencies": EXTERNALDEP, "General Dependencies": GENERALDEP, "COMPILEDEP": COMPILEDEP, "Python Extentions": PYEXT, "Scan Configuration": SCANCONF } for dep_check in dep_dict: tui.header(dep_check) for dep in self.core.dependencies: if self.core.dependencies[dep][7] == dep_dict[dep_check] and any([self.core.selected_options[x] for x in self.core.dependencies[dep][1]]): self.__update_deps_info(supported_distro_vrs, dep, self.core.dependencies[dep]) # tui.header(" External Dependencies") # for dep in self.dependencies: # if self.dependencies[dep][7] == EXTERNALDEP: # self.__update_deps_info(supported_distro_vrs, dep, self.dependencies[dep]) # tui.header(" General Dependencies") # for dep in self.dependencies: # if self.dependencies[dep][7] == GENERALDEP: # self.__update_deps_info(supported_distro_vrs, dep, self.dependencies[dep]) # tui.header(" COMPILEDEP") # for dep in self.dependencies: # if self.dependencies[dep][7] == COMPILEDEP: # self.__update_deps_info(supported_distro_vrs, dep, self.dependencies[dep]) # tui.header(" Python Extentions") # for dep in self.dependencies: # if self.dependencies[dep][7] == PYEXT: # self.__update_deps_info(supported_distro_vrs, dep, self.dependencies[dep]) # tui.header(" Scan Configuration") # for dep in self.dependencies: # if self.dependencies[dep][7] == SCANCONF: # self.__update_deps_info(supported_distro_vrs, dep, self.dependencies[dep]) # tui.header(" Other Dependencies") # for dep in self.dependencies: # if self.dependencies[dep][7] in dep_dict: # # if self.dependencies[dep][7] != SCANCONF and \ # # self.dependencies[dep][7] != PYEXT and \ # # self.dependencies[dep][7] != COMPILEDEP and \ # # self.dependencies[dep][7] != GENERALDEP and \ # # self.dependencies[dep][7] != EXTERNALDEP: # self.__update_deps_info(supported_distro_vrs, dep, self.dependencies[dep]) if self.scanning_enabled: tui.header("DISCOVERED SCANNER DEVICES") if utils.which('scanimage'): status, output = utils.run("scanimage -L") if status != 0 : log.error("Failed to get Scanners information.") elif 'No scanners were identified' in output: log.info("No Scanner found.") else: log.info(output) if device_avail: #if prop.par_build: #tui.header("DISCOVERED PARALLEL DEVICES") #devices = device.probeDevices(['par']) #if devices: #f = tui.Formatter() #f.header = ("Device URI", "Model") #for d, dd in devices.items(): #f.add((d, dd[0])) #f.output() #else: #log.info("No devices found.") #if not core.have_dependencies['ppdev']: #log.error("'ppdecmds_to_be_runv' kernel module not loaded.") if prop.usb_build: tui.header("DISCOVERED USB DEVICES") devices = device.probeDevices(['usb']) if devices: f = tui.Formatter() f.header = ("Device URI", "Model") for d, dd in list(devices.items()): f.add((d, dd[0])) f.output() else: log.info("No devices found.") tui.header("INSTALLED CUPS PRINTER QUEUES") lpstat_pat = re.compile(r"""(\S*): (.*)""", re.IGNORECASE) status, output = utils.run('lpstat -v') log.info() cups_printers = [] plugin_sts = None for p in output.splitlines(): try: match = lpstat_pat.search(p) printer_name = match.group(1) device_uri = match.group(2) cups_printers.append((printer_name, device_uri)) except AttributeError: pass log.debug(cups_printers) if cups_printers: #non_hp = False for p in cups_printers: printer_name, device_uri = p if device_uri.startswith("cups-pdf:/") or \ device_uri.startswith('ipp://'): continue try: back_end, is_hp, bus, model, serial, dev_file, host, zc, port = \ device.parseDeviceURI(device_uri) except Error: back_end, is_hp, bus, model, serial, dev_file, host, zc, port = \ '', False, '', '', '', '', '', '', 1 #print back_end, is_hp, bus, model, serial, dev_file, host, zc, port log.info(log.bold(printer_name)) log.info(log.bold('-'*len(printer_name))) x = "Unknown" if back_end == 'hpfax': x = "Fax" elif back_end == 'hp': x = "Printer" log.info("Type: %s" % x) #if is_hp: # x = 'Yes, using the %s: CUPS backend.' % back_end #else: # x = 'No, not using the hp: or hpfax: CUPS backend.' # non_hp = True #log.info("Installed in HPLIP?: %s" % x) log.info("Device URI: %s" % device_uri) ppd = os.path.join('/etc/cups/ppd', printer_name + '.ppd') if os.path.exists(ppd): log.info("PPD: %s" % ppd) nickname_pat = re.compile(r'''\*NickName:\s*\"(.*)"''', re.MULTILINE) try: f = to_string_utf8(open(ppd, 'rb').read()) except IOError: log.warn("Failed to read %s ppd file"%ppd) desc = '' else: try: desc = nickname_pat.search(f).group(1) except AttributeError: desc = '' log.info("PPD Description: %s" % desc) status, output = utils.run('lpstat -p%s' % printer_name) log.info("Printer status: %s" % output.replace("\n", "")) if back_end == 'hpfax' and desc and not 'HP Fax' in desc: self.num_errors += 1 log.error("Incorrect PPD file for fax queue '%s'. Fax queues must use 'HP-Fax-hplip.ppd'." % printer_name) elif back_end == 'hp' and desc and 'HP Fax' in desc: self.num_errors += 1 log.error("Incorrect PPD file for a print queue '%s'. Print queues must not use 'HP-Fax-hplip.ppd'." % printer_name) elif back_end not in ('hp', 'hpfax'): log.warn("Printer is not HPLIP installed. Printers must use the hp: or hpfax: CUPS backend for HP-Devices.") self.num_warns += 1 if device_avail and is_hp: d = None try: try: d = device.Device(device_uri,None, None, None, True) except Error: log.error("Device initialization failed.") continue plugin = d.mq.get('plugin', PLUGIN_NONE) if plugin in (PLUGIN_REQUIRED, PLUGIN_OPTIONAL): if not plugin_sts: from installer import pluginhandler pluginObj = pluginhandler.PluginHandle() plugin_sts = pluginObj.getStatus() if plugin_sts == pluginhandler.PLUGIN_INSTALLED: self.plugin_status = PLUGIN_INSTALLED if plugin == pluginhandler.PLUGIN_REQUIRED: log.info("Required plug-in status: Installed") else: log.info("Optional plug-in status: Installed") elif plugin_sts == pluginhandler.PLUGIN_NOT_INSTALLED: self.plugin_status = PLUGIN_NOT_INSTALLED if plugin == PLUGIN_REQUIRED: self.num_errors += 1 log.error("Required plug-in status: Not installed") else: self.num_warns +=1 log.warn("Optional plug-in status: Not installed") elif plugin_sts == pluginhandler.PLUGIN_VERSION_MISMATCH: self.num_warns += 1 self.plugin_status = pluginhandler.PLUGIN_VERSION_MISMATCH log.warn("plug-in status: Version mismatch") if bus in ('par', 'usb'): try: d.open() except Error as e: log.error(e.msg) deviceid = '' else: deviceid = d.getDeviceID() log.debug(deviceid) #print deviceid if not deviceid: log.error("Communication status: Failed") self.comm_error_devices[printer_name] = device_uri self.num_errors += 1 else: log.info("Communication status: Good") elif bus == 'net': try: error_code, deviceid = d.getPML(pml.OID_DEVICE_ID) except Error: pass #print error_code if not deviceid: log.error("Communication status: Failed") self.comm_error_devices[printer_name] = device_uri self.num_errors += 1 else: log.info("Communication status: Good") finally: if d is not None: d.close() log.info() else: log.warn("No queues found.") tui.header("PERMISSION") # sts,avl_grps_out =utils.run('groups') # sts, out = utils.check_user_groups(self.user_grps_cmd, avl_grps_out) # if sts: # log.info("%-15s %-30s %-15s %-8s %-8s %-8s %s"%("groups", "user-groups","Required", "-","-", "OK",avl_grps_out)) # else: # log.info(log.red("error: %-8s %-30s %-15s %-8s %-8s %-8s %s"%("groups", "user-groups", "Required","-", "-", "MISSING", out))) # self.num_errors += 1 # self.missing_user_grps = out if self.hpmudext_avail: lsusb = utils.which('lsusb') if lsusb: lsusb = os.path.join(lsusb, 'lsusb') status, output = utils.run("%s -d03f0:" % lsusb) if output: lsusb_pat = re.compile("""^Bus\s([0-9a-fA-F]{3,3})\sDevice\s([0-9a-fA-F]{3,3}):\sID\s([0-9a-fA-F]{4,4}):([0-9a-fA-F]{4,4})(.*)""", re.IGNORECASE) log.debug(output) try: import hpmudext except ImportError: log.error("NOT FOUND OR FAILED TO LOAD! Please reinstall HPLIP and check for the proper installation of hpmudext.") self.num_errors += 1 for o in output.splitlines(): ok = True match = lsusb_pat.search(o) if match is not None: bus, dev, vid, pid, mfg = match.groups() #log.info("\nHP Device 0x%x at %s:%s: " % (int(pid, 16), bus, dev)) result_code, deviceuri = hpmudext.make_usb_uri(bus, dev) if result_code == hpmudext.HPMUD_R_OK: deviceuri = to_string_utf8(deviceuri) # log.info(" Device URI: %s" % deviceuri) d = None try: d = device.Device(deviceuri,None, None, None, True) except Error: continue if not d.supported: continue else: log.debug(" Device URI: (Makeuri FAILED)") continue printers = cups.getPrinters() printer_name=None for p in printers: if p.device_uri == deviceuri: printer_name=p.name break devnode = os.path.join("/", "dev", "bus", "usb", bus, dev) if not os.path.exists(devnode): devnode = os.path.join("/", "proc", "bus", "usb", bus, dev) if os.path.exists(devnode): # log.debug(" Device node: %s" % devnode) st_mode, st_ino, st_dev, st_nlink, st_uid, st_gid, \ st_size, st_atime, st_mtime, st_ctime = os.stat(devnode) getfacl = utils.which('getfacl',True) if getfacl: # log.debug("%s %s" % (getfacl, devnode)) status, output = utils.run("%s %s" % (getfacl, devnode)) getfacl_out_list = output.split('\r\n') out ='' for g in getfacl_out_list: if 'getfacl' not in g and '' is not g and 'file' not in g: pat = re.compile('''.*:(.*)''') if pat.search(g): out = out +' '+ pat.search(g).group(1) log.info("%-15s %-30s %-15s %-8s %-8s %-8s %s"%("USB", printer_name, "Required", "-", "-", "OK", "Node:'%s' Perm:'%s'"%(devnode,out))) else: log.info("%-15s %-30s %-15s %-8s %-8s %-8s %s"%("USB", printer_name, "Required","-","-","OK", "Node:'%s' Mode:'%s'"%(devnode,st_mode&0o777))) # selinux_file = '/etc/selinux/config' # if os.path.exists(selinux_file): # tui.header("SELINUX") # try: # selinux_fp = open(selinux_file, 'r') # except IOError: # log.error("Failed to open %s file."%selinux_file) # else: # for line in selinux_fp: # line=re.sub(r'\s','',line) # if line == "SELINUX=enforcing": # self.num_warns += 1 # log.warn("%-12s %-12s %-10s %-3s %-3s %-8s %s" \ # %("SELinux", "enabled", "Optional", "-", "-", "INCOMPAT", "'SELinux needs to be disabled for Plugin printers and Fax functionality.'")) # self.disable_selinux = True # break # if self.disable_selinux == False: # log.info("%-15s %-15s %-10s %-3s %-3s %-8s %s"\ # %("SELinux", "disabled", "Optional", "-", "-", "OK", "-")) self.smart_install_devices = smart_install.get_smartinstall_enabled_devices() if len(self.smart_install_devices): tui.header("'CD-ROM'/'Smart Install' Detected Devices") self.num_errors += 1 for d in self.smart_install_devices: log.error("%-30s %-20s %s "%(d, "CD_ROM_Enabled", "Needs to disable Smart Install")) else: log.error("HPLIP not found.") self.num_errors += 1 if is_quiet_mode: log.set_where(org_log_location) return self.num_errors, self.num_warns
elif o == '-g': log.set_level('debug') elif o in ('-h', '--help'): usage() elif o == '--help-rest': usage('rest') elif o == '--help-man': usage('man') if len( args ) == 0: cups11 = utils.to_bool(sys_conf.get('configure', 'cups11', '0')) try: probed_devices = device.probeDevices(['usb', 'par'], filter={'fax-type': (operator.gt, 0)}) except Error: sys.exit(CUPS_BACKEND_FAILED) good_devices = 0 for uri in probed_devices: try: back_end, is_hp, bus, model, serial, dev_file, host, zc, port = \ device.parseDeviceURI(uri) except Error: continue mq = device.queryModelByModel(model)
def validate(self,time_flag=DEPENDENCY_RUN_AND_COMPILE_TIME, is_quiet_mode= False): ############ Variables ####################### self.cups_ddk_not_req = False self.hpmudext_avail = False self.ui_toolkit = sys_conf.get('configure','ui-toolkit') org_log_location = log.get_where() if is_quiet_mode: log.set_where(log.LOG_TO_FILE) IS_LIBUSB01_ENABLED = sys_conf.get('configure', 'libusb01-build', 'no') vrs =self.get_distro_data('versions_list') supported_distro_vrs= self.distro_version if self.distro_version not in vrs and len(vrs): supported_distro_vrs= vrs[len(vrs)-1] log.warn(log.bold("%s-%s version is not supported. Using %s-%s versions dependencies to verify and install..." \ %(self.distro_name, self.distro_version, self.distro_name, supported_distro_vrs))) tui.header("SYSTEM INFO") Sts, Kernel_info =utils.run("uname -r -v -o") Sts, Host_info =utils.run("uname -n") Sts, Proc_info =utils.run("uname -r -v -o") log.info(" Kernel: %s Host: %s Proc: %s Distribution: %s %s"\ %(Kernel_info,Host_info,Proc_info,self.distro_name, self.distro_version)) log.info(" Bitness: %s bit\n"%utils.getBitness()) tui.header("HPLIP CONFIGURATION") v = sys_conf.get('hplip', 'version') if v: home = sys_conf.get('dirs', 'home') log.info("HPLIP-Version: HPLIP %s" %v) log.info("HPLIP-Home: %s" %home) if self.is_auto_installer_support(): log.info("HPLIP-Installation: Auto installation is supported for %s distro %s version " %(self.distro_name, self.distro_version)) else: log.warn("HPLIP-Installation: Auto installation is not supported for %s distro %s version " %(self.distro_name, self.distro_version)) log.info() log.info(log.bold("Current contents of '/etc/hp/hplip.conf' file:")) try: output = open('/etc/hp/hplip.conf', 'r').read() except (IOError, OSError) as e: log.error("Could not access file: %s. Check HPLIP installation." % e.strerror) self.num_errors += 1 else: log.info(output) log.info() log.info(log.bold("Current contents of '/var/lib/hp/hplip.state' file:")) try: output = open(os.path.expanduser('/var/lib/hp/hplip.state'), 'r').read() except (IOError, OSError) as e: log.info("Plugins are not installed. Could not access file: %s" % e.strerror) else: log.info(output) log.info() log.info(log.bold("Current contents of '~/.hplip/hplip.conf' file:")) try: output = open(os.path.expanduser('~/.hplip/hplip.conf'), 'r').read() except (IOError, OSError) as e: log.warn("Could not access file: %s" % e.strerror) self.num_warns += 1 else: log.info(output) self.scanning_enabled = utils.to_bool(sys_conf.get('configure', 'scanner-build', '0')) log.info(" %-20s %-20s %-10s %-10s %-10s %-10s %s"%( "<Package-name>", " <Package-Desc>", "<Required/Optional>", "<Min-Version>","<Installed-Version>", "<Status>", "<Comment>")) self.dependencies.update(self.hplip_dependencies) if time_flag == DEPENDENCY_RUN_AND_COMPILE_TIME or time_flag == DEPENDENCY_RUN_TIME: tui.header(" External Dependencies") for dep in self.dependencies: if self.dependencies[dep][7] == EXTERNALDEP: self.__update_deps_info(supported_distro_vrs, dep, self.dependencies[dep]) tui.header(" General Dependencies") for dep in self.dependencies: if self.dependencies[dep][7] == GENERALDEP: self.__update_deps_info(supported_distro_vrs, dep, self.dependencies[dep]) tui.header(" COMPILEDEP") for dep in self.dependencies: if self.dependencies[dep][7] == COMPILEDEP: self.__update_deps_info(supported_distro_vrs, dep, self.dependencies[dep]) tui.header(" Python Extentions") for dep in self.dependencies: if self.dependencies[dep][7] == PYEXT: self.__update_deps_info(supported_distro_vrs, dep, self.dependencies[dep]) tui.header(" Scan Configuration") for dep in self.dependencies: if self.dependencies[dep][7] == SCANCONF: self.__update_deps_info(supported_distro_vrs, dep, self.dependencies[dep]) tui.header(" Other Dependencies") for dep in self.dependencies: if self.dependencies[dep][7] != SCANCONF and \ self.dependencies[dep][7] != PYEXT and \ self.dependencies[dep][7] != COMPILEDEP and \ self.dependencies[dep][7] != GENERALDEP and \ self.dependencies[dep][7] != EXTERNALDEP: self.__update_deps_info(supported_distro_vrs, dep, self.dependencies[dep]) if self.scanning_enabled: tui.header("DISCOVERED SCANNER DEVICES") if utils.which('scanimage'): status, output = utils.run("scanimage -L") if status != 0 : log.error("Failed to get Scanners information.") elif 'No scanners were identified' in output: log.info("No Scanner found.") else: log.info(output) if device_avail: #if prop.par_build: #tui.header("DISCOVERED PARALLEL DEVICES") #devices = device.probeDevices(['par']) #if devices: #f = tui.Formatter() #f.header = ("Device URI", "Model") #for d, dd in devices.items(): #f.add((d, dd[0])) #f.output() #else: #log.info("No devices found.") #if not core.have_dependencies['ppdev']: #log.error("'ppdecmds_to_be_runv' kernel module not loaded.") if prop.usb_build: tui.header("DISCOVERED USB DEVICES") devices = device.probeDevices(['usb']) if devices: f = tui.Formatter() f.header = ("Device URI", "Model") for d, dd in list(devices.items()): f.add((d, dd[0])) f.output() else: log.info("No devices found.") tui.header("INSTALLED CUPS PRINTER QUEUES") lpstat_pat = re.compile(r"""(\S*): (.*)""", re.IGNORECASE) status, output = utils.run('lpstat -v') log.info() cups_printers = [] plugin_sts = None for p in output.splitlines(): try: match = lpstat_pat.search(p) printer_name = match.group(1) device_uri = match.group(2) cups_printers.append((printer_name, device_uri)) except AttributeError: pass log.debug(cups_printers) if cups_printers: #non_hp = False for p in cups_printers: printer_name, device_uri = p if device_uri.startswith("cups-pdf:/") or \ device_uri.startswith('ipp://'): continue try: back_end, is_hp, bus, model, serial, dev_file, host, zc, port = \ device.parseDeviceURI(device_uri) except Error: back_end, is_hp, bus, model, serial, dev_file, host, zc, port = \ '', False, '', '', '', '', '', '', 1 #print back_end, is_hp, bus, model, serial, dev_file, host, zc, port log.info(log.bold(printer_name)) log.info(log.bold('-'*len(printer_name))) x = "Unknown" if back_end == 'hpfax': x = "Fax" elif back_end == 'hp': x = "Printer" log.info("Type: %s" % x) #if is_hp: # x = 'Yes, using the %s: CUPS backend.' % back_end #else: # x = 'No, not using the hp: or hpfax: CUPS backend.' # non_hp = True #log.info("Installed in HPLIP?: %s" % x) log.info("Device URI: %s" % device_uri) ppd = os.path.join('/etc/cups/ppd', printer_name + '.ppd') if os.path.exists(ppd): log.info("PPD: %s" % ppd) nickname_pat = re.compile(r'''\*NickName:\s*\"(.*)"''', re.MULTILINE) try: f = to_string_utf8(open(ppd, 'rb').read()) except IOError: log.warn("Failed to read %s ppd file"%ppd) desc = '' else: try: desc = nickname_pat.search(f).group(1) except AttributeError: desc = '' log.info("PPD Description: %s" % desc) status, output = utils.run('lpstat -p%s' % printer_name) log.info("Printer status: %s" % output.replace("\n", "")) if back_end == 'hpfax' and not 'HP Fax' in desc and desc != '': self.num_errors += 1 log.error("Incorrect PPD file for fax queue '%s'. Fax queues must use 'HP-Fax(n)-hpcups.ppd'." % printer_name) elif back_end == 'hp' and 'HP Fax' in desc and desc != '': self.num_errors += 1 log.error("Incorrect PPD file for a print queue '%s'. Print queues must not use 'HP-Fax(n)-hpcups.ppd'." % printer_name) elif back_end not in ('hp', 'hpfax'): log.warn("Printer is not HPLIP installed. Printers must use the hp: or hpfax: CUPS backend for HP-Devices.") self.num_warns += 1 if device_avail and is_hp: d = None try: try: d = device.Device(device_uri,None, None, None, True) except Error: log.error("Device initialization failed.") continue plugin = d.mq.get('plugin', PLUGIN_NONE) if plugin in (PLUGIN_REQUIRED, PLUGIN_OPTIONAL): if not plugin_sts: from installer import pluginhandler pluginObj = pluginhandler.PluginHandle() plugin_sts = pluginObj.getStatus() if plugin_sts == pluginhandler.PLUGIN_INSTALLED: self.plugin_status = PLUGIN_INSTALLED if plugin == pluginhandler.PLUGIN_REQUIRED: log.info("Required plug-in status: Installed") else: log.info("Optional plug-in status: Installed") elif plugin_sts == pluginhandler.PLUGIN_NOT_INSTALLED: self.plugin_status = PLUGIN_NOT_INSTALLED if plugin == PLUGIN_REQUIRED: self.num_errors += 1 log.error("Required plug-in status: Not installed") else: self.num_warns +=1 log.warn("Optional plug-in status: Not installed") elif plugin_sts == pluginhandler.PLUGIN_VERSION_MISMATCH: self.num_warns += 1 self.plugin_status = pluginhandler.PLUGIN_VERSION_MISMATCH log.warn("plug-in status: Version mismatch") if bus in ('par', 'usb'): try: d.open() except Error as e: log.error(e.msg) deviceid = '' else: deviceid = d.getDeviceID() log.debug(deviceid) #print deviceid if not deviceid: log.error("Communication status: Failed") self.comm_error_devices[printer_name] = device_uri self.num_errors += 1 else: log.info("Communication status: Good") elif bus == 'net': try: error_code, deviceid = d.getPML(pml.OID_DEVICE_ID) except Error: pass #print error_code if not deviceid: log.error("Communication status: Failed") self.comm_error_devices[printer_name] = device_uri self.num_errors += 1 else: log.info("Communication status: Good") finally: if d is not None: d.close() log.info() else: log.warn("No queues found.") tui.header("PERMISSION") # sts,avl_grps_out =utils.run('groups') # sts, out = utils.check_user_groups(self.user_grps_cmd, avl_grps_out) # if sts: # log.info("%-15s %-30s %-15s %-8s %-8s %-8s %s"%("groups", "user-groups","Required", "-","-", "OK",avl_grps_out)) # else: # log.info(log.red("error: %-8s %-30s %-15s %-8s %-8s %-8s %s"%("groups", "user-groups", "Required","-", "-", "MISSING", out))) # self.num_errors += 1 # self.missing_user_grps = out if self.hpmudext_avail: lsusb = utils.which('lsusb') if lsusb: lsusb = os.path.join(lsusb, 'lsusb') status, output = utils.run("%s -d03f0:" % lsusb) if output: lsusb_pat = re.compile("""^Bus\s([0-9a-fA-F]{3,3})\sDevice\s([0-9a-fA-F]{3,3}):\sID\s([0-9a-fA-F]{4,4}):([0-9a-fA-F]{4,4})(.*)""", re.IGNORECASE) log.debug(output) try: import hpmudext except ImportError: log.error("NOT FOUND OR FAILED TO LOAD! Please reinstall HPLIP and check for the proper installation of hpmudext.") self.num_errors += 1 for o in output.splitlines(): ok = True match = lsusb_pat.search(o) if match is not None: bus, dev, vid, pid, mfg = match.groups() #log.info("\nHP Device 0x%x at %s:%s: " % (int(pid, 16), bus, dev)) result_code, deviceuri = hpmudext.make_usb_uri(bus, dev) if result_code == hpmudext.HPMUD_R_OK: deviceuri = to_string_utf8(deviceuri) # log.info(" Device URI: %s" % deviceuri) d = None try: d = device.Device(deviceuri,None, None, None, True) except Error: continue if not d.supported: continue else: log.debug(" Device URI: (Makeuri FAILED)") continue printers = cups.getPrinters() printer_name=None for p in printers: if p.device_uri == deviceuri: printer_name=p.name break devnode = os.path.join("/", "dev", "bus", "usb", bus, dev) if not os.path.exists(devnode): devnode = os.path.join("/", "proc", "bus", "usb", bus, dev) if os.path.exists(devnode): # log.debug(" Device node: %s" % devnode) st_mode, st_ino, st_dev, st_nlink, st_uid, st_gid, \ st_size, st_atime, st_mtime, st_ctime = os.stat(devnode) getfacl = utils.which('getfacl',True) if getfacl: # log.debug("%s %s" % (getfacl, devnode)) status, output = utils.run("%s %s" % (getfacl, devnode)) getfacl_out_list = output.split('\r\n') out ='' for g in getfacl_out_list: if 'getfacl' not in g and '' is not g and 'file' not in g: pat = re.compile('''.*:(.*)''') if pat.search(g): out = out +' '+ pat.search(g).group(1) log.info("%-15s %-30s %-15s %-8s %-8s %-8s %s"%("USB", printer_name, "Required", "-", "-", "OK", "Node:'%s' Perm:'%s'"%(devnode,out))) else: log.info("%-15s %-30s %-15s %-8s %-8s %-8s %s"%("USB", printer_name, "Required","-","-","OK", "Node:'%s' Mode:'%s'"%(devnode,st_mode&0o777))) # selinux_file = '/etc/selinux/config' # if os.path.exists(selinux_file): # tui.header("SELINUX") # try: # selinux_fp = open(selinux_file, 'r') # except IOError: # log.error("Failed to open %s file."%selinux_file) # else: # for line in selinux_fp: # line=re.sub(r'\s','',line) # if line == "SELINUX=enforcing": # self.num_warns += 1 # log.warn("%-12s %-12s %-10s %-3s %-3s %-8s %s" \ # %("SELinux", "enabled", "Optional", "-", "-", "INCOMPAT", "'SELinux needs to be disabled for Plugin printers and Fax functionality.'")) # self.disable_selinux = True # break # if self.disable_selinux == False: # log.info("%-15s %-15s %-10s %-3s %-3s %-8s %s"\ # %("SELinux", "disabled", "Optional", "-", "-", "OK", "-")) self.smart_install_devices = smart_install.get_smartinstall_enabled_devices() if len(self.smart_install_devices): tui.header("'CD-ROM'/'Smart Install' Detected Devices") self.num_errors += 1 for d in self.smart_install_devices: log.error("%-30s %-20s %s "%(d, "CD_ROM_Enabled", "Needs to disable Smart Install")) else: log.error("HPLIP not found.") self.num_errors += 1 if is_quiet_mode: log.set_where(org_log_location) return self.num_errors, self.num_warns
) log.info(commands_to_run[0]) elif len(commands_to_run) > 1: log.info( "To install this dependency, execute these commands:" ) for c in commands_to_run: log.info(c) log.info() if time_flag in (DEPENDENCY_RUN_TIME, DEPENDENCY_RUN_AND_COMPILE_TIME): tui.header("HPLIP INSTALLATION") scanning_enabled = utils.to_bool( sys_conf.get('configure', 'scanner-build', '0')) log.info() log.info(log.bold("Currently installed HPLIP version...")) v = sys_conf.get('hplip', 'version') home = sys_conf.get('dirs', 'home') if v: log.info("HPLIP %s currently installed in '%s'." % (v, home)) log.info() log.info( log.bold("Current contents of '/etc/hp/hplip.conf' file:")) try: output = file('/etc/hp/hplip.conf', 'r').read() except (IOError, OSError), e:
policy_kit = dbus.Interface(obj, "org.freedesktop.PolicyKit1.Authority") subject = ("system-bus-name", {"name": dbus.String(sender, variant_level=1)}) details = {"": ""} flags = dbus.UInt32(1) # AllowUserInteraction = 0x00000001 cancel_id = "" (ok, notused, details) = policy_kit.CheckAuthorization(subject, action, details, flags, cancel_id) if not ok: log.error("Session not authorized by PolicyKit version 1") raise AccessDeniedException("Session not authorized by PolicyKit") return ok if utils.to_bool(sys_conf.get("configure", "policy-kit")): class BackendService(PolicyKitService): INTERFACE_NAME = "com.hp.hplip" SERVICE_NAME = "com.hp.hplip" def __init__(self, connection=None, path="/"): if connection is None: connection = get_service_bus() super(BackendService, self).__init__(connection, path) self.name = dbus.service.BusName(self.SERVICE_NAME, connection) self.loop = gobject.MainLoop() self.version = 0 log.set_level("debug")