~ubuntu-branches/ubuntu/gutsy/hplip/gutsy-security

« back to all changes in this revision

Viewing changes to base/utils.py

  • Committer: Bazaar Package Importer
  • Author(s): Till Kamppeter
  • Date: 2006-09-15 18:00:07 UTC
  • mfrom: (1.2.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20060915180007-96mez3nck3oy5wij
Tags: 1.6.7-2ubuntu1
* Merge from debian unstable.
* Removed patches 50_ui-supportform-cleanups.dpatch and
  55_ui-supportform-debian.dpatch, there is no support window in the HP
  toolbox any more.
* HPLIP (file io/hpiod/usbext.h) includes linux/compiler.h which is not
  part of Ubuntu Linux and not needed. Removed the include with patch
  80_no-compiler.h.dpatch.
* debian/control: Let the "Conflicts:" of hpijs-ppds be only a "Breaks:"
  to facilitate an update from the previous version when both hpijs and
  hpijs-ppds are installed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
534
534
def log_title(program_name, version):
535
535
    log.info("")
536
536
    log.info(bold("HP Linux Imaging and Printing System (ver. %s)" % prop.version))
537
 
    log.info(bold("%s ver. %s" % (program_name,version)))
 
537
    log.info(bold("%s ver. %s" % (program_name, version)))
538
538
    log.info("")
539
539
    log.info("Copyright (c) 2003-6 Hewlett-Packard Development Company, LP")
540
540
    log.info("This software comes with ABSOLUTELY NO WARRANTY.")
543
543
    log.info("")
544
544
 
545
545
 
546
 
def which(command):
 
546
def which(command, return_full_path=False):
547
547
    path = os.getenv('PATH').split(':')
 
548
 
 
549
    # Add these paths for Fedora
 
550
    path.append('/sbin')
 
551
    path.append('/usr/sbin')
 
552
    path.append('/usr/local/sbin')
 
553
 
548
554
    found_path = ''
549
555
    for p in path:
550
556
        try:
556
562
                found_path = p
557
563
                break
558
564
 
559
 
    return found_path
 
565
    if return_full_path:
 
566
        if found_path:
 
567
            return os.path.join(found_path, command)
 
568
        else:
 
569
            return ''
 
570
    else:
 
571
        return found_path
560
572
 
561
573
 
562
574
def deviceDefaultFunctions():
615
627
        cmd_pcard = 'python %HOME%/unload.py -d %DEVICE_URI%'
616
628
 
617
629
    # Copy
 
630
    path = which('hp-makecopies')
 
631
 
 
632
    if len(path):
 
633
        cmd_copy = 'hp-makecopies -d %DEVICE_URI%'
 
634
 
 
635
    else:
 
636
        cmd_copy = 'python %HOME%/makecopies.py -d %DEVICE_URI%'
618
637
 
619
638
    # Fax
620
639
    path = which('hp-sendfax')
913
932
                log.error("Duplicate model in XML: %s" % self.cur_model)
914
933
                raise Error(ERROR_INTERNAL)
915
934
 
916
 
            print self.cur_model
 
935
            #print self.cur_model
917
936
            self.models[self.cur_model] = self.model
918
937
 
919
938
            self.model = None
960
979
    return True
961
980
 
962
981
def openURL(url):
963
 
    browsers = ['firefox', 'mozilla', 'konqueror', 'galeon', 'skipstone']
 
982
    browsers = ['firefox', 'mozilla', 'konqueror', 'galeon', 'skipstone'] # in preferred order
 
983
    browser_opt = {'firefox': '-new-window', 'mozilla' : '', 'konqueror': '', 'galeon': '-w', 'skipstone': ''}
 
984
    
964
985
    for b in browsers:
 
986
        print b
965
987
        if which(b):
966
 
            cmd = "%s %s &" % (b, url)
 
988
            cmd = "%s %s %s &" % (b, browser_opt[b], url)
967
989
            log.debug(cmd)
968
990
            os.system(cmd)
969
991
            break
1086
1108
USAGE_DEVICE = ("To specify a device-URI:", "-d<device-uri> or --device=<device-uri>", "option", False)
1087
1109
USAGE_PRINTER = ("To specify a CUPS printer:", "-p<printer> or --printer=<printer>", "option", False)
1088
1110
USAGE_BUS1 = ("Bus to probe (if device not specified):", "-b<bus> or --bus=<bus>", "option", False)
1089
 
USAGE_BUS2 = ("", "<bus>: cups\*, usb*, net, bt, fw, par\* (\*default) (Note: bt and fw not supported in this release", 'option', False)
 
1111
USAGE_BUS2 = ("", "<bus>: cups\*, usb*, net, bt, fw, par\* (\*defaults) (Note: bt and fw not supported in this release.)", 'option', False)
1090
1112
USAGE_HELP = ("This help information:", "-h or --help", "option", True)
1091
1113
USAGE_SPACE = ("", "", "space", False)
1092
1114
USAGE_EXAMPLES = ("Examples:", "", "heading", False)
1170
1192
        for line in text_list:
1171
1193
            text1, text2, format, trailing_space = line
1172
1194
 
1173
 
            if format in ('option', 'example'):
 
1195
            if format in ('option', 'example', 'note'):
1174
1196
                colwidth1 = max(len(text1), colwidth1)
1175
1197
                colwidth2 = max(len(text2), colwidth2)
1176
1198
            
1272
1294
                log.info(text1)
1273
1295
                
1274
1296
        log.info("")
 
1297
        
 
1298
        
 
1299
def dquote(s):
 
1300
    return ''.join(['"', s, '"'])
 
1301
    
 
1302
# Python 2.2 compatibility functions (strip() family with char argument)
 
1303
def xlstrip(s, chars=' '):
 
1304
    i = 0
 
1305
    for c, i in zip(s, range(len(s))):
 
1306
        if c not in chars:
 
1307
            break
 
1308
    
 
1309
    return s[i:]
 
1310
            
 
1311
def xrstrip(s, chars=' '):
 
1312
    return xreverse(xlstrip(xreverse(s), chars))
 
1313
 
 
1314
def xreverse(s):
 
1315
    l = list(s)
 
1316
    l.reverse()
 
1317
    return ''.join(l)
 
1318
 
 
1319
def xstrip(s, chars=' '):
 
1320
    return xreverse(xlstrip(xreverse(xlstrip(s, chars)), chars))
 
1321
 
 
1322
    
 
1323
 
 
1324
def getBitness():
 
1325
    try:
 
1326
        import platform
 
1327
    except ImportError:
 
1328
        return struct.calcsize("P") << 3
 
1329
    else:
 
1330
        return int(platform.architecture()[0][:-3])
 
1331
 
 
1332
        
 
1333
BIG_ENDIAN = 0
 
1334
LITTLE_ENDIAN = 1
 
1335
 
 
1336
def getEndian():
 
1337
    if struct.pack("@I", 0x01020304)[0] == '\x01':
 
1338
        return BIG_ENDIAN
 
1339
    else:
 
1340
        return LITTLE_ENDIAN
 
1341
        
 
1342
        
 
1343
 
 
1344