/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/copy_base.py

  • Committer: Tim Marston
  • Date: 2014-04-18 14:45:39 UTC
  • Revision ID: tim@ed.am-20140418144539-uhprdfn5oyc8wc82
implemented ignore lists in copyer and made symlink substitution work only one
way (so that symlink substitutions can only occur in ~/ and not in the repo)

Show diffs side-by-side

added added

removed removed

31
31
        information.
32
32
        """
33
33
 
34
 
        accept_list = None
 
34
 
 
35
        def __init__( self ):
 
36
                self.check_src_symlinks = False
 
37
                self.check_dst_symlinks = False
 
38
                self.check_dst_ignores = False
35
39
 
36
40
 
37
41
        def process( self, rel_file, src, dst ):
38
42
 
 
43
                # ignore?
 
44
                if self.check_dst_ignores and the.config.ignores.matches( rel_file ):
 
45
                        if the.verbose >= 2:
 
46
                                self.print_op( rel_file, '%s#%s' % ( src.type, dst.type ) )
 
47
                        return True
 
48
 
39
49
                # src entity is directory
40
50
                if src.type == 'd':
41
51
 
55
65
 
56
66
                        # if dst entity is a symlink to a directory, and this is an
57
67
                        # acceptable substitute, just recurse
58
 
                        elif dst.link_type == 'd' and \
59
 
                                        self.accept_list and self.accept_list.match( rel_file ):
 
68
                        elif self.check_dst_symlinks and dst.link_type == 'd' and \
 
69
                                        the.config.symlinks.matches( rel_file ):
60
70
                                if the.verbose >= 2: self.print_op( rel_file, 'd@d' )
61
71
                                return True
62
72
 
130
140
                                os.unlink( dst.file )
131
141
                                os.symlink( os.readlink( src.file ), dst.file )
132
142
 
133
 
                        # if dst entity is a directory, and src entity is a symlink to a
134
 
                        # directory, and this is an acceptable substitute, just recurse
135
 
                        elif dst.type == 'd' and src.link_type == 'd' and \
136
 
                                        self.accept_list and self.accept_list.match( rel_file ):
137
 
                                if the.verbose >= 2: self.print_op( rel_file, 'd@d' )
138
 
                                return True
139
 
 
140
 
                        # if dst entity is a directory, replace it with symlink
 
143
                        # if dst entity is a directory...
141
144
                        elif dst.type == 'd':
 
145
 
 
146
                                # if src entity is a symlink to a directory, and this is an
 
147
                                # acceptable substitute, just recurse
 
148
                                if self.check_src_symlinks and src.link_type == 'd' and \
 
149
                                                the.config.symlinks.matches( rel_file ):
 
150
                                        if the.verbose >= 2: self.print_op( rel_file, 'd@d' )
 
151
                                        return True
 
152
 
 
153
                                # else replace it with a symlink
142
154
                                if the.verbose >= 2: self.print_op( rel_file, 'l>d' )
143
155
                                shutil.rmtree( dst.file )
144
156
                                os.symlink( os.readlink( src.file ), dst.file )