/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

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
from shutil import (
40
40
    rmtree,
41
41
    )
 
42
import signal
42
43
import subprocess
43
44
import tempfile
44
45
from tempfile import (
201
202
    :param old: The old path, to rename from
202
203
    :param new: The new path, to rename to
203
204
    :param rename_func: The potentially non-atomic rename function
204
 
    :param unlink_func: A way to delete the target file if the full rename succeeds
 
205
    :param unlink_func: A way to delete the target file if the full rename
 
206
        succeeds
205
207
    """
206
 
 
207
208
    # sftp rename doesn't allow overwriting, so play tricks:
208
209
    base = os.path.basename(new)
209
210
    dirname = os.path.dirname(new)
210
 
    tmp_name = u'tmp.%s.%.9f.%d.%s' % (base, time.time(), os.getpid(), rand_chars(10))
 
211
    # callers use different encodings for the paths so the following MUST
 
212
    # respect that. We rely on python upcasting to unicode if new is unicode
 
213
    # and keeping a str if not.
 
214
    tmp_name = 'tmp.%s.%.9f.%d.%s' % (base, time.time(),
 
215
                                      os.getpid(), rand_chars(10))
211
216
    tmp_name = pathjoin(dirname, tmp_name)
212
217
 
213
218
    # Rename the file out of the way, but keep track if it didn't exist
1427
1432
    _terminal_size = _ioctl_terminal_size
1428
1433
 
1429
1434
 
 
1435
def _terminal_size_changed(signum, frame):
 
1436
    """Set COLUMNS upon receiving a SIGnal for WINdow size CHange."""
 
1437
    width, height = _terminal_size(None, None)
 
1438
    if width is not None:
 
1439
        os.environ['COLUMNS'] = str(width)
 
1440
 
 
1441
if sys.platform == 'win32':
 
1442
    # Martin (gz) mentioned WINDOW_BUFFER_SIZE_RECORD from ReadConsoleInput but
 
1443
    # I've no idea how to plug that in the current design -- vila 20091216
 
1444
    pass
 
1445
else:
 
1446
    signal.signal(signal.SIGWINCH, _terminal_size_changed)
 
1447
 
 
1448
 
1430
1449
def supports_executable():
1431
1450
    return sys.platform != "win32"
1432
1451
 
2072
2091
    if use_cache:
2073
2092
        _cached_concurrency = concurrency
2074
2093
    return concurrency
 
2094
 
 
2095
 
 
2096
class UnicodeOrBytesToBytesWriter(codecs.StreamWriter):
 
2097
    """A stream writer that doesn't decode str arguments."""
 
2098
 
 
2099
    def __init__(self, encode, stream, errors='strict'):
 
2100
        codecs.StreamWriter.__init__(self, stream, errors)
 
2101
        self.encode = encode
 
2102
 
 
2103
    def write(self, object):
 
2104
        if type(object) is str:
 
2105
            self.stream.write(object)
 
2106
        else:
 
2107
            data, _ = self.encode(object, self.errors)
 
2108
            self.stream.write(data)