~ubuntu-branches/ubuntu/vivid/hplip/vivid-proposed

« back to all changes in this revision

Viewing changes to check.py

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2013-08-17 12:27:56 UTC
  • mfrom: (38.1.2 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130817122756-3bqj73ysasf646s8
Tags: 3.13.8-1
* New Upstream Release 
* Update Vcs: header
* Fixup field "section" in package hpijs-ppds
* Update libhpmud-dev Description: - duplicate-long-description
* Update debian/copyright - fixes copyright-refers-to-symlink-license
* Update Description: - fixes extended-description-is-probably-too-short

Show diffs side-by-side

added added

removed removed

Lines of Context:
203
203
            'xsane':            (False, ['scan'], "SANE-GUI", self.check_xsane,'0.9','FUNC#get_xsane_version'),
204
204
            'scanimage':        (False, ['scan'], "Shell-Scanning", self.check_scanimage,'1.0','scanimage --version'),
205
205
            'network':        (False, ['network'], "Network-wget", self.check_wget,'-','wget --version'),
 
206
            'avahi-utils':        (False, ['network'], "avahi-utils", self.check_avahi_utils, '-','avahi-browse --version'),
206
207
            },
207
208
            GENERALDEP:
208
209
            {'libpthread':       (True,  ['base'], "POSIX-Threads-Lib", self.check_libpthread,'-','FUNC#get_libpthread_version'),
482
483
                        log.info("No devices found.")
483
484
 
484
485
 
485
 
            tui.header("INSTALLED CUPS PRINTER QUEUES")
486
 
 
487
 
            lpstat_pat = re.compile(r"""(\S*): (.*)""", re.IGNORECASE)
488
 
            status, output = utils.run('lpstat -v')
489
 
            log.info()
490
 
 
491
 
            cups_printers = []
492
 
            plugin_sts = None
493
 
            for p in output.splitlines():
494
 
                try:
495
 
                    match = lpstat_pat.search(p)
496
 
                    printer_name = match.group(1)
497
 
                    device_uri = match.group(2)
498
 
                    cups_printers.append((printer_name, device_uri))
499
 
                except AttributeError:
500
 
                    pass
501
 
 
502
 
            log.debug(cups_printers)
503
 
            if cups_printers:
504
 
                #non_hp = False
505
 
                for p in cups_printers:
506
 
                    printer_name, device_uri = p
507
 
 
508
 
                    if device_uri.startswith("cups-pdf:/") or \
509
 
                        device_uri.startswith('ipp://'):
510
 
                        continue
511
 
 
 
486
                tui.header("INSTALLED CUPS PRINTER QUEUES")
 
487
 
 
488
                lpstat_pat = re.compile(r"""(\S*): (.*)""", re.IGNORECASE)
 
489
                status, output = utils.run('lpstat -v')
 
490
                log.info()
 
491
 
 
492
                cups_printers = []
 
493
                plugin_sts = None
 
494
                for p in output.splitlines():
512
495
                    try:
513
 
                        back_end, is_hp, bus, model, serial, dev_file, host, zc, port = \
514
 
                            device.parseDeviceURI(device_uri)
515
 
                    except Error:
516
 
                        back_end, is_hp, bus, model, serial, dev_file, host, zc, port = \
517
 
                            '', False, '', '', '', '', '', '', 1
518
 
 
519
 
                    #print back_end, is_hp, bus, model, serial, dev_file, host, zc, port
520
 
 
521
 
                    log.info(log.bold(printer_name))
522
 
                    log.info(log.bold('-'*len(printer_name)))
523
 
 
524
 
                    x = "Unknown"
525
 
                    if back_end == 'hpfax':
526
 
                        x = "Fax"
527
 
                    elif back_end == 'hp':
528
 
                        x = "Printer"
529
 
 
530
 
                    log.info("Type: %s" % x)
531
 
 
532
 
                    #if is_hp:
533
 
                    #    x = 'Yes, using the %s: CUPS backend.' % back_end
534
 
                    #else:
535
 
                    #    x = 'No, not using the hp: or hpfax: CUPS backend.'
536
 
                    #    non_hp = True
537
 
 
538
 
                    #log.info("Installed in HPLIP?: %s" % x)
539
 
                    log.info("Device URI: %s" % device_uri)
540
 
 
541
 
                    ppd = os.path.join('/etc/cups/ppd', printer_name + '.ppd')
542
 
 
543
 
                    if os.path.exists(ppd):
544
 
                        log.info("PPD: %s" % ppd)
545
 
                        nickname_pat = re.compile(r'''\*NickName:\s*\"(.*)"''', re.MULTILINE)
 
496
                        match = lpstat_pat.search(p)
 
497
                        printer_name = match.group(1)
 
498
                        device_uri = match.group(2)
 
499
                        cups_printers.append((printer_name, device_uri))
 
500
                    except AttributeError:
 
501
                        pass
 
502
 
 
503
                log.debug(cups_printers)
 
504
                if cups_printers:
 
505
                    #non_hp = False
 
506
                    for p in cups_printers:
 
507
                        printer_name, device_uri = p
 
508
 
 
509
                        if device_uri.startswith("cups-pdf:/") or \
 
510
                            device_uri.startswith('ipp://'):
 
511
                            continue
 
512
 
546
513
                        try:
547
 
                            f = file(ppd, 'r').read(4096)
548
 
                        except IOError:
549
 
                            log.warn("Failed to read %s ppd file"%ppd)
550
 
                            desc = ''
551
 
                        else:
 
514
                            back_end, is_hp, bus, model, serial, dev_file, host, zc, port = \
 
515
                                device.parseDeviceURI(device_uri)
 
516
                        except Error:
 
517
                            back_end, is_hp, bus, model, serial, dev_file, host, zc, port = \
 
518
                                '', False, '', '', '', '', '', '', 1
 
519
 
 
520
                        #print back_end, is_hp, bus, model, serial, dev_file, host, zc, port
 
521
 
 
522
                        log.info(log.bold(printer_name))
 
523
                        log.info(log.bold('-'*len(printer_name)))
 
524
 
 
525
                        x = "Unknown"
 
526
                        if back_end == 'hpfax':
 
527
                            x = "Fax"
 
528
                        elif back_end == 'hp':
 
529
                            x = "Printer"
 
530
 
 
531
                        log.info("Type: %s" % x)
 
532
 
 
533
                        #if is_hp:
 
534
                        #    x = 'Yes, using the %s: CUPS backend.' % back_end
 
535
                        #else:
 
536
                        #    x = 'No, not using the hp: or hpfax: CUPS backend.'
 
537
                        #    non_hp = True
 
538
 
 
539
                        #log.info("Installed in HPLIP?: %s" % x)
 
540
                        log.info("Device URI: %s" % device_uri)
 
541
 
 
542
                        ppd = os.path.join('/etc/cups/ppd', printer_name + '.ppd')
 
543
 
 
544
                        if os.path.exists(ppd):
 
545
                            log.info("PPD: %s" % ppd)
 
546
                            nickname_pat = re.compile(r'''\*NickName:\s*\"(.*)"''', re.MULTILINE)
552
547
                            try:
553
 
                                desc = nickname_pat.search(f).group(1)
554
 
                            except AttributeError:
 
548
                                f = file(ppd, 'r').read(4096)
 
549
                            except IOError:
 
550
                                log.warn("Failed to read %s ppd file"%ppd)
555
551
                                desc = ''
556
 
 
557
 
                        log.info("PPD Description: %s" % desc)
558
 
 
559
 
                        status, output = utils.run('lpstat -p%s' % printer_name)
560
 
                        log.info("Printer status: %s" % output.replace("\n", ""))
561
 
 
562
 
                        if back_end == 'hpfax' and not 'HP Fax' in desc:
563
 
                            self.num_errors += 1
564
 
                            log.error("Incorrect PPD file for fax queue '%s'. Fax queues must use 'HP-Fax-hplip.ppd'." % printer_name)
565
 
 
566
 
                        elif back_end == 'hp' and 'HP Fax' in desc:
567
 
                            self.num_errors += 1
568
 
                            log.error("Incorrect PPD file for a print queue '%s'. Print queues must not use 'HP-Fax-hplip.ppd'." % printer_name)
569
 
 
570
 
                        elif back_end not in ('hp', 'hpfax'):
571
 
                            log.warn("Printer is not HPLIP installed. Printers must use the hp: or hpfax: CUPS backend for HP-Devices.")
572
 
                            self.num_warns += 1
573
 
 
574
 
                    if device_avail and is_hp:
575
 
                        d = None
576
 
                        try:
 
552
                            else:
 
553
                                try:
 
554
                                    desc = nickname_pat.search(f).group(1)
 
555
                                except AttributeError:
 
556
                                    desc = ''
 
557
 
 
558
                            log.info("PPD Description: %s" % desc)
 
559
 
 
560
                            status, output = utils.run('lpstat -p%s' % printer_name)
 
561
                            log.info("Printer status: %s" % output.replace("\n", ""))
 
562
 
 
563
                            if back_end == 'hpfax' and not 'HP Fax' in desc:
 
564
                                self.num_errors += 1
 
565
                                log.error("Incorrect PPD file for fax queue '%s'. Fax queues must use 'HP-Fax-hplip.ppd'." % printer_name)
 
566
 
 
567
                            elif back_end == 'hp' and 'HP Fax' in desc:
 
568
                                self.num_errors += 1
 
569
                                log.error("Incorrect PPD file for a print queue '%s'. Print queues must not use 'HP-Fax-hplip.ppd'." % printer_name)
 
570
 
 
571
                            elif back_end not in ('hp', 'hpfax'):
 
572
                                log.warn("Printer is not HPLIP installed. Printers must use the hp: or hpfax: CUPS backend for HP-Devices.")
 
573
                                self.num_warns += 1
 
574
 
 
575
                        if device_avail and is_hp:
 
576
                            d = None
577
577
                            try:
578
 
                                d = device.Device(device_uri,None, None, None, True)
579
 
                            except Error:
580
 
                                log.error("Device initialization failed.")
581
 
                                continue
582
 
 
583
 
                            plugin = d.mq.get('plugin', PLUGIN_NONE)
584
 
                            if plugin in (PLUGIN_REQUIRED, PLUGIN_OPTIONAL):
585
 
                                if not plugin_sts:
586
 
                                    from installer import pluginhandler
587
 
                                    pluginObj = pluginhandler.PluginHandle()
588
 
                                    plugin_sts = pluginObj.getStatus()
589
 
 
590
 
                                if plugin_sts == pluginhandler.PLUGIN_INSTALLED:
591
 
                                    self.plugin_status = PLUGIN_INSTALLED
592
 
                                    if plugin == pluginhandler.PLUGIN_REQUIRED:
593
 
                                        log.info("Required plug-in status: Installed")
594
 
                                    else:
595
 
                                        log.info("Optional plug-in status: Installed")
596
 
                                elif plugin_sts == pluginhandler.PLUGIN_NOT_INSTALLED:
597
 
                                    self.plugin_status = PLUGIN_NOT_INSTALLED
598
 
                                    if plugin == PLUGIN_REQUIRED:
599
 
                                        self.num_errors += 1
600
 
                                        log.error("Required plug-in status: Not installed")
601
 
                                    else:
602
 
                                        self.num_warns +=1
603
 
                                        log.warn("Optional plug-in status: Not installed")
604
 
                                elif plugin_sts == pluginhandler.PLUGIN_VERSION_MISMATCH:
605
 
                                    self.num_warns += 1
606
 
                                    self.plugin_status = pluginhandler.PLUGIN_VERSION_MISMATCH
607
 
                                    log.warn("plug-in status: Version mismatch")
608
 
 
609
 
 
610
 
                            if bus in ('par', 'usb'):
611
 
                                try:
612
 
                                    d.open()
613
 
                                except Error, e:
614
 
                                    log.error(e.msg)
615
 
                                    deviceid = ''
616
 
                                else:
617
 
                                    deviceid = d.getDeviceID()
618
 
                                    log.debug(deviceid)
619
 
 
620
 
                                #print deviceid
621
 
                                if not deviceid:
622
 
                                    log.error("Communication status: Failed")
623
 
                                    self.comm_error_devices[printer_name] = device_uri
624
 
                                    self.num_errors += 1
625
 
                                else:
626
 
                                    log.info("Communication status: Good")
627
 
 
628
 
                            elif bus == 'net':
629
 
                                try:
630
 
                                    error_code, deviceid = d.getPML(pml.OID_DEVICE_ID)
 
578
                                try:
 
579
                                    d = device.Device(device_uri,None, None, None, True)
631
580
                                except Error:
632
 
                                    pass
633
 
 
634
 
                                #print error_code
635
 
                                if not deviceid:
636
 
                                    log.error("Communication status: Failed")
637
 
                                    self.comm_error_devices[printer_name] = device_uri
638
 
                                    self.num_errors += 1
639
 
                                else:
640
 
                                    log.info("Communication status: Good")
641
 
 
642
 
                        finally:
643
 
                            if d is not None:
644
 
                                d.close()
645
 
                    log.info()
646
 
            else:
647
 
                log.warn("No queues found.")
 
581
                                    log.error("Device initialization failed.")
 
582
                                    continue
 
583
 
 
584
                                plugin = d.mq.get('plugin', PLUGIN_NONE)
 
585
                                if plugin in (PLUGIN_REQUIRED, PLUGIN_OPTIONAL):
 
586
                                    if not plugin_sts:
 
587
                                        from installer import pluginhandler
 
588
                                        pluginObj = pluginhandler.PluginHandle()
 
589
                                        plugin_sts = pluginObj.getStatus()
 
590
 
 
591
                                    if plugin_sts == pluginhandler.PLUGIN_INSTALLED:
 
592
                                        self.plugin_status = PLUGIN_INSTALLED
 
593
                                        if plugin == pluginhandler.PLUGIN_REQUIRED:
 
594
                                            log.info("Required plug-in status: Installed")
 
595
                                        else:
 
596
                                            log.info("Optional plug-in status: Installed")
 
597
                                    elif plugin_sts == pluginhandler.PLUGIN_NOT_INSTALLED:
 
598
                                        self.plugin_status = PLUGIN_NOT_INSTALLED
 
599
                                        if plugin == PLUGIN_REQUIRED:
 
600
                                            self.num_errors += 1
 
601
                                            log.error("Required plug-in status: Not installed")
 
602
                                        else:
 
603
                                            self.num_warns +=1
 
604
                                            log.warn("Optional plug-in status: Not installed")
 
605
                                    elif plugin_sts == pluginhandler.PLUGIN_VERSION_MISMATCH:
 
606
                                        self.num_warns += 1
 
607
                                        self.plugin_status = pluginhandler.PLUGIN_VERSION_MISMATCH
 
608
                                        log.warn("plug-in status: Version mismatch")
 
609
 
 
610
 
 
611
                                if bus in ('par', 'usb'):
 
612
                                    try:
 
613
                                        d.open()
 
614
                                    except Error, e:
 
615
                                        log.error(e.msg)
 
616
                                        deviceid = ''
 
617
                                    else:
 
618
                                        deviceid = d.getDeviceID()
 
619
                                        log.debug(deviceid)
 
620
 
 
621
                                    #print deviceid
 
622
                                    if not deviceid:
 
623
                                        log.error("Communication status: Failed")
 
624
                                        self.comm_error_devices[printer_name] = device_uri
 
625
                                        self.num_errors += 1
 
626
                                    else:
 
627
                                        log.info("Communication status: Good")
 
628
 
 
629
                                elif bus == 'net':
 
630
                                    try:
 
631
                                        error_code, deviceid = d.getPML(pml.OID_DEVICE_ID)
 
632
                                    except Error:
 
633
                                        pass
 
634
 
 
635
                                    #print error_code
 
636
                                    if not deviceid:
 
637
                                        log.error("Communication status: Failed")
 
638
                                        self.comm_error_devices[printer_name] = device_uri
 
639
                                        self.num_errors += 1
 
640
                                    else:
 
641
                                        log.info("Communication status: Good")
 
642
 
 
643
                            finally:
 
644
                                if d is not None:
 
645
                                    d.close()
 
646
                        log.info()
 
647
                else:
 
648
                    log.warn("No queues found.")
648
649
 
649
650
            tui.header("PERMISSION")
650
651
            sts,avl_grps_out =utils.run('groups')
691
692
                                    if not d.supported:
692
693
                                        continue
693
694
                                else:
694
 
                                    log.warn("    Device URI: (Makeuri FAILED)")
 
695
                                    log.debug("    Device URI: (Makeuri FAILED)")
695
696
                                    continue
696
697
                                printers = cups.getPrinters()
697
698
                                printer_name=None
818
819
        log.info("Total Warnings: %d" % self.num_warns)
819
820
        log.info()
820
821
        if self.disable_selinux or self.missing_user_grps or (self.plugin_status == PLUGIN_VERSION_MISMATCH) or (self.plugin_status == PLUGIN_NOT_INSTALLED) or len(self.req_deps_to_be_installed) or len(self.opt_deps_to_be_installed):
821
 
             log.info("Re-run 'hp-doctor' command to prompt and fix the issues. ")
 
822
             log.info("Run 'hp-doctor' command to prompt and fix the issues. ")
822
823
             
823
824
 
824
825
############ Main #######################