/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-05-22 16:22:07 UTC
  • Revision ID: tim@ed.am-20160522162207-4b2i6gfejzev6o8g
add symlink in ~/bin to dev version in dev script

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.
66
 
                        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
67
69
 
68
70
 
69
71
        class File:
79
81
                        else:
80
82
                                self.type = '?'
81
83
                        if os.path.islink( self.file ):
82
 
                                self.link_type = type
 
84
                                self.link_type = self.type
83
85
                                self.type = 'l'
84
86
                        else:
85
87
                                self.link_type = False
91
93
                        elif self.type == '_': return 'missing'
92
94
                        else: return 'unknown'
93
95
 
 
96
                def __str__( self ):
 
97
                        type = self.type
 
98
                        if( self.link_type ): type += '/' + self.link_type
 
99
                        return 'File( %s (%s) )' % ( self.file, type )
 
100
 
94
101
 
95
102
        @staticmethod
96
 
        def generate_walk_list( full_dir, rel_file = '' ):
 
103
        def generate_walk_list( rel_file = '', full_dir = None ):
97
104
                """Returns a list of files and directories in full_dir, specified as relative
98
105
                files (relative to full_dir), breadth first.
99
106
                """
100
107
 
 
108
                # default place to walk
 
109
                if full_dir is None: full_dir = the.repo.full_dir
 
110
 
101
111
                # ignore some files
102
 
                if rel_file in { '.bzr', '.bzrignore', '.stdhome', '.stdhomerc' }:
 
112
                if rel_file in [ '.bzr', '.bzrignore', '.stdhome', '.stdhomerc' ]:
103
113
                        return list()
104
114
 
105
115
                full_file = os.path.join( full_dir, rel_file )
113
123
                        ret = [ rel_file ] if rel_file != '' else []
114
124
                        for file in os.listdir( full_file ):
115
125
                                ret.extend( Walker.generate_walk_list(
116
 
                                        full_dir, os.path.join( rel_file, file ) ) )
 
126
                                        os.path.join( rel_file, file ), full_dir ) )
117
127
                        return sorted( ret )
118
128
 
119
129
                # other kinds are invalid