/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

  • Committer: John Arbash Meinel
  • Date: 2006-10-06 05:53:44 UTC
  • mfrom: (2063 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2071.
  • Revision ID: john@arbash-meinel.com-20061006055344-e73b97b7c6ca6e72
[merge] bzr.dev 2063

Show diffs side-by-side

added added

removed removed

Lines of Context:
597
597
    return time.strftime('%Y%m%d%H%M%S', time.gmtime(when))
598
598
    
599
599
 
 
600
def format_delta(delta):
 
601
    """Get a nice looking string for a time delta.
 
602
 
 
603
    :param delta: The time difference in seconds, can be positive or negative.
 
604
        positive indicates time in the past, negative indicates time in the
 
605
        future. (usually time.time() - stored_time)
 
606
    :return: String formatted to show approximate resolution
 
607
    """
 
608
    delta = int(delta)
 
609
    if delta >= 0:
 
610
        direction = 'ago'
 
611
    else:
 
612
        direction = 'in the future'
 
613
        delta = -delta
 
614
 
 
615
    seconds = delta
 
616
    if seconds < 90: # print seconds up to 90 seconds
 
617
        if seconds == 1:
 
618
            return '%d second %s' % (seconds, direction,)
 
619
        else:
 
620
            return '%d seconds %s' % (seconds, direction)
 
621
 
 
622
    minutes = int(seconds / 60)
 
623
    seconds -= 60 * minutes
 
624
    if seconds == 1:
 
625
        plural_seconds = ''
 
626
    else:
 
627
        plural_seconds = 's'
 
628
    if minutes < 90: # print minutes, seconds up to 90 minutes
 
629
        if minutes == 1:
 
630
            return '%d minute, %d second%s %s' % (
 
631
                    minutes, seconds, plural_seconds, direction)
 
632
        else:
 
633
            return '%d minutes, %d second%s %s' % (
 
634
                    minutes, seconds, plural_seconds, direction)
 
635
 
 
636
    hours = int(minutes / 60)
 
637
    minutes -= 60 * hours
 
638
    if minutes == 1:
 
639
        plural_minutes = ''
 
640
    else:
 
641
        plural_minutes = 's'
 
642
 
 
643
    if hours == 1:
 
644
        return '%d hour, %d minute%s %s' % (hours, minutes,
 
645
                                            plural_minutes, direction)
 
646
    return '%d hours, %d minute%s %s' % (hours, minutes,
 
647
                                         plural_minutes, direction)
600
648
 
601
649
def filesize(f):
602
650
    """Return size of given open file."""
1039
1087
        _cached_user_encoding = locale.getpreferredencoding()
1040
1088
    except locale.Error, e:
1041
1089
        sys.stderr.write('bzr: warning: %s\n'
1042
 
                         '  Could not what text encoding to use.\n'
 
1090
                         '  Could not determine what text encoding to use.\n'
1043
1091
                         '  This error usually means your Python interpreter\n'
1044
1092
                         '  doesn\'t support the locale set by $LANG (%s)\n'
1045
1093
                         "  Continuing with ascii encoding.\n"