/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: Marius Kruger
  • Date: 2007-08-12 08:15:15 UTC
  • mfrom: (2695 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2979.
  • Revision ID: amanic@gmail.com-20070812081515-vgekipfhohcuj6rn
merge with bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
69
69
# OR with 0 on those platforms
70
70
O_BINARY = getattr(os, 'O_BINARY', 0)
71
71
 
 
72
# On posix, use lstat instead of stat so that we can
 
73
# operate on broken symlinks. On Windows revert to stat.
 
74
lstat = getattr(os, 'lstat', os.stat)
72
75
 
73
76
def make_readonly(filename):
74
77
    """Make a filename read-only."""
75
 
    mod = os.stat(filename).st_mode
76
 
    mod = mod & 0777555
77
 
    os.chmod(filename, mod)
 
78
    mod = lstat(filename).st_mode
 
79
    if not stat.S_ISLNK(mod):
 
80
        mod = mod & 0777555
 
81
        os.chmod(filename, mod)
78
82
 
79
83
 
80
84
def make_writable(filename):
81
 
    mod = os.stat(filename).st_mode
82
 
    mod = mod | 0200
83
 
    os.chmod(filename, mod)
 
85
    mod = lstat(filename).st_mode
 
86
    if not stat.S_ISLNK(mod):
 
87
        mod = mod | 0200
 
88
        os.chmod(filename, mod)
84
89
 
85
90
 
86
91
_QUOTE_RE = None
606
611
    return offset.days * 86400 + offset.seconds
607
612
 
608
613
    
609
 
def format_date(t, offset=0, timezone='original', date_fmt=None, 
 
614
def format_date(t, offset=0, timezone='original', date_fmt=None,
610
615
                show_offset=True):
611
 
    ## TODO: Perhaps a global option to use either universal or local time?
612
 
    ## Or perhaps just let people set $TZ?
613
 
    assert isinstance(t, float)
614
 
    
 
616
    """Return a formatted date string.
 
617
 
 
618
    :param t: Seconds since the epoch.
 
619
    :param offset: Timezone offset in seconds east of utc.
 
620
    :param timezone: How to display the time: 'utc', 'original' for the
 
621
         timezone specified by offset, or 'local' for the process's current
 
622
         timezone.
 
623
    :param show_offset: Whether to append the timezone.
 
624
    :param date_fmt: strftime format.
 
625
    """
615
626
    if timezone == 'utc':
616
627
        tt = time.gmtime(t)
617
628
        offset = 0
1143
1154
        path-from-top might be unicode or utf8, but it is the correct path to
1144
1155
        pass to os functions to affect the file in question. (such as os.lstat)
1145
1156
    """
1146
 
    fs_encoding = sys.getfilesystemencoding()
 
1157
    fs_encoding = _fs_enc.upper()
1147
1158
    if (sys.platform == 'win32' or
1148
1159
        fs_encoding not in ('UTF-8', 'US-ASCII', 'ANSI_X3.4-1968')): # ascii
1149
1160
        return _walkdirs_unicode_to_utf8(top, prefix=prefix)