/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-03-08 00:47:23 UTC
  • Revision ID: tim@ed.am-20140308004723-hkl3s2hobsblf72o
added diff command; moved all command to commands subdir; made stage-revert
handle ongoing deployment automatically (now that initial revno is known); made
verbose level incremental; detect obstructing conflicts in ConflictWalker;
handle files deleted from repo during copy-out (update)

Show diffs side-by-side

added added

removed removed

20
20
 
21
21
 
22
22
import os
23
 
import stdhome.the
24
23
 
25
24
 
26
25
class Walker:
90
89
 
91
90
 
92
91
        @staticmethod
93
 
        def generate_walk_list( full_dir, rel_dir = '' ):
 
92
        def generate_walk_list( full_dir, rel_file = '' ):
94
93
                """Returns a list of files and directories in full_dir, specified as relative
95
94
                files (relative to full_dir), breadth first.
96
95
                """
97
96
 
98
 
                ret = list()
99
 
 
100
 
                for file in os.listdir( os.path.join( full_dir, rel_dir ) ):
101
 
 
102
 
                        rel_file = os.path.join( rel_dir, file )
103
 
                        if rel_file == '.bzr': continue
104
 
 
105
 
                        full_file = os.path.join( full_dir, rel_file )
106
 
 
107
 
                        if os.path.isfile( full_file ) or os.path.islink( full_file ):
108
 
                                ret.append( rel_file )
109
 
                        elif os.path.isdir( full_file ):
110
 
                                ret.append( rel_file )
111
 
                                ret.extend( generate_file_list( full_dir, rel_file ) )
112
 
                        else:
113
 
                                raise RuntimeError(
114
 
                                        'unknown/exotic file: %s' % full_file )
115
 
 
116
 
                return ret
 
97
                # ignore some files
 
98
                if rel_file in { '.bzr', '.stdhome' }: return list()
 
99
 
 
100
                full_file = os.path.join( full_dir, rel_file )
 
101
 
 
102
                # files and links are returned
 
103
                if os.path.isfile( full_file ) or os.path.islink( full_file ):
 
104
                        return [ rel_file ]
 
105
 
 
106
                # directories are returned and recursed in to
 
107
                elif os.path.isdir( full_file ):
 
108
                        ret = [ rel_file ] if rel_file != '' else []
 
109
                        for file in os.listdir( full_file ):
 
110
                                ret.extend( Walker.generate_walk_list(
 
111
                                        full_dir, os.path.join( rel_file, file ) ) )
 
112
                        return sorted( ret )
 
113
 
 
114
                # other kinds are invalid
 
115
                else:
 
116
                        raise RuntimeError(
 
117
                                'unknown/exotic file: %s' % full_file )
117
118
 
118
119
 
119
120
        @staticmethod