/stdhome

To get this branch, use:
bzr branch http://bzr.ed.am/stdhome

« back to all changes in this revision

Viewing changes to lib/stdhome/walker/walker.py

  • Committer: Tim Marston
  • Date: 2021-09-01 12:55:42 UTC
  • Revision ID: tim@ed.am-20210901125542-zbuzpswfo7mmm5br
fix broken use of self in @staticmethod

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
        process() for more information.
33
33
        """
34
34
 
 
35
 
35
36
        def walk( self ):
36
37
                """Iterates over self.walk_list, calling process() for each entry in turn.  For
37
38
                directory entries, where process() returns False, subsequent entries in
38
39
                walk_list that fall under the directory are skipped.
39
40
                """
40
41
 
 
42
                if the.verbose >= 3:
 
43
                        print("walking [%s]" % self.__class__.__name__)
 
44
 
41
45
                skip = ''
42
 
 
43
46
                for rel_file in self.walk_list:
44
47
 
45
48
                        # if we're skipping, skip entries in subdirectories, or turn off
61
64
                        # way of knowing what to check.  It could be src_type or dst_type
62
65
                        # (if src_dir or dst_dir was used to generate the walk list) or it
63
66
                        # could be neither (if the walk list came from somewhere else).  But
64
 
                        # it shouldn't matter.  We adding an os.pathset to the end of the
65
 
                        # filename, so it wuill only match files that are descendents of a
66
 
                        # directory with the name of this file.
 
67
                        # it shouldn't matter: we add a path seperateor (os.sep) to the end
 
68
                        # of the filename, so it wuill only match files that are descendents
 
69
                        # of a directory with the name of this file.
67
70
                        if not recurse: skip = rel_file + os.sep
68
71
 
69
72
 
99
102
 
100
103
 
101
104
        @staticmethod
102
 
        def generate_walk_list( rel_file = '', full_dir = None ):
 
105
        def generate_walk_list( full_dir, rel_file = '', recurse = True ):
103
106
                """Returns a list of files and directories in full_dir, specified as relative
104
107
                files (relative to full_dir), breadth first.
 
108
 
105
109
                """
106
110
 
107
 
                # default place to walk
108
 
                if full_dir is None: full_dir = the.repo.full_dir
109
 
 
110
111
                # ignore some files
111
 
                if rel_file in { '.bzr', '.bzrignore', '.stdhome', '.stdhomerc' }:
 
112
                static_ignores = [ '.stdhome', '.stdhomerc' ] + \
 
113
                                                 the.repo.vcs.ignored_files
 
114
                if rel_file in static_ignores:
112
115
                        return list()
113
116
 
114
117
                full_file = os.path.join( full_dir, rel_file )
120
123
                # directories are returned and recursed in to
121
124
                elif os.path.isdir( full_file ):
122
125
                        ret = [ rel_file ] if rel_file != '' else []
123
 
                        for file in os.listdir( full_file ):
124
 
                                ret.extend( Walker.generate_walk_list(
125
 
                                        os.path.join( rel_file, file ), full_dir ) )
 
126
                        if recurse:
 
127
                                for file in os.listdir( full_file ):
 
128
                                        ret.extend( Walker.generate_walk_list(
 
129
                                                full_dir, os.path.join( rel_file, file ) ) )
126
130
                        return sorted( ret )
127
131
 
128
132
                # other kinds are invalid