/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:27:09 UTC
  • Revision ID: tim@ed.am-20140405222709-4mp50aiu184blnf1
fixed file_matcher

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