/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: 2014-04-04 22:33:09 UTC
  • Revision ID: tim@ed.am-20140404223309-macifjzkiryg982n
read ~/.stdhomerc; commands set repo before run(); program performs late
initialisation of some variables; updated help

Show diffs side-by-side

added added

removed removed

20
20
 
21
21
 
22
22
import os
23
 
import stdhome.the as the
24
23
 
25
24
 
26
25
class Walker:
64
63
                        # it shouldn't matter.  We adding an os.pathset to the end of the
65
64
                        # filename, so it wuill only match files that are descendents of a
66
65
                        # directory with the name of this file.
67
 
                        if not recurse: skip = rel_file + os.sep
 
66
                        if not recurse: skip = rel_file + os.pathsep
68
67
 
69
68
 
70
69
        class File:
80
79
                        else:
81
80
                                self.type = '?'
82
81
                        if os.path.islink( self.file ):
83
 
                                self.link_type = self.type
 
82
                                self.link_type = type
84
83
                                self.type = 'l'
85
84
                        else:
86
85
                                self.link_type = False
92
91
                        elif self.type == '_': return 'missing'
93
92
                        else: return 'unknown'
94
93
 
95
 
                def __str__( self ):
96
 
                        type = self.type
97
 
                        if( self.link_type ): type += '/' + self.link_type
98
 
                        return 'File( %s (%s) )' % ( self.file, type )
99
 
 
100
94
 
101
95
        @staticmethod
102
 
        def generate_walk_list( rel_file = '', full_dir = None ):
 
96
        def generate_walk_list( full_dir, rel_file = '' ):
103
97
                """Returns a list of files and directories in full_dir, specified as relative
104
98
                files (relative to full_dir), breadth first.
105
99
                """
106
100
 
107
 
                # default place to walk
108
 
                if full_dir is None: full_dir = the.repo.full_dir
109
 
 
110
101
                # ignore some files
111
 
                if rel_file in [ '.bzr', '.bzrignore', '.stdhome', '.stdhomerc' ]:
 
102
                if rel_file in { '.bzr', '.bzrignore', '.stdhome', '.stdhomerc' }:
112
103
                        return list()
113
104
 
114
105
                full_file = os.path.join( full_dir, rel_file )
122
113
                        ret = [ rel_file ] if rel_file != '' else []
123
114
                        for file in os.listdir( full_file ):
124
115
                                ret.extend( Walker.generate_walk_list(
125
 
                                        os.path.join( rel_file, file ), full_dir ) )
 
116
                                        full_dir, os.path.join( rel_file, file ) ) )
126
117
                        return sorted( ret )
127
118
 
128
119
                # other kinds are invalid