/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: Parth Malwankar
  • Date: 2010-03-17 05:36:11 UTC
  • mfrom: (5091 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5092.
  • Revision ID: parth.malwankar@gmail.com-20100317053611-xpmn8gili6j191in
merged in trunk. fixed blackbox.test_upgrade to use backup.bzr.~N~ convention.

Show diffs side-by-side

added added

removed removed

Lines of Context:
85
85
# be opened in binary mode, rather than text mode.
86
86
# On other platforms, O_BINARY doesn't exist, because
87
87
# they always open in binary mode, so it is okay to
88
 
# OR with 0 on those platforms
 
88
# OR with 0 on those platforms.
 
89
# O_NOINHERIT and O_TEXT exists only on win32 too.
89
90
O_BINARY = getattr(os, 'O_BINARY', 0)
 
91
O_TEXT = getattr(os, 'O_TEXT', 0)
 
92
O_NOINHERIT = getattr(os, 'O_NOINHERIT', 0)
90
93
 
91
94
 
92
95
def get_unicode_argv():
663
666
def sha_file_by_name(fname):
664
667
    """Calculate the SHA1 of a file by reading the full text"""
665
668
    s = sha()
666
 
    f = os.open(fname, os.O_RDONLY | O_BINARY)
 
669
    f = os.open(fname, os.O_RDONLY | O_BINARY | O_NOINHERIT)
667
670
    try:
668
671
        while True:
669
672
            b = os.read(f, 1<<16)
1346
1349
    normalized_filename = _inaccessible_normalized_filename
1347
1350
 
1348
1351
 
 
1352
def set_signal_handler(signum, handler, restart_syscall=True):
 
1353
    """A wrapper for signal.signal that also calls siginterrupt(signum, False)
 
1354
    on platforms that support that.
 
1355
 
 
1356
    :param restart_syscall: if set, allow syscalls interrupted by a signal to
 
1357
        automatically restart (by calling `signal.siginterrupt(signum,
 
1358
        False)`).  May be ignored if the feature is not available on this
 
1359
        platform or Python version.
 
1360
    """
 
1361
    old_handler = signal.signal(signum, handler)
 
1362
    if restart_syscall:
 
1363
        try:
 
1364
            siginterrupt = signal.siginterrupt
 
1365
        except AttributeError: # siginterrupt doesn't exist on this platform, or for this version of
 
1366
            # Python.
 
1367
            pass
 
1368
        else:
 
1369
            siginterrupt(signum, False)
 
1370
    return old_handler
 
1371
 
 
1372
 
1349
1373
default_terminal_width = 80
1350
1374
"""The default terminal width for ttys.
1351
1375
 
1453
1477
            # the current design -- vila 20091216
1454
1478
            pass
1455
1479
        else:
1456
 
            signal.signal(signal.SIGWINCH, _terminal_size_changed)
 
1480
            set_signal_handler(signal.SIGWINCH, _terminal_size_changed)
1457
1481
        _registered_sigwinch = True
1458
1482
 
1459
1483
 
2117
2141
        else:
2118
2142
            data, _ = self.encode(object, self.errors)
2119
2143
            self.stream.write(data)
 
2144
 
 
2145
if sys.platform == 'win32':
 
2146
    def open_file(filename, mode='r', bufsize=-1):
 
2147
        """This function is used to override the ``open`` builtin.
 
2148
        
 
2149
        But it uses O_NOINHERIT flag so the file handle is not inherited by
 
2150
        child processes.  Deleting or renaming a closed file opened with this
 
2151
        function is not blocking child processes.
 
2152
        """
 
2153
        writing = 'w' in mode
 
2154
        appending = 'a' in mode
 
2155
        updating = '+' in mode
 
2156
        binary = 'b' in mode
 
2157
 
 
2158
        flags = O_NOINHERIT
 
2159
        # see http://msdn.microsoft.com/en-us/library/yeby3zcb%28VS.71%29.aspx
 
2160
        # for flags for each modes.
 
2161
        if binary:
 
2162
            flags |= O_BINARY
 
2163
        else:
 
2164
            flags |= O_TEXT
 
2165
 
 
2166
        if writing:
 
2167
            if updating:
 
2168
                flags |= os.O_RDWR
 
2169
            else:
 
2170
                flags |= os.O_WRONLY
 
2171
            flags |= os.O_CREAT | os.O_TRUNC
 
2172
        elif appending:
 
2173
            if updating:
 
2174
                flags |= os.O_RDWR
 
2175
            else:
 
2176
                flags |= os.O_WRONLY
 
2177
            flags |= os.O_CREAT | os.O_APPEND
 
2178
        else: #reading
 
2179
            if updating:
 
2180
                flags |= os.O_RDWR
 
2181
            else:
 
2182
                flags |= os.O_RDONLY
 
2183
 
 
2184
        return os.fdopen(os.open(filename, flags), mode, bufsize)
 
2185
else:
 
2186
    open_file = open