40
40
_QUOTE_RE = re.compile(r'([^a-zA-Z0-9.,:/_~-])')
42
_SLASH_RE = re.compile(r'[\\/]+')
45
"""Return a quoted filename filename
47
This previously used backslash quoting, but that works poorly on
49
# TODO: I'm not really sure this is the best format either.x
50
if _QUOTE_RE.search(f):
42
"""Return shell-quoted filename"""
43
## We could be a bit more terse by using double-quotes etc
44
f = _QUOTE_RE.sub(r'\\\1', f)
81
"""Copy a file to a backup.
83
Backups are named in GNU-style, with a ~ suffix.
85
If the file is already a backup, it's not copied.
98
outf = file(bfn, 'wb')
104
def rename(path_from, path_to):
105
"""Basically the same as os.rename() just special for win32"""
106
if sys.platform == 'win32':
110
if e.errno != e.ENOENT:
112
os.rename(path_from, path_to)
119
75
"""True if f is an accessible directory."""
135
91
def is_inside(dir, fname):
136
92
"""True if fname is inside dir.
138
The parameters should typically be passed to os.path.normpath first, so
139
that . and .. and repeated slashes are eliminated, and the separators
140
are canonical for the platform.
142
The empty string as a dir name is taken as top-of-tree and matches
145
>>> is_inside('src', 'src/foo.c')
147
>>> is_inside('src', 'srccontrol')
149
>>> is_inside('src', 'src/a/a/a/foo.c')
151
>>> is_inside('foo.c', 'foo.c')
153
>>> is_inside('foo.c', '')
155
>>> is_inside('', 'foo.c')
158
# XXX: Most callers of this can actually do something smarter by
159
# looking at the inventory
166
if dir[-1] != os.sep:
169
return fname.startswith(dir)
94
return os.path.commonprefix([dir, fname]) == dir
172
97
def is_inside_any(dir_list, fname):
173
98
"""True if fname is inside any of given dirs."""
99
# quick scan for perfect match
100
if fname in dir_list:
174
103
for dirname in dir_list:
175
104
if is_inside(dirname, fname):
367
296
tt = time.localtime(t)
368
297
offset = local_time_offset(t)
370
raise BzrError("unsupported timezone format %r" % timezone,
371
['options are "utc", "original", "local"'])
299
raise BzrError("unsupported timezone format %r",
300
['options are "utc", "original", "local"'])
373
302
return (time.strftime("%a %Y-%m-%d %H:%M:%S", tt)
374
303
+ ' %+03d%02d' % (offset / 3600, (offset / 60) % 60))