/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: 2016-04-17 21:00:42 UTC
  • Revision ID: tim@ed.am-20160417210042-njcd725axg87i20j
renamed tools dir to dev

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:
37
38
                walk_list that fall under the directory are skipped.
38
39
                """
39
40
 
 
41
                if the.verbose >= 3: print "walking [%s]" % self.__class__.__name__
 
42
 
40
43
                skip = ''
41
 
 
42
44
                for rel_file in self.walk_list:
43
45
 
44
46
                        # if we're skipping, skip entries in subdirectories, or turn off
60
62
                        # way of knowing what to check.  It could be src_type or dst_type
61
63
                        # (if src_dir or dst_dir was used to generate the walk list) or it
62
64
                        # 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.
 
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.
66
68
                        if not recurse: skip = rel_file + os.sep
67
69
 
68
70
 
98
100
 
99
101
 
100
102
        @staticmethod
101
 
        def generate_walk_list( full_dir, rel_file = '' ):
 
103
        def generate_walk_list( rel_file = '', full_dir = None ):
102
104
                """Returns a list of files and directories in full_dir, specified as relative
103
105
                files (relative to full_dir), breadth first.
104
106
                """
105
107
 
 
108
                # default place to walk
 
109
                if full_dir is None: full_dir = the.repo.full_dir
 
110
 
106
111
                # ignore some files
107
 
                if rel_file in { '.bzr', '.bzrignore', '.stdhome', '.stdhomerc' }:
 
112
                if rel_file in [ '.bzr', '.bzrignore', '.stdhome', '.stdhomerc' ]:
108
113
                        return list()
109
114
 
110
115
                full_file = os.path.join( full_dir, rel_file )
118
123
                        ret = [ rel_file ] if rel_file != '' else []
119
124
                        for file in os.listdir( full_file ):
120
125
                                ret.extend( Walker.generate_walk_list(
121
 
                                        full_dir, os.path.join( rel_file, file ) ) )
 
126
                                        os.path.join( rel_file, file ), full_dir ) )
122
127
                        return sorted( ret )
123
128
 
124
129
                # other kinds are invalid