/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-05 22:29:08 UTC
  • Revision ID: tim@ed.am-20140405222908-3onggkfp5akpz21t
got symlink accept lists working; fixed some walker bugs

Show diffs side-by-side

added added

removed removed

21
21
 
22
22
import filecmp, os, shutil
23
23
from walker import Walker
24
 
from stdhome.file_matcher import FileMatcher
25
24
import stdhome.the as the
26
25
 
27
26
 
32
31
        information.
33
32
        """
34
33
 
35
 
        def __init__( self, updated_files = None ):
36
 
                self.accept_list = FileMatcher()
 
34
        accept_list = None
37
35
 
38
36
 
39
37
        def process( self, rel_file, src, dst ):
45
43
                        # since we're copying the whole directory)
46
44
                        if dst.type == '_':
47
45
                                if the.verbose > 1: self.print_op( rel_file, 'd>_' )
48
 
                                os.mkdir( dst.file )
49
 
                                shutil.copystat( src.file, dst.file )
50
 
                                return False
 
46
                                shutil.copytree( src.file, dst.file, True )
51
47
 
52
48
                        # if dst entity is a directory, copy permissions, as required (and
53
49
                        # recurse)
57
53
                                shutil.copystat( src.file, dst.file )
58
54
                                return True
59
55
 
60
 
                        # TODO: if dst entity is a symlink to a directory, and rel_file is
61
 
                        # matched by the acceptable symlinks file matcher, just recurse
62
 
                        elif dst.link_type == 'd' and self.accept_list.match( rel_file ):
 
56
                        # if dst entity is a symlink to a directory, and this is an
 
57
                        # acceptable substitute, just recurse
 
58
                        elif dst.link_type == 'd' and \
 
59
                                        self.accept_list and self.accept_list.match( rel_file ):
63
60
                                if the.verbose > 1: self.print_op( rel_file, 'd@d' )
64
61
                                return True
65
62
 
69
66
                        elif dst.type == 'f' or dst.type == 'l':
70
67
                                if the.verbose > 1: self.print_op( rel_file, 'd>' + dst.type )
71
68
                                os.unlink( dst.file )
72
 
                                os.mkdir( dst.file )
73
 
                                shutil.copystat( src.file, dst.file )
74
 
                                return False
 
69
                                shutil.copytree( src.file, dst.file, True )
75
70
 
76
71
                        else:
77
72
                                raise NotImplementedError()
78
73
 
79
74
                # src entity is file
80
 
                if src.type == 'f':
 
75
                elif src.type == 'f':
81
76
 
82
77
                        # if dst entity doesn't exist, copy file
83
78
                        if dst.type == '_':
113
108
                                raise NotImplementedError()
114
109
 
115
110
                # src entity is a symlink
116
 
                if src.type == 'l':
 
111
                elif src.type == 'l':
117
112
 
118
113
                        # if dst entity doesn't exist, copy symlink
119
114
                        if dst.type == '_':
135
130
                                os.unlink( dst.file )
136
131
                                os.symlink( os.readlink( src.file ), dst.file )
137
132
 
 
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 > 1: self.print_op( rel_file, 'd@d' )
 
138
                                return True
 
139
 
138
140
                        # if dst entity is a directory, replace it with symlink
139
141
                        elif dst.type == 'd':
140
142
                                if the.verbose > 1: self.print_op( rel_file, 'l>d' )
145
147
                                raise NotImplementedError()
146
148
 
147
149
                # src entity is missing
148
 
                if src.type == '_':
 
150
                elif src.type == '_':
149
151
 
150
152
                        # if dst entity doesn't exist, we're good
151
153
                        if dst.type == '_':
164
166
                        else:
165
167
                                raise NotImplementedError()
166
168
 
167
 
                # non-directories can not be recursed in to
 
169
                # if we got here, we don't want to recurse...
168
170
                return False