53
src_file = os.path.join( self.src_dir, rel_file )
54
dst_file = os.path.join( self.dst_dir, rel_file )
56
src_type = Walker.get_file_type( src_file )
57
dst_type = Walker.get_file_type( dst_file )
59
recurse = self.process(
60
rel_file, src_file, src_type, dst_file, dst_type )
54
src = Walker.File( os.path.join( self.src_dir, rel_file ) )
55
dst = Walker.File( os.path.join( self.dst_dir, rel_file ) )
58
recurse = self.process( rel_file, src, dst )
62
60
# Set up skipping, as required. Note that we don't check to see if
63
61
# we're dealing with a directory here. We can't, because we've no
64
62
# way of knowing what to check. It could be src_type or dst_type
65
63
# (if src_dir or dst_dir was used to generate the walk list) or it
66
64
# could be neither (if the walk list came from somewhere else). But
67
# it shouldn't matter. We adding an os.pathset to the end of the
68
# filename, so it wuill only match files that are descendents of a
69
# directory with the name of this file.
70
if not recurse: skip = rel_file + os.pathsep
65
# it shouldn't matter: we add a path seperateor (os.sep) to the end
66
# of the filename, so it wuill only match files that are descendents
67
# of a directory with the name of this file.
68
if not recurse: skip = rel_file + os.sep
73
def __init__( self, full_file ):
75
if not os.path.exists( self.file ):
77
elif os.path.isfile( self.file ):
79
elif os.path.isdir( self.file ):
83
if os.path.islink( self.file ):
84
self.link_type = self.type
87
self.link_type = False
89
def get_type_name( self ):
90
if self.type == 'l': return 'symlink'
91
elif self.type == 'f': return 'file'
92
elif self.type == 'd': return 'directory'
93
elif self.type == '_': return 'missing'
94
else: return 'unknown'
98
if( self.link_type ): type += '/' + self.link_type
99
return 'File( %s (%s) )' % ( self.file, type )
74
def get_file_type( full_file ):
75
"""Returns the type of a given file, at the time of calling. Types are 'd' for
76
directory, 'f' for file, 'l' for symlink, '_' for missing and '?' for
103
def generate_walk_list( rel_file = '', full_dir = None ):
104
"""Returns a list of files and directories in full_dir, specified as relative
105
files (relative to full_dir), breadth first.
80
if not os.path.lexists( full_file ):
82
elif os.path.islink( full_file ):
84
elif os.path.isfile( full_file ):
108
# default place to walk
109
if full_dir is None: full_dir = the.repo.full_dir
112
if rel_file in [ '.bzr', '.bzrignore', '.stdhome', '.stdhomerc' ]:
115
full_file = os.path.join( full_dir, rel_file )
117
# files and links are returned
118
if os.path.isfile( full_file ) or os.path.islink( full_file ):
121
# directories are returned and recursed in to
86
122
elif os.path.isdir( full_file ):
123
ret = [ rel_file ] if rel_file != '' else []
124
for file in os.listdir( full_file ):
125
ret.extend( Walker.generate_walk_list(
126
os.path.join( rel_file, file ), full_dir ) )
129
# other kinds are invalid
93
def generate_walk_list( full_dir, rel_dir = '' ):
94
"""Returns a list of files and directories in full_dir, specified as relative
95
files (relative to full_dir), breadth first.
100
for file in os.listdir( os.path.join( full_dir, rel_dir ) ):
102
rel_file = os.path.join( rel_dir, file )
103
if rel_file == '.bzr': continue
105
full_file = os.path.join( full_dir, rel_file )
107
if os.path.isfile( full_file ) or os.path.islink( full_file ):
108
ret.append( rel_file )
109
elif os.path.isdir( full_file ):
110
ret.append( rel_file )
111
ret.extend( generate_file_list( full_dir, rel_file ) )
114
'unknown/exotic file: %s' % full_file )
120
def name_of_type( type ):
121
if type == 'd': return 'a directory'
122
elif type == 'f': return 'a file'
123
elif type == 'l': return 'a symlink'
124
elif type == '_': return 'missing'
125
else: return 'something exotic'
132
'unknown/exotic file: %s' % full_file )