/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: Martin Pool
  • Date: 2005-07-23 13:52:38 UTC
  • Revision ID: mbp@sourcefrog.net-20050723135238-96b1580de8dff136
doc

Show diffs side-by-side

added added

removed removed

Lines of Context:
139
139
    that . and .. and repeated slashes are eliminated, and the separators
140
140
    are canonical for the platform.
141
141
    
142
 
    The empty string as a dir name is taken as top-of-tree and matches 
143
 
    everything.
144
 
    
145
142
    >>> is_inside('src', 'src/foo.c')
146
143
    True
147
144
    >>> is_inside('src', 'srccontrol')
150
147
    True
151
148
    >>> is_inside('foo.c', 'foo.c')
152
149
    True
153
 
    >>> is_inside('foo.c', '')
154
 
    False
155
 
    >>> is_inside('', 'foo.c')
156
 
    True
157
150
    """
158
151
    # XXX: Most callers of this can actually do something smarter by 
159
152
    # looking at the inventory
160
 
    if dir == fname:
161
 
        return True
162
 
    
163
 
    if dir == '':
164
 
        return True
165
 
    
166
 
    if dir[-1] != os.sep:
167
 
        dir += os.sep
168
 
    
169
 
    return fname.startswith(dir)
170
 
 
 
153
    
 
154
    dir = dir.split(os.sep)
 
155
    pl = len(dir)
 
156
    fname = fname.split(os.sep)
 
157
   
 
158
    return (len(fname) >= pl) and (dir == fname[:pl])
 
159
    
171
160
 
172
161
def is_inside_any(dir_list, fname):
173
162
    """True if fname is inside any of given dirs."""
 
163
    # quick scan for perfect match
 
164
    if fname in dir_list:
 
165
        return True
 
166
    
174
167
    for dirname in dir_list:
175
168
        if is_inside(dirname, fname):
176
169
            return True
367
360
        tt = time.localtime(t)
368
361
        offset = local_time_offset(t)
369
362
    else:
370
 
        raise BzrError("unsupported timezone format %r" % timezone,
371
 
                       ['options are "utc", "original", "local"'])
 
363
        raise BzrError("unsupported timezone format %r",
 
364
                ['options are "utc", "original", "local"'])
372
365
 
373
366
    return (time.strftime("%a %Y-%m-%d %H:%M:%S", tt)
374
367
            + ' %+03d%02d' % (offset / 3600, (offset / 60) % 60))