~ubuntu-branches/ubuntu/saucy/hplip/saucy-proposed

« back to all changes in this revision

Viewing changes to base/device.py

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2012-05-26 11:20:39 UTC
  • mfrom: (1.5.6) (31.1.3 precise)
  • Revision ID: package-import@ubuntu.com-20120526112039-bevxczegxnbyr5m7
Tags: 3.12.4-1
* New upstream release
* Switch to source/format 3.0 (quilt) - drop dpatch
* Refreshed debian/patches
* dh_autoreconf debian/autogen.sh & set local-options single-debian-patch
* Update to debian/compat -> 9
* Fix "hardened build flags" patch from Moritz - thanks (Closes: #667828)
* Fix "duplex descriptor uninitialized" patch from Matej (Closes: #583273)
* Fix "please migrate to kde-runtime" patch from Pino (Closes: #666544)

Show diffs side-by-side

added added

removed removed

Lines of Context:
96
96
 
97
97
### **********Lambda Function UniStar for checking type of arguments to constructor of class event*******************************
98
98
 
99
 
UniStr = lambda title: isinstance(title, str) and utils.xrstrip(title, '\x00')[:128] or utils.xrstrip(title, '\x00')[:128].encode('utf-8')  
 
99
UniStr = lambda title: isinstance(title, str) and utils.xrstrip(title, '\x00')[:128] or utils.xrstrip(title, '\x00')[:128].encode('utf-8')
100
100
 
101
101
 
102
102
#
1303
1303
 
1304
1304
    def openEWS_LEDM(self):
1305
1305
        return self.__openChannel(hpmudext.HPMUD_S_EWS_LEDM_CHANNEL)
1306
 
    
 
1306
 
1307
1307
    def openLEDM(self):
1308
1308
        return self.__openChannel(hpmudext.HPMUD_S_LEDM_SCAN)
1309
1309
 
1330
1330
 
1331
1331
    def closeEWS_LEDM(self):
1332
1332
        return self.__closeChannel(hpmudext.HPMUD_S_EWS_LEDM_CHANNEL)
1333
 
    
 
1333
 
1334
1334
    def closeLEDM(self):
1335
1335
        return self.__closeChannel(hpmudext.HPMUD_S_LEDM_SCAN)
1336
1336
 
1714
1714
 
1715
1715
            elif status_type == STATUS_TYPE_LEDM:
1716
1716
                log.debug("Type 10: LEDM")
1717
 
                status_block = status.StatusType10(self)
 
1717
                status_block = status.StatusType10(self.getEWSUrl_LEDM)
 
1718
 
 
1719
            elif status_type == STATUS_TYPE_LEDM_FF_CC_0:
 
1720
                log.debug("Type 11: LEDM_FF_CC_0")
 
1721
                status_block = status.StatusType10(self.getUrl_LEDM)
1718
1722
 
1719
1723
            else:
1720
1724
                log.error("Unimplemented status type: %d" % status_type)
2466
2470
                if footer:
2467
2471
                    return opener.open_hp(url2, data, footer)
2468
2472
                else:
2469
 
                    return opener.open_hp(url2, data) 
 
2473
                    return opener.open_hp(url2, data)
2470
2474
            except Error:
2471
2475
                log.debug("Status read failed: %s" % url2)
2472
2476
        finally:
2473
2477
            self.closeEWS_LEDM()
2474
 
    
 
2478
 
2475
2479
    def getUrl_LEDM(self, url, stream, footer=""):
2476
2480
        try:
2477
2481
            url2 = "%s&loc=%s" % (self.device_uri.replace('hpfax:', 'hp:'), url)
2481
2485
                if footer:
2482
2486
                    return opener.open_hp(url2, data, footer)
2483
2487
                else:
2484
 
                    return opener.open_hp(url2, data) 
 
2488
                    return opener.open_hp(url2, data)
2485
2489
            except Error:
2486
2490
                log.debug("Status read failed: %s" % url2)
2487
2491
 
2501
2505
        return data
2502
2506
 
2503
2507
#-------------------------For LEDM SOAP PROTOCOL(FAX) Devices----------------------------------------------------------------------#
2504
 
    
 
2508
 
2505
2509
    def FetchEWS_LEDMUrl(self, url, footer=""):
2506
2510
        data_fp = cStringIO.StringIO()
2507
2511
        if footer:
2521
2525
            log.error("Unable To read the XML data from device")
2522
2526
            return ""
2523
2527
        xmlDict = utils.XMLToDictParser().parseXML(data)
2524
 
        return str(xmlDict[attribute])
 
2528
        try:
 
2529
            return str(xmlDict[attribute])
 
2530
        except:
 
2531
            return str("")
2525
2532
 
2526
2533
#---------------------------------------------------------------------------------------------------#
2527
 
 
 
2534
 
2528
2535
    def readAttributeFromXml(self,uri,attribute):
2529
2536
        stream = cStringIO.StringIO()
2530
 
        data = self.FetchLEDMUrl(uri)        
 
2537
        data = self.FetchLEDMUrl(uri)
2531
2538
        if not data:
2532
2539
            log.error("Unable To read the XML data from device")
2533
2540
            return ""
2534
 
        xmlDict = utils.XMLToDictParser().parseXML(data)  
2535
 
        return str(xmlDict[attribute])
2536
 
                
 
2541
        xmlDict = utils.XMLToDictParser().parseXML(data)
 
2542
        try:
 
2543
            return str(xmlDict[attribute])
 
2544
        except:
 
2545
            return str("")
 
2546
 
2537
2547
    def downloadFirmware(self, usb_bus_id=None, usb_device_id=None): # Note: IDs not currently used
2538
2548
        ok = False
2539
2549
        filename = os.path.join(prop.data_dir, "firmware", self.model.lower() + '.fw.gz')
2630
2640
 
2631
2641
        reply = xStringIO()
2632
2642
 
2633
 
        while dev.readEWS_LEDM(8080, reply, timeout=3):
 
2643
        while dev.readEWS_LEDM(512, reply, timeout=3):
2634
2644
            pass
2635
2645
 
2636
2646
        reply.seek(0)
2656
2666
 
2657
2667
        reply = xStringIO()
2658
2668
 
2659
 
        while dev.readLEDM(8080, reply, timeout=3):
 
2669
        while dev.readLEDM(512, reply, timeout=3):
2660
2670
            pass
2661
2671
 
2662
2672
        reply.seek(0)
2663
2673
        return reply.getvalue()
2664
2674
 
2665
2675
 
2666
 
    
 
2676