135
132
def is_inside(dir, fname):
136
133
"""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)
135
return os.path.commonprefix([dir, fname]) == dir
172
138
def is_inside_any(dir_list, fname):
173
139
"""True if fname is inside any of given dirs."""
140
# quick scan for perfect match
141
if fname in dir_list:
174
144
for dirname in dir_list:
175
145
if is_inside(dirname, fname):
367
337
tt = time.localtime(t)
368
338
offset = local_time_offset(t)
370
raise BzrError("unsupported timezone format %r" % timezone,
371
['options are "utc", "original", "local"'])
340
raise BzrError("unsupported timezone format %r",
341
['options are "utc", "original", "local"'])
373
343
return (time.strftime("%a %Y-%m-%d %H:%M:%S", tt)
374
344
+ ' %+03d%02d' % (offset / 3600, (offset / 60) % 60))