def get_smartinstall_enabled_devices(): smartinstall_dev_list = [] lsusb_cmd = utils.which("lsusb", True) if not lsusb_cmd: log.error("Failed to find the lsusb command") return smartinstall_dev_list try: sts, out = utils.run(lsusb_cmd) if sts != 0: log.error("Failed to run the %s command" % lsusb_cmd) return smartinstall_dev_list for d in out.splitlines(): usb_dev_pat = re.compile(r""".*([0-9a-f]{4}:([0-9a-f]{4}))\s*""", re.I) if usb_dev_pat.match(d): vid_pid = usb_dev_pat.match(d).group(1) bsts, usb_params = get_usb_details(vid_pid) if not bsts: continue # These are not HP-devices log.debug( "Product['%s'],Interfaces[%s],InterfaceClass[%s]" % (usb_params["iProduct"], usb_params["bNumInterfaces"], usb_params["bInterfaceClass"]) ) if ( usb_params["bNumInterfaces"] == "1" and usb_params["bInterfaceClass"] == "8" and "laserjet" in usb_params["iProduct"].lower() ): #'8' is MASS STORAGE smartinstall_dev_list.append(usb_params["iProduct"]) else: log.warn("Failed to find vid and pid for USB device[%s]" % d) except KeyError: pass if smartinstall_dev_list: smartinstall_dev_list = utils.uniqueList(smartinstall_dev_list) return smartinstall_dev_list
def get_smartinstall_enabled_devices(): smartinstall_dev_list = [] lsusb_cmd = utils.which('lsusb', True) if not lsusb_cmd: log.error("Failed to find the lsusb command") return smartinstall_dev_list try: sts, out = utils.run(lsusb_cmd) if sts != 0: log.error("Failed to run the %s command" % lsusb_cmd) return smartinstall_dev_list for d in out.splitlines(): usb_dev_pat = re.compile(r""".*([0-9a-f]{4}:([0-9a-f]{4}))\s*""", re.I) if usb_dev_pat.match(d): vid_pid = usb_dev_pat.match(d).group(1) bsts, usb_params = get_usb_details(vid_pid) if not bsts: continue # These are not HP-devices log.debug( "Product['%s'],Interfaces[%s],InterfaceClass[%s]" % (usb_params["iProduct"], usb_params["bNumInterfaces"], usb_params["bInterfaceClass"])) if usb_params["bNumInterfaces"] == '1' and usb_params[ "bInterfaceClass"] == '8' and "laserjet" in usb_params[ "iProduct"].lower(): #'8' is MASS STORAGE smartinstall_dev_list.append(usb_params["iProduct"]) else: log.warn("Failed to find vid and pid for USB device[%s]" % d) except KeyError: pass if smartinstall_dev_list: smartinstall_dev_list = utils.uniqueList(smartinstall_dev_list) return smartinstall_dev_list
def __getPluginFilesList(self, src_dir): if not os.path.exists(src_dir+"/plugin.spec"): log.warn("%s/plugin.spec file doesn't exists."%src_dir) return [] cwd = os.getcwd() os.chdir(src_dir) plugin_spec = ConfigBase("plugin.spec") products = plugin_spec.keys("products") BITNESS = utils.getBitness() ENDIAN = utils.getEndian() PPDDIR = sys_conf.get('dirs', 'ppd') DRVDIR = sys_conf.get('dirs', 'drv') HOMEDIR = sys_conf.get('dirs', 'home') DOCDIR = sys_conf.get('dirs', 'doc') CUPSBACKENDDIR = sys_conf.get('dirs', 'cupsbackend') CUPSFILTERDIR = sys_conf.get('dirs', 'cupsfilter') RULESDIR = '/etc/udev/rules.d' BIN = sys_conf.get('dirs', 'bin') # Copying plugin.spec file to home dir. if src_dir != HOMEDIR: shutil.copyfile(src_dir+"/plugin.spec", HOMEDIR+"/plugin.spec") os.chmod(HOMEDIR+"/plugin.spec",0644) processor = utils.getProcessor() if processor == 'power_machintosh': ARCH = 'ppc' else: ARCH = 'x86_%d' % BITNESS if BITNESS == 64: SANELIBDIR = '/usr/lib64/sane' LIBDIR = '/usr/lib64' else: SANELIBDIR = '/usr/lib/sane' LIBDIR = '/usr/lib' copies = [] for PRODUCT in products: MODEL = PRODUCT.replace('hp-', '').replace('hp_', '') for s in plugin_spec.get("products", PRODUCT).split(','): if not plugin_spec.has_section(s): log.error("Missing section [%s]" % s) os.chdir(cwd) return [] src = plugin_spec.get(s, 'src', '') trg = plugin_spec.get(s, 'trg', '') link = plugin_spec.get(s, 'link', '') if not src: log.error("Missing 'src=' value in section [%s]" % s) os.chdir(cwd) return [] if not trg: log.error("Missing 'trg=' value in section [%s]" % s) os.chdir(cwd) return [] src = os.path.basename(utils.cat(src)) trg = utils.cat(trg) if link: link = utils.cat(link) copies.append((src, trg, link)) copies = utils.uniqueList(copies) copies.sort() os.chdir(cwd) return copies
def __getPluginFilesList(self, src_dir): if not os.path.exists(src_dir + "/plugin.spec"): log.warn("%s/plugin.spec file doesn't exists." % src_dir) return [] cwd = os.getcwd() os.chdir(src_dir) plugin_spec = ConfigBase("plugin.spec") products = plugin_spec.keys("products") BITNESS = utils.getBitness() ENDIAN = utils.getEndian() PPDDIR = sys_conf.get('dirs', 'ppd') DRVDIR = sys_conf.get('dirs', 'drv') HOMEDIR = sys_conf.get('dirs', 'home') DOCDIR = sys_conf.get('dirs', 'doc') CUPSBACKENDDIR = sys_conf.get('dirs', 'cupsbackend') CUPSFILTERDIR = sys_conf.get('dirs', 'cupsfilter') RULESDIR = '/etc/udev/rules.d' BIN = sys_conf.get('dirs', 'bin') # Copying plugin.spec file to home dir. if src_dir != HOMEDIR: shutil.copyfile(src_dir + "/plugin.spec", HOMEDIR + "/plugin.spec") os.chmod(HOMEDIR + "/plugin.spec", 0o644) processor = utils.getProcessor() if processor == 'power_machintosh': ARCH = 'ppc' elif (processor == 'armv6l' or processor == 'armv7l' or processor == 'aarch64' or processor == 'aarch32'): ARCH = 'arm%d' % BITNESS else: ARCH = 'x86_%d' % BITNESS if BITNESS == 64: SANELIBDIR = '/usr/lib64/sane' LIBDIR = '/usr/lib64' else: SANELIBDIR = '/usr/lib/sane' LIBDIR = '/usr/lib' copies = [] for PRODUCT in products: MODEL = PRODUCT.replace('hp-', '').replace('hp_', '') for s in plugin_spec.get("products", PRODUCT).split(','): if not plugin_spec.has_section(s): log.error("Missing section [%s]" % s) os.chdir(cwd) return [] src = plugin_spec.get(s, 'src', '') trg = plugin_spec.get(s, 'trg', '') link = plugin_spec.get(s, 'link', '') if not src: log.error("Missing 'src=' value in section [%s]" % s) os.chdir(cwd) return [] if not trg: log.error("Missing 'trg=' value in section [%s]" % s) os.chdir(cwd) return [] src = os.path.basename(utils.cat(src)) trg = utils.cat(trg) if link: link = utils.cat(link) copies.append((src, trg, link)) copies = utils.uniqueList(copies) copies.sort() os.chdir(cwd) return copies
import warnings # Ignore: .../dbus/connection.py:242: DeprecationWarning: object.__init__() takes no parameters # (occurring on Python 2.6/dBus 0.83/Ubuntu 9.04) warnings.simplefilter("ignore", DeprecationWarning) dbus_avail, service, session_bus = device.init_dbus() if not dbus_avail or service is None: log.error("Unable to initialize dBus. PC send fax requires dBus and hp-systray support. Exiting.") sys.exit(1) phone_num_list = [] log.debug("Faxnum list = %s" % faxnum_list) faxnum_list = utils.uniqueList(faxnum_list) log.debug("Unique list=%s" % faxnum_list) for f in faxnum_list: for c in f: if c not in '0123456789-(+) *#': log.error("Invalid character in fax number '%s'. Only the characters '0123456789-(+) *#' are valid." % f) sys.exit(1) log.debug("Group list = %s" % group_list) group_list = utils.uniqueList(group_list) log.debug("Unique list=%s" % group_list) for g in group_list: entries = db.group_members(g) if not entries:
def copyPluginFiles(src_dir): os.chdir(src_dir) plugin_spec = ConfigBase("plugin.spec") products = plugin_spec.keys("products") BITNESS = utils.getBitness() ENDIAN = utils.getEndian() PPDDIR = sys_conf.get('dirs', 'ppd') DRVDIR = sys_conf.get('dirs', 'drv') HOMEDIR = sys_conf.get('dirs', 'home') DOCDIR = sys_conf.get('dirs', 'doc') CUPSBACKENDDIR = sys_conf.get('dirs', 'cupsbackend') CUPSFILTERDIR = sys_conf.get('dirs', 'cupsfilter') RULESDIR = '/etc/udev/rules.d' processor = utils.getProcessor() if processor == 'power_machintosh': ARCH = 'ppc' else: ARCH = 'x86_%d' % BITNESS if BITNESS == 64: SANELIBDIR = '/usr/lib64/sane' LIBDIR = '/usr/lib64' else: SANELIBDIR = '/usr/lib/sane' LIBDIR = '/usr/lib' copies = [] for PRODUCT in products: MODEL = PRODUCT.replace('hp-', '').replace('hp_', '') UDEV_SYSFS_RULES=sys_conf.get('configure','udev_sysfs_rules','no') for s in plugin_spec.get("products", PRODUCT).split(','): if not plugin_spec.has_section(s): log.error("Missing section [%s]" % s) return False src = plugin_spec.get(s, 'src', '') trg = plugin_spec.get(s, 'trg', '') link = plugin_spec.get(s, 'link', '') # In Cent os 5.x distro's SYSFS attribute will be used. and Other distro's uses ATTR/ATTRS attribute in rules. # Following condition to check this... if UDEV_SYSFS_RULES == 'no' and 'sysfs' in src: continue if UDEV_SYSFS_RULES == 'yes' and 'sysfs' not in src: continue if not src: log.error("Missing 'src=' value in section [%s]" % s) return False if not trg: log.error("Missing 'trg=' value in section [%s]" % s) return False src = os.path.basename(utils.cat(src)) trg = utils.cat(trg) if link: link = utils.cat(link) copies.append((src, trg, link)) copies = utils.uniqueList(copies) copies.sort() os.umask(0) for src, trg, link in copies: if not os.path.exists(src): log.debug("Source file %s does not exist. Skipping." % src) continue if os.path.exists(trg): log.debug("Target file %s already exists. Replacing." % trg) os.remove(trg) trg_dir = os.path.dirname(trg) if not os.path.exists(trg_dir): log.debug("Target directory %s does not exist. Creating." % trg_dir) os.makedirs(trg_dir, 0755) if not os.path.isdir(trg_dir): log.error("Target directory %s exists but is not a directory. Skipping." % trg_dir) continue try: shutil.copyfile(src, trg) except (IOError, OSError), e: log.error("File copy failed: %s" % e.strerror) continue else: if not os.path.exists(trg): log.error("Target file %s does not exist. File copy failed." % trg) continue else: os.chmod(trg, stat.S_IRWXU | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH) if link: if os.path.exists(link): log.debug("Symlink already exists. Replacing.") os.remove(link) log.debug("Creating symlink %s (link) to file %s (target)..." % (link, trg)) try: os.symlink(trg, link) except (OSError, IOError), e: log.debug("Unable to create symlink: %s" % e.strerror) pass
def __init__(self, device_uri, printer_name, args, parent=None, name=None, modal=0, fl=0): QMainWindow.__init__(self,parent,name,fl) self.setIcon(load_pixmap('hp_logo', '128x128')) self.init_failed = False self.device_uri = device_uri self.dev = None self.printer_name = printer_name bus = ['cups'] self.filename = '' self.username = prop.username self.args = args self.setCentralWidget(QWidget(self,"qt_central_widget")) self.FormLayout = QGridLayout(self.centralWidget(),1,1,11,6,"FormLayout") self.resize(QSize(600,480).expandedTo(self.minimumSizeHint())) self.clearWState(Qt.WState_Polished) self.languageChange() # if self.device_uri and self.printer_name: # log.error("You may not specify both a printer (-p) and a device (-d).") # self.FailureUI(self.__tr("<p><b>You may not specify both a printer (-p) and a device (-d).")) # self.device_uri, self.printer_name = None, None # self.init_failed = True self.cups_printers = cups.getPrinters() log.debug(self.cups_printers) if self.printer_name: found = False for p in self.cups_printers: if p.name == printer_name: self.device_uri = p.device_uri found = True break if not found: self.FailureUI(self.__tr("<b>Unknown printer name: %1</b><p>Please check the printer name and try again.").arg(self.printer_name)) if found and not p.device_uri.startswith('hpfax:/'): self.FailureUI(self.__tr("You must specify a printer that has a device URI in the form 'hpfax:/...'")) self.init_failed = True if not self.device_uri and not self.printer_name: t = device.probeDevices(bus=bus, filter={'fax-type':(operator.gt, FAX_TYPE_NONE)}) #print t probed_devices = [] for d in t: probed_devices.append(d.replace('hp:/', 'hpfax:/')) #print probed_devices probed_devices = utils.uniqueList(probed_devices) log.debug(probed_devices) max_deviceid_size, x, devices = 0, 0, {} for d in probed_devices: printers = [] for p in self.cups_printers: #print p.device_uri, d if p.device_uri == d: #print "OK" printers.append(p.name) devices[x] = (d, printers) x += 1 max_deviceid_size = max(len(d), max_deviceid_size) x = len(devices) #print devices if x == 0: from .nodevicesform import NoDevicesForm self.FailureUI(self.__tr("<p><b>No devices found.</b><p>Please make sure your device is properly installed and try again.")) self.init_failed = True elif x == 1: log.info(log.bold("Using device: %s" % devices[0][0])) self.device_uri = devices[0][0] else: from .chooseprinterdlg import ChoosePrinterDlg dlg = ChoosePrinterDlg(self.cups_printers, ['hpfax']) if dlg.exec_loop() == QDialog.Accepted: self.device_uri = dlg.device_uri else: self.init_failed = True self.dbus_avail, self.service, session_bus = device.init_dbus() self.FaxView = ScrollFaxView(self.service, self.centralWidget(), self) self.FormLayout.addWidget(self.FaxView,0,0) if not self.init_failed: if not self.device_uri or not self.device_uri.startswith("hpfax:"): log.error("Invalid device URI: %s" % repr(device_uri)) self.FailureUI(self.__tr("<b>Invalid device URI %1.</b><p>Please check the parameters to hp-print and try again.").arg(repr(device_uri))); self.init_failed = True else: try: self.cur_device = device.Device(device_uri=self.device_uri, printer_name=self.printer_name) except Error as e: log.error("Invalid device URI or printer name.") self.FailureUI("<b>Invalid device URI or printer name.</b><p>Please check the parameters to hp-print and try again.") self.init_failed = True else: self.device_uri = self.cur_device.device_uri user_conf.set('last_used', 'device_uri', self.device_uri) log.debug(self.device_uri) self.statusBar().message(self.device_uri) QTimer.singleShot(0, self.InitialUpdate)
def __init__(self, device_uri, printer_name, args, parent=None, name=None, modal=0, fl=0): QMainWindow.__init__(self, parent, name, fl) self.setIcon(load_pixmap('hp_logo', '128x128')) self.init_failed = False self.device_uri = device_uri self.dev = None self.printer_name = printer_name bus = ['cups'] self.filename = '' self.username = prop.username self.args = args self.setCentralWidget(QWidget(self, "qt_central_widget")) self.FormLayout = QGridLayout(self.centralWidget(), 1, 1, 11, 6, "FormLayout") self.resize(QSize(600, 480).expandedTo(self.minimumSizeHint())) self.clearWState(Qt.WState_Polished) self.languageChange() # if self.device_uri and self.printer_name: # log.error("You may not specify both a printer (-p) and a device (-d).") # self.FailureUI(self.__tr("<p><b>You may not specify both a printer (-p) and a device (-d).")) # self.device_uri, self.printer_name = None, None # self.init_failed = True self.cups_printers = cups.getPrinters() log.debug(self.cups_printers) if self.printer_name: found = False for p in self.cups_printers: if p.name == printer_name: self.device_uri = p.device_uri found = True break if not found: self.FailureUI( self.__tr( "<b>Unknown printer name: %1</b><p>Please check the printer name and try again." ).arg(self.printer_name)) if found and not p.device_uri.startswith('hpfax:/'): self.FailureUI( self.__tr( "You must specify a printer that has a device URI in the form 'hpfax:/...'" )) self.init_failed = True if not self.device_uri and not self.printer_name: t = device.probeDevices( bus=bus, filter={'fax-type': (operator.gt, FAX_TYPE_NONE)}) #print t probed_devices = [] for d in t: probed_devices.append(d.replace('hp:/', 'hpfax:/')) #print probed_devices probed_devices = utils.uniqueList(probed_devices) log.debug(probed_devices) max_deviceid_size, x, devices = 0, 0, {} for d in probed_devices: printers = [] for p in self.cups_printers: #print p.device_uri, d if p.device_uri == d: #print "OK" printers.append(p.name) devices[x] = (d, printers) x += 1 max_deviceid_size = max(len(d), max_deviceid_size) x = len(devices) #print devices if x == 0: from nodevicesform import NoDevicesForm self.FailureUI( self.__tr( "<p><b>No devices found.</b><p>Please make sure your device is properly installed and try again." )) self.init_failed = True elif x == 1: log.info(log.bold("Using device: %s" % devices[0][0])) self.device_uri = devices[0][0] else: from chooseprinterdlg import ChoosePrinterDlg dlg = ChoosePrinterDlg(self.cups_printers, ['hpfax']) if dlg.exec_loop() == QDialog.Accepted: self.device_uri = dlg.device_uri else: self.init_failed = True self.dbus_avail, self.service, session_bus = device.init_dbus() self.FaxView = ScrollFaxView(self.service, self.centralWidget(), self) self.FormLayout.addWidget(self.FaxView, 0, 0) if not self.init_failed: if not self.device_uri or not self.device_uri.startswith("hpfax:"): log.error("Invalid device URI: %s" % repr(device_uri)) self.FailureUI( self.__tr( "<b>Invalid device URI %1.</b><p>Please check the parameters to hp-print and try again." ).arg(repr(device_uri))) self.init_failed = True else: try: self.cur_device = device.Device( device_uri=self.device_uri, printer_name=self.printer_name) except Error, e: log.error("Invalid device URI or printer name.") self.FailureUI( "<b>Invalid device URI or printer name.</b><p>Please check the parameters to hp-print and try again." ) self.init_failed = True else: self.device_uri = self.cur_device.device_uri user_conf.set('last_used', 'device_uri', self.device_uri) log.debug(self.device_uri) self.statusBar().message(self.device_uri)