/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-07-05 19:11:53 UTC
  • Revision ID: tim@ed.am-20210705191153-5jcbb6lxv5i15ypx
fix debian dist-package installation

Show diffs side-by-side

added added

removed removed

20
20
 
21
21
 
22
22
import os
 
23
import stdhome.the as the
23
24
 
24
25
 
25
26
class Walker:
31
32
        process() for more information.
32
33
        """
33
34
 
 
35
 
34
36
        def walk( self ):
35
37
                """Iterates over self.walk_list, calling process() for each entry in turn.  For
36
38
                directory entries, where process() returns False, subsequent entries in
37
39
                walk_list that fall under the directory are skipped.
38
40
                """
39
41
 
 
42
                if the.verbose >= 3:
 
43
                        print "walking [%s]" % self.__class__.__name__
 
44
 
40
45
                skip = ''
41
 
 
42
46
                for rel_file in self.walk_list:
43
47
 
44
48
                        # if we're skipping, skip entries in subdirectories, or turn off
60
64
                        # way of knowing what to check.  It could be src_type or dst_type
61
65
                        # (if src_dir or dst_dir was used to generate the walk list) or it
62
66
                        # could be neither (if the walk list came from somewhere else).  But
63
 
                        # it shouldn't matter.  We adding an os.pathset to the end of the
64
 
                        # filename, so it wuill only match files that are descendents of a
65
 
                        # directory with the name of this file.
66
 
                        if not recurse: skip = rel_file + os.pathsep
 
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.
 
70
                        if not recurse: skip = rel_file + os.sep
67
71
 
68
72
 
69
73
        class File:
79
83
                        else:
80
84
                                self.type = '?'
81
85
                        if os.path.islink( self.file ):
82
 
                                self.link_type = type
 
86
                                self.link_type = self.type
83
87
                                self.type = 'l'
84
88
                        else:
85
89
                                self.link_type = False
91
95
                        elif self.type == '_': return 'missing'
92
96
                        else: return 'unknown'
93
97
 
 
98
                def __str__( self ):
 
99
                        type = self.type
 
100
                        if( self.link_type ): type += '/' + self.link_type
 
101
                        return 'File( %s (%s) )' % ( self.file, type )
 
102
 
94
103
 
95
104
        @staticmethod
96
 
        def generate_walk_list( full_dir, rel_file = '' ):
 
105
        def generate_walk_list( full_dir, rel_file = '', recurse = True ):
97
106
                """Returns a list of files and directories in full_dir, specified as relative
98
107
                files (relative to full_dir), breadth first.
 
108
 
99
109
                """
100
110
 
101
111
                # ignore some files
102
 
                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:
103
115
                        return list()
104
116
 
105
117
                full_file = os.path.join( full_dir, rel_file )
111
123
                # directories are returned and recursed in to
112
124
                elif os.path.isdir( full_file ):
113
125
                        ret = [ rel_file ] if rel_file != '' else []
114
 
                        for file in os.listdir( full_file ):
115
 
                                ret.extend( Walker.generate_walk_list(
116
 
                                        full_dir, os.path.join( rel_file, file ) ) )
 
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 ) ) )
117
130
                        return sorted( ret )
118
131
 
119
132
                # other kinds are invalid