/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
1 by mbp at sourcefrog
import from baz patch-364
1
# Bazaar-NG -- distributed version control
1185.1.41 by Robert Collins
massive patch from Alexander Belchenko - many PEP8 fixes, removes unused function uuid
2
#
1 by mbp at sourcefrog
import from baz patch-364
3
# Copyright (C) 2005 by Canonical Ltd
1185.1.41 by Robert Collins
massive patch from Alexander Belchenko - many PEP8 fixes, removes unused function uuid
4
#
1 by mbp at sourcefrog
import from baz patch-364
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
1185.1.41 by Robert Collins
massive patch from Alexander Belchenko - many PEP8 fixes, removes unused function uuid
9
#
1 by mbp at sourcefrog
import from baz patch-364
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
# GNU General Public License for more details.
1185.1.41 by Robert Collins
massive patch from Alexander Belchenko - many PEP8 fixes, removes unused function uuid
14
#
1 by mbp at sourcefrog
import from baz patch-364
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
1185.3.28 by John Arbash Meinel
Adding knowledge about fifo/block/etc, they will be unknown/ignored.
19
from stat import (S_ISREG, S_ISDIR, S_ISLNK, ST_MODE, ST_SIZE,
1185.1.41 by Robert Collins
massive patch from Alexander Belchenko - many PEP8 fixes, removes unused function uuid
20
                  S_ISCHR, S_ISBLK, S_ISFIFO, S_ISSOCK)
21
import errno
22
import os
23
import re
24
import sha
25
import sys
26
import time
27
import types
1 by mbp at sourcefrog
import from baz patch-364
28
1185.1.41 by Robert Collins
massive patch from Alexander Belchenko - many PEP8 fixes, removes unused function uuid
29
import bzrlib
694 by Martin Pool
- weed out all remaining calls to bailout() and remove the function
30
from bzrlib.errors import BzrError
31
from bzrlib.trace import mutter
1185.1.41 by Robert Collins
massive patch from Alexander Belchenko - many PEP8 fixes, removes unused function uuid
32
1 by mbp at sourcefrog
import from baz patch-364
33
34
def make_readonly(filename):
35
    """Make a filename read-only."""
36
    mod = os.stat(filename).st_mode
37
    mod = mod & 0777555
38
    os.chmod(filename, mod)
39
40
41
def make_writable(filename):
42
    mod = os.stat(filename).st_mode
43
    mod = mod | 0200
44
    os.chmod(filename, mod)
45
46
1077 by Martin Pool
- avoid compiling REs at module load time
47
_QUOTE_RE = None
969 by Martin Pool
- Add less-sucky is_within_any
48
49
1 by mbp at sourcefrog
import from baz patch-364
50
def quotefn(f):
779 by Martin Pool
- better quotefn for windows: use doublequotes for strings with
51
    """Return a quoted filename filename
52
53
    This previously used backslash quoting, but that works poorly on
54
    Windows."""
55
    # TODO: I'm not really sure this is the best format either.x
1077 by Martin Pool
- avoid compiling REs at module load time
56
    global _QUOTE_RE
57
    if _QUOTE_RE == None:
1185.1.41 by Robert Collins
massive patch from Alexander Belchenko - many PEP8 fixes, removes unused function uuid
58
        _QUOTE_RE = re.compile(r'([^a-zA-Z0-9.,:/\\_~-])')
1077 by Martin Pool
- avoid compiling REs at module load time
59
        
779 by Martin Pool
- better quotefn for windows: use doublequotes for strings with
60
    if _QUOTE_RE.search(f):
61
        return '"' + f + '"'
62
    else:
63
        return f
1 by mbp at sourcefrog
import from baz patch-364
64
65
66
def file_kind(f):
67
    mode = os.lstat(f)[ST_MODE]
68
    if S_ISREG(mode):
69
        return 'file'
70
    elif S_ISDIR(mode):
71
        return 'directory'
20 by mbp at sourcefrog
don't abort on trees that happen to contain symlinks
72
    elif S_ISLNK(mode):
73
        return 'symlink'
1185.3.28 by John Arbash Meinel
Adding knowledge about fifo/block/etc, they will be unknown/ignored.
74
    elif S_ISCHR(mode):
75
        return 'chardev'
76
    elif S_ISBLK(mode):
77
        return 'block'
78
    elif S_ISFIFO(mode):
79
        return 'fifo'
80
    elif S_ISSOCK(mode):
81
        return 'socket'
1 by mbp at sourcefrog
import from baz patch-364
82
    else:
1185.3.28 by John Arbash Meinel
Adding knowledge about fifo/block/etc, they will be unknown/ignored.
83
        return 'unknown'
488 by Martin Pool
- new helper function kind_marker()
84
85
86
def kind_marker(kind):
87
    if kind == 'file':
88
        return ''
89
    elif kind == 'directory':
90
        return '/'
91
    elif kind == 'symlink':
92
        return '@'
93
    else:
94
        raise BzrError('invalid file kind %r' % kind)
1 by mbp at sourcefrog
import from baz patch-364
95
1092.2.6 by Robert Collins
symlink support updated to work
96
def lexists(f):
97
    try:
98
        if hasattr(os, 'lstat'):
99
            os.lstat(f)
100
        else:
101
            os.stat(f)
102
        return True
103
    except OSError,e:
104
        if e.errno == errno.ENOENT:
105
            return False;
106
        else:
107
            raise BzrError("lstat/stat of (%r): %r" % (f, e))
1 by mbp at sourcefrog
import from baz patch-364
108
1092.2.6 by Robert Collins
symlink support updated to work
109
def normalizepath(f):
110
    if hasattr(os.path, 'realpath'):
111
        F = os.path.realpath
112
    else:
113
        F = os.path.abspath
114
    [p,e] = os.path.split(f)
115
    if e == "" or e == "." or e == "..":
116
        return F(f)
117
    else:
118
        return os.path.join(F(p), e)
119
    
1 by mbp at sourcefrog
import from baz patch-364
120
779 by Martin Pool
- better quotefn for windows: use doublequotes for strings with
121
def backup_file(fn):
122
    """Copy a file to a backup.
123
124
    Backups are named in GNU-style, with a ~ suffix.
125
126
    If the file is already a backup, it's not copied.
127
    """
128
    if fn[-1] == '~':
129
        return
130
    bfn = fn + '~'
131
132
    inf = file(fn, 'rb')
133
    try:
134
        content = inf.read()
135
    finally:
136
        inf.close()
137
    
138
    outf = file(bfn, 'wb')
139
    try:
140
        outf.write(content)
141
    finally:
142
        outf.close()
143
1185.1.40 by Robert Collins
Merge what applied of Alexander Belchenko's win32 patch.
144
if os.name == 'nt':
145
    import shutil
146
    rename = shutil.move
147
else:
148
    rename = os.rename
779 by Martin Pool
- better quotefn for windows: use doublequotes for strings with
149
150
1 by mbp at sourcefrog
import from baz patch-364
151
def isdir(f):
152
    """True if f is an accessible directory."""
153
    try:
154
        return S_ISDIR(os.lstat(f)[ST_MODE])
155
    except OSError:
156
        return False
157
158
159
def isfile(f):
160
    """True if f is a regular file."""
161
    try:
162
        return S_ISREG(os.lstat(f)[ST_MODE])
163
    except OSError:
164
        return False
165
1092.2.6 by Robert Collins
symlink support updated to work
166
def islink(f):
167
    """True if f is a symlink."""
168
    try:
169
        return S_ISLNK(os.lstat(f)[ST_MODE])
170
    except OSError:
171
        return False
1 by mbp at sourcefrog
import from baz patch-364
172
485 by Martin Pool
- move commit code into its own module
173
def is_inside(dir, fname):
174
    """True if fname is inside dir.
969 by Martin Pool
- Add less-sucky is_within_any
175
    
176
    The parameters should typically be passed to os.path.normpath first, so
177
    that . and .. and repeated slashes are eliminated, and the separators
178
    are canonical for the platform.
179
    
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
180
    The empty string as a dir name is taken as top-of-tree and matches 
181
    everything.
182
    
1185.1.40 by Robert Collins
Merge what applied of Alexander Belchenko's win32 patch.
183
    >>> is_inside('src', os.path.join('src', 'foo.c'))
969 by Martin Pool
- Add less-sucky is_within_any
184
    True
185
    >>> is_inside('src', 'srccontrol')
186
    False
1185.1.40 by Robert Collins
Merge what applied of Alexander Belchenko's win32 patch.
187
    >>> is_inside('src', os.path.join('src', 'a', 'a', 'a', 'foo.c'))
969 by Martin Pool
- Add less-sucky is_within_any
188
    True
189
    >>> is_inside('foo.c', 'foo.c')
190
    True
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
191
    >>> is_inside('foo.c', '')
192
    False
193
    >>> is_inside('', 'foo.c')
194
    True
485 by Martin Pool
- move commit code into its own module
195
    """
969 by Martin Pool
- Add less-sucky is_within_any
196
    # XXX: Most callers of this can actually do something smarter by 
197
    # looking at the inventory
972 by Martin Pool
- less dodgy is_inside function
198
    if dir == fname:
199
        return True
200
    
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
201
    if dir == '':
202
        return True
1185.1.41 by Robert Collins
massive patch from Alexander Belchenko - many PEP8 fixes, removes unused function uuid
203
972 by Martin Pool
- less dodgy is_inside function
204
    if dir[-1] != os.sep:
205
        dir += os.sep
1185.1.41 by Robert Collins
massive patch from Alexander Belchenko - many PEP8 fixes, removes unused function uuid
206
972 by Martin Pool
- less dodgy is_inside function
207
    return fname.startswith(dir)
208
485 by Martin Pool
- move commit code into its own module
209
210
def is_inside_any(dir_list, fname):
211
    """True if fname is inside any of given dirs."""
212
    for dirname in dir_list:
213
        if is_inside(dirname, fname):
214
            return True
215
    else:
216
        return False
217
218
1 by mbp at sourcefrog
import from baz patch-364
219
def pumpfile(fromfile, tofile):
220
    """Copy contents of one file to another."""
221
    tofile.write(fromfile.read())
222
223
224
def sha_file(f):
225
    if hasattr(f, 'tell'):
226
        assert f.tell() == 0
227
    s = sha.new()
320 by Martin Pool
- Compute SHA-1 of files in chunks
228
    BUFSIZE = 128<<10
229
    while True:
230
        b = f.read(BUFSIZE)
231
        if not b:
232
            break
233
        s.update(b)
1 by mbp at sourcefrog
import from baz patch-364
234
    return s.hexdigest()
235
236
237
def sha_string(f):
238
    s = sha.new()
239
    s.update(f)
240
    return s.hexdigest()
241
242
124 by mbp at sourcefrog
- check file text for past revisions is correct
243
def fingerprint_file(f):
244
    s = sha.new()
126 by mbp at sourcefrog
Use just one big read to fingerprint files
245
    b = f.read()
246
    s.update(b)
247
    size = len(b)
124 by mbp at sourcefrog
- check file text for past revisions is correct
248
    return {'size': size,
249
            'sha1': s.hexdigest()}
250
251
258 by Martin Pool
- Take email from ~/.bzr.conf/email
252
def config_dir():
253
    """Return per-user configuration directory.
254
255
    By default this is ~/.bzr.conf/
256
    
257
    TODO: Global option --config-dir to override this.
258
    """
1185.1.41 by Robert Collins
massive patch from Alexander Belchenko - many PEP8 fixes, removes unused function uuid
259
    return os.path.join(os.path.expanduser("~"), ".bzr.conf")
258 by Martin Pool
- Take email from ~/.bzr.conf/email
260
261
252 by Martin Pool
- Don't use host fqdn for default user name, because DNS tends
262
def _auto_user_id():
246 by mbp at sourcefrog
- unicode decoding in getting email and userid strings
263
    """Calculate automatic user identification.
264
265
    Returns (realname, email).
266
252 by Martin Pool
- Don't use host fqdn for default user name, because DNS tends
267
    Only used when none is set in the environment or the id file.
246 by mbp at sourcefrog
- unicode decoding in getting email and userid strings
268
252 by Martin Pool
- Don't use host fqdn for default user name, because DNS tends
269
    This previously used the FQDN as the default domain, but that can
270
    be very slow on machines where DNS is broken.  So now we simply
271
    use the hostname.
1 by mbp at sourcefrog
import from baz patch-364
272
    """
251 by mbp at sourcefrog
- factor out locale.getpreferredencoding()
273
    import socket
246 by mbp at sourcefrog
- unicode decoding in getting email and userid strings
274
275
    # XXX: Any good way to get real user name on win32?
276
1 by mbp at sourcefrog
import from baz patch-364
277
    try:
278
        import pwd
279
        uid = os.getuid()
280
        w = pwd.getpwuid(uid)
251 by mbp at sourcefrog
- factor out locale.getpreferredencoding()
281
        gecos = w.pw_gecos.decode(bzrlib.user_encoding)
282
        username = w.pw_name.decode(bzrlib.user_encoding)
25 by Martin Pool
cope when gecos field doesn't have a comma
283
        comma = gecos.find(',')
284
        if comma == -1:
285
            realname = gecos
286
        else:
287
            realname = gecos[:comma]
256 by Martin Pool
- More handling of auto-username case
288
        if not realname:
289
            realname = username
246 by mbp at sourcefrog
- unicode decoding in getting email and userid strings
290
1 by mbp at sourcefrog
import from baz patch-364
291
    except ImportError:
246 by mbp at sourcefrog
- unicode decoding in getting email and userid strings
292
        import getpass
256 by Martin Pool
- More handling of auto-username case
293
        realname = username = getpass.getuser().decode(bzrlib.user_encoding)
252 by Martin Pool
- Don't use host fqdn for default user name, because DNS tends
294
256 by Martin Pool
- More handling of auto-username case
295
    return realname, (username + '@' + socket.gethostname())
252 by Martin Pool
- Don't use host fqdn for default user name, because DNS tends
296
297
1074 by Martin Pool
- check for email address in BRANCH_ROOT/.bzr/email, so you can
298
def _get_user_id(branch):
258 by Martin Pool
- Take email from ~/.bzr.conf/email
299
    """Return the full user id from a file or environment variable.
300
1074 by Martin Pool
- check for email address in BRANCH_ROOT/.bzr/email, so you can
301
    e.g. "John Hacker <jhacker@foo.org>"
302
303
    branch
304
        A branch to use for a per-branch configuration, or None.
305
306
    The following are searched in order:
307
308
    1. $BZREMAIL
309
    2. .bzr/email for this branch.
310
    3. ~/.bzr.conf/email
311
    4. $EMAIL
312
    """
252 by Martin Pool
- Don't use host fqdn for default user name, because DNS tends
313
    v = os.environ.get('BZREMAIL')
314
    if v:
315
        return v.decode(bzrlib.user_encoding)
1074 by Martin Pool
- check for email address in BRANCH_ROOT/.bzr/email, so you can
316
317
    if branch:
318
        try:
319
            return (branch.controlfile("email", "r") 
320
                    .read()
321
                    .decode(bzrlib.user_encoding)
322
                    .rstrip("\r\n"))
323
        except IOError, e:
324
            if e.errno != errno.ENOENT:
325
                raise
326
        except BzrError, e:
327
            pass
252 by Martin Pool
- Don't use host fqdn for default user name, because DNS tends
328
    
329
    try:
258 by Martin Pool
- Take email from ~/.bzr.conf/email
330
        return (open(os.path.join(config_dir(), "email"))
252 by Martin Pool
- Don't use host fqdn for default user name, because DNS tends
331
                .read()
332
                .decode(bzrlib.user_encoding)
333
                .rstrip("\r\n"))
256 by Martin Pool
- More handling of auto-username case
334
    except IOError, e:
335
        if e.errno != errno.ENOENT:
252 by Martin Pool
- Don't use host fqdn for default user name, because DNS tends
336
            raise e
337
338
    v = os.environ.get('EMAIL')
339
    if v:
340
        return v.decode(bzrlib.user_encoding)
341
    else:    
342
        return None
246 by mbp at sourcefrog
- unicode decoding in getting email and userid strings
343
344
1074 by Martin Pool
- check for email address in BRANCH_ROOT/.bzr/email, so you can
345
def username(branch):
246 by mbp at sourcefrog
- unicode decoding in getting email and userid strings
346
    """Return email-style username.
347
348
    Something similar to 'Martin Pool <mbp@sourcefrog.net>'
349
254 by Martin Pool
- Doc cleanups from Magnus Therning
350
    TODO: Check it's reasonably well-formed.
246 by mbp at sourcefrog
- unicode decoding in getting email and userid strings
351
    """
1074 by Martin Pool
- check for email address in BRANCH_ROOT/.bzr/email, so you can
352
    v = _get_user_id(branch)
252 by Martin Pool
- Don't use host fqdn for default user name, because DNS tends
353
    if v:
354
        return v
355
    
356
    name, email = _auto_user_id()
246 by mbp at sourcefrog
- unicode decoding in getting email and userid strings
357
    if name:
358
        return '%s <%s>' % (name, email)
359
    else:
360
        return email
1 by mbp at sourcefrog
import from baz patch-364
361
362
1074 by Martin Pool
- check for email address in BRANCH_ROOT/.bzr/email, so you can
363
def user_email(branch):
1 by mbp at sourcefrog
import from baz patch-364
364
    """Return just the email component of a username."""
1074 by Martin Pool
- check for email address in BRANCH_ROOT/.bzr/email, so you can
365
    e = _get_user_id(branch)
1 by mbp at sourcefrog
import from baz patch-364
366
    if e:
1077 by Martin Pool
- avoid compiling REs at module load time
367
        m = re.search(r'[\w+.-]+@[\w+.-]+', e)
1 by mbp at sourcefrog
import from baz patch-364
368
        if not m:
1185.1.41 by Robert Collins
massive patch from Alexander Belchenko - many PEP8 fixes, removes unused function uuid
369
            raise BzrError("%r doesn't seem to contain "
370
                           "a reasonable email address" % e)
1 by mbp at sourcefrog
import from baz patch-364
371
        return m.group(0)
372
252 by Martin Pool
- Don't use host fqdn for default user name, because DNS tends
373
    return _auto_user_id()[1]
1 by mbp at sourcefrog
import from baz patch-364
374
375
376
def compare_files(a, b):
377
    """Returns true if equal in contents"""
74 by mbp at sourcefrog
compare_files: read in one page at a time rather than
378
    BUFSIZE = 4096
379
    while True:
380
        ai = a.read(BUFSIZE)
381
        bi = b.read(BUFSIZE)
382
        if ai != bi:
383
            return False
384
        if ai == '':
385
            return True
1 by mbp at sourcefrog
import from baz patch-364
386
387
49 by mbp at sourcefrog
fix local-time-offset calculation
388
def local_time_offset(t=None):
389
    """Return offset of local zone from GMT, either at present or at time t."""
73 by mbp at sourcefrog
fix time.localtime call for python 2.3
390
    # python2.3 localtime() can't take None
183 by mbp at sourcefrog
pychecker fixups
391
    if t == None:
73 by mbp at sourcefrog
fix time.localtime call for python 2.3
392
        t = time.time()
393
        
49 by mbp at sourcefrog
fix local-time-offset calculation
394
    if time.localtime(t).tm_isdst and time.daylight:
8 by mbp at sourcefrog
store committer's timezone in revision and show
395
        return -time.altzone
396
    else:
397
        return -time.timezone
398
399
    
400
def format_date(t, offset=0, timezone='original'):
1 by mbp at sourcefrog
import from baz patch-364
401
    ## TODO: Perhaps a global option to use either universal or local time?
402
    ## Or perhaps just let people set $TZ?
403
    assert isinstance(t, float)
404
    
8 by mbp at sourcefrog
store committer's timezone in revision and show
405
    if timezone == 'utc':
1 by mbp at sourcefrog
import from baz patch-364
406
        tt = time.gmtime(t)
407
        offset = 0
8 by mbp at sourcefrog
store committer's timezone in revision and show
408
    elif timezone == 'original':
23 by mbp at sourcefrog
format_date: handle revisions with no timezone offset
409
        if offset == None:
410
            offset = 0
16 by mbp at sourcefrog
fix inverted calculation for original timezone -> utc
411
        tt = time.gmtime(t + offset)
12 by mbp at sourcefrog
new --timezone option for bzr log
412
    elif timezone == 'local':
1 by mbp at sourcefrog
import from baz patch-364
413
        tt = time.localtime(t)
49 by mbp at sourcefrog
fix local-time-offset calculation
414
        offset = local_time_offset(t)
12 by mbp at sourcefrog
new --timezone option for bzr log
415
    else:
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
416
        raise BzrError("unsupported timezone format %r" % timezone,
417
                       ['options are "utc", "original", "local"'])
8 by mbp at sourcefrog
store committer's timezone in revision and show
418
1 by mbp at sourcefrog
import from baz patch-364
419
    return (time.strftime("%a %Y-%m-%d %H:%M:%S", tt)
8 by mbp at sourcefrog
store committer's timezone in revision and show
420
            + ' %+03d%02d' % (offset / 3600, (offset / 60) % 60))
1 by mbp at sourcefrog
import from baz patch-364
421
422
423
def compact_date(when):
424
    return time.strftime('%Y%m%d%H%M%S', time.gmtime(when))
425
    
426
427
428
def filesize(f):
429
    """Return size of given open file."""
430
    return os.fstat(f.fileno())[ST_SIZE]
431
1185.1.7 by Robert Collins
Nathaniel McCallums patch for urandom friendliness on aix.
432
# Define rand_bytes based on platform.
433
try:
434
    # Python 2.4 and later have os.urandom,
435
    # but it doesn't work on some arches
436
    os.urandom(1)
1 by mbp at sourcefrog
import from baz patch-364
437
    rand_bytes = os.urandom
1185.1.7 by Robert Collins
Nathaniel McCallums patch for urandom friendliness on aix.
438
except (NotImplementedError, AttributeError):
439
    # If python doesn't have os.urandom, or it doesn't work,
440
    # then try to first pull random data from /dev/urandom
441
    if os.path.exists("/dev/urandom"):
442
        rand_bytes = file('/dev/urandom', 'rb').read
443
    # Otherwise, use this hack as a last resort
444
    else:
445
        # not well seeded, but better than nothing
446
        def rand_bytes(n):
447
            import random
448
            s = ''
449
            while n:
450
                s += chr(random.randint(0, 255))
451
                n -= 1
452
            return s
1 by mbp at sourcefrog
import from baz patch-364
453
454
## TODO: We could later have path objects that remember their list
455
## decomposition (might be too tricksy though.)
456
457
def splitpath(p):
458
    """Turn string into list of parts.
459
460
    >>> splitpath('a')
461
    ['a']
462
    >>> splitpath('a/b')
463
    ['a', 'b']
464
    >>> splitpath('a/./b')
465
    ['a', 'b']
466
    >>> splitpath('a/.b')
467
    ['a', '.b']
468
    >>> splitpath('a/../b')
184 by mbp at sourcefrog
pychecker fixups
469
    Traceback (most recent call last):
1 by mbp at sourcefrog
import from baz patch-364
470
    ...
694 by Martin Pool
- weed out all remaining calls to bailout() and remove the function
471
    BzrError: sorry, '..' not allowed in path
1 by mbp at sourcefrog
import from baz patch-364
472
    """
473
    assert isinstance(p, types.StringTypes)
271 by Martin Pool
- Windows path fixes
474
475
    # split on either delimiter because people might use either on
476
    # Windows
477
    ps = re.split(r'[\\/]', p)
478
479
    rps = []
1 by mbp at sourcefrog
import from baz patch-364
480
    for f in ps:
481
        if f == '..':
694 by Martin Pool
- weed out all remaining calls to bailout() and remove the function
482
            raise BzrError("sorry, %r not allowed in path" % f)
271 by Martin Pool
- Windows path fixes
483
        elif (f == '.') or (f == ''):
484
            pass
485
        else:
486
            rps.append(f)
487
    return rps
1 by mbp at sourcefrog
import from baz patch-364
488
489
def joinpath(p):
490
    assert isinstance(p, list)
491
    for f in p:
183 by mbp at sourcefrog
pychecker fixups
492
        if (f == '..') or (f == None) or (f == ''):
694 by Martin Pool
- weed out all remaining calls to bailout() and remove the function
493
            raise BzrError("sorry, %r not allowed in path" % f)
271 by Martin Pool
- Windows path fixes
494
    return os.path.join(*p)
1 by mbp at sourcefrog
import from baz patch-364
495
496
497
def appendpath(p1, p2):
498
    if p1 == '':
499
        return p2
500
    else:
271 by Martin Pool
- Windows path fixes
501
        return os.path.join(p1, p2)
1 by mbp at sourcefrog
import from baz patch-364
502
    
503
504
def extern_command(cmd, ignore_errors = False):
505
    mutter('external command: %s' % `cmd`)
506
    if os.system(cmd):
507
        if not ignore_errors:
694 by Martin Pool
- weed out all remaining calls to bailout() and remove the function
508
            raise BzrError('command failed')
1 by mbp at sourcefrog
import from baz patch-364
509
763 by Martin Pool
- Patch from Torsten Marek to take commit messages through an
510
511
def _read_config_value(name):
512
    """Read a config value from the file ~/.bzr.conf/<name>
513
    Return None if the file does not exist"""
514
    try:
515
        f = file(os.path.join(config_dir(), name), "r")
516
        return f.read().decode(bzrlib.user_encoding).rstrip("\r\n")
517
    except IOError, e:
518
        if e.errno == errno.ENOENT:
519
            return None
520
        raise