/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-02-28 17:51:29 UTC
  • Revision ID: tim@ed.am-20160228175129-ea341cedv8g3s63m
fixed display of bzr output

Show diffs side-by-side

added added

removed removed

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