/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
84
84
    Windows."""
85
85
    # TODO: I'm not really sure this is the best format either.x
86
86
    global _QUOTE_RE
87
 
    if _QUOTE_RE == None:
 
87
    if _QUOTE_RE is None:
88
88
        _QUOTE_RE = re.compile(r'([^a-zA-Z0-9.,:/\\_~-])')
89
89
        
90
90
    if _QUOTE_RE.search(f):
150
150
if lexists is None:
151
151
    def lexists(f):
152
152
        try:
153
 
            if hasattr(os, 'lstat'):
 
153
            if getattr(os, 'lstat') is not None:
154
154
                os.lstat(f)
155
155
            else:
156
156
                os.stat(f)
190
190
        pass
191
191
    except IOError, e:
192
192
        # RBC 20060103 abstraction leakage: the paramiko SFTP clients rename
193
 
        # function raises an IOError with errno == None when a rename fails.
 
193
        # function raises an IOError with errno is None when a rename fails.
194
194
        # This then gets caught here.
195
195
        if e.errno not in (None, errno.ENOENT, errno.ENOTDIR):
196
196
            raise
197
197
    except Exception, e:
198
 
        if (not hasattr(e, 'errno') 
 
198
        if (getattr(e, 'errno', None) is None
199
199
            or e.errno not in (errno.ENOENT, errno.ENOTDIR)):
200
200
            raise
201
201
    else:
370
370
 
371
371
 
372
372
def normalizepath(f):
373
 
    if hasattr(os.path, 'realpath'):
 
373
    if getattr(os.path, 'realpath', None) is not None:
374
374
        F = realpath
375
375
    else:
376
376
        F = abspath
505
505
 
506
506
 
507
507
def sha_file(f):
508
 
    if hasattr(f, 'tell'):
 
508
    if getattr(f, 'tell', None) is not None:
509
509
        assert f.tell() == 0
510
510
    s = sha.new()
511
511
    BUFSIZE = 128<<10
555
555
def local_time_offset(t=None):
556
556
    """Return offset of local zone from GMT, either at present or at time t."""
557
557
    # python2.3 localtime() can't take None
558
 
    if t == None:
 
558
    if t is None:
559
559
        t = time.time()
560
560
        
561
561
    if time.localtime(t).tm_isdst and time.daylight:
574
574
        tt = time.gmtime(t)
575
575
        offset = 0
576
576
    elif timezone == 'original':
577
 
        if offset == None:
 
577
        if offset is None:
578
578
            offset = 0
579
579
        tt = time.gmtime(t + offset)
580
580
    elif timezone == 'local':
596
596
    return time.strftime('%Y%m%d%H%M%S', time.gmtime(when))
597
597
    
598
598
 
 
599
def format_delta(delta):
 
600
    """Get a nice looking string for a time delta.
 
601
 
 
602
    :param delta: The time difference in seconds, can be positive or negative.
 
603
        positive indicates time in the past, negative indicates time in the
 
604
        future. (usually time.time() - stored_time)
 
605
    :return: String formatted to show approximate resolution
 
606
    """
 
607
    delta = int(delta)
 
608
    if delta >= 0:
 
609
        direction = 'ago'
 
610
    else:
 
611
        direction = 'in the future'
 
612
        delta = -delta
 
613
 
 
614
    seconds = delta
 
615
    if seconds < 90: # print seconds up to 90 seconds
 
616
        if seconds == 1:
 
617
            return '%d second %s' % (seconds, direction,)
 
618
        else:
 
619
            return '%d seconds %s' % (seconds, direction)
 
620
 
 
621
    minutes = int(seconds / 60)
 
622
    seconds -= 60 * minutes
 
623
    if seconds == 1:
 
624
        plural_seconds = ''
 
625
    else:
 
626
        plural_seconds = 's'
 
627
    if minutes < 90: # print minutes, seconds up to 90 minutes
 
628
        if minutes == 1:
 
629
            return '%d minute, %d second%s %s' % (
 
630
                    minutes, seconds, plural_seconds, direction)
 
631
        else:
 
632
            return '%d minutes, %d second%s %s' % (
 
633
                    minutes, seconds, plural_seconds, direction)
 
634
 
 
635
    hours = int(minutes / 60)
 
636
    minutes -= 60 * hours
 
637
    if minutes == 1:
 
638
        plural_minutes = ''
 
639
    else:
 
640
        plural_minutes = 's'
 
641
 
 
642
    if hours == 1:
 
643
        return '%d hour, %d minute%s %s' % (hours, minutes,
 
644
                                            plural_minutes, direction)
 
645
    return '%d hours, %d minute%s %s' % (hours, minutes,
 
646
                                         plural_minutes, direction)
599
647
 
600
648
def filesize(f):
601
649
    """Return size of given open file."""
676
724
def joinpath(p):
677
725
    assert isinstance(p, list)
678
726
    for f in p:
679
 
        if (f == '..') or (f == None) or (f == ''):
 
727
        if (f == '..') or (f is None) or (f == ''):
680
728
            raise BzrError("sorry, %r not allowed in path" % f)
681
729
    return pathjoin(*p)
682
730
 
726
774
 
727
775
 
728
776
def has_symlinks():
729
 
    if hasattr(os, 'symlink'):
 
777
    if getattr(os, 'symlink', None) is not None:
730
778
        return True
731
779
    else:
732
780
        return False
1052
1100
        _cached_user_encoding = locale.getpreferredencoding()
1053
1101
    except locale.Error, e:
1054
1102
        sys.stderr.write('bzr: warning: %s\n'
1055
 
                         '  Could not what text encoding to use.\n'
 
1103
                         '  Could not determine what text encoding to use.\n'
1056
1104
                         '  This error usually means your Python interpreter\n'
1057
1105
                         '  doesn\'t support the locale set by $LANG (%s)\n'
1058
1106
                         "  Continuing with ascii encoding.\n"