/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: 2016-02-16 00:26:53 UTC
  • Revision ID: tim@ed.am-20160216002653-oa8dgponknyislg3
added home directory change reporting to CopyOutWalker; added --quiet option to
update, resolve, revert and init commands; replace use of re.match with
re.search for clarity (and fixed related bug in FileMatcher); added BzrVcs.run
command output when verbose >= 2

Show diffs side-by-side

added added

removed removed

28
28
        """The copy-base walker traverses a walklist ruthlessly mirroring src to dst.
29
29
        It is designed to be the base class of both the copy-in and copy-out walker,
30
30
        both of which are specialisations of this purpose.  See them for more
31
 
        information.
 
31
        information.  The print_op method, derived in those classes, takes, in
 
32
        addition to the relative filename, a source file type, an operation, and a
 
33
        sestination file type.  Valid file types are f (file), l (symlink), d
 
34
        (directory) and _ (non-existant).  Valid operations are * (modify), = (skip:
 
35
        same), @ (skip: symlink substitute) and # (skip: ignored).
32
36
        """
33
37
 
34
38
 
42
46
 
43
47
                # ignore?
44
48
                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 ) )
 
49
                        self.print_op( rel_file, src.type, '#', dst.type )
47
50
                        return True
48
51
 
49
52
                # src entity is directory
52
55
                        # if dst entity doesn't exist, create directory (no need to recurse,
53
56
                        # since we're copying the whole directory)
54
57
                        if dst.type == '_':
55
 
                                if the.verbose >= 2: self.print_op( rel_file, 'd>_' )
 
58
                                self.print_op( rel_file, 'd', '*', '_' )
56
59
                                shutil.copytree( src.file, dst.file, True )
57
60
 
58
61
                        # if dst entity is a directory, copy permissions, as required (and
59
62
                        # recurse)
60
63
                        elif dst.type == 'd':
61
64
                                # TODO: should check permission and only do as necessary
62
 
                                if the.verbose >= 2: self.print_op( rel_file, 'd>d' )
 
65
                                self.print_op( rel_file, 'd', '*', 'd' )
63
66
                                shutil.copystat( src.file, dst.file )
64
67
                                return True
65
68
 
67
70
                        # acceptable substitute, just recurse
68
71
                        elif self.check_dst_symlinks and dst.link_type == 'd' and \
69
72
                                        the.config.symlinks.matches( rel_file ):
70
 
                                if the.verbose >= 2: self.print_op( rel_file, 'd@d' )
 
73
                                self.print_op( rel_file, 'd', '@', 'd' )
71
74
                                return True
72
75
 
73
76
                        # if dst entity is a file or symlink in home dir, replace it with
74
77
                        # directory (no need to recurse, since we're copying the whole
75
78
                        # directory)
76
79
                        elif dst.type == 'f' or dst.type == 'l':
77
 
                                if the.verbose >= 2: self.print_op( rel_file, 'd>' + dst.type )
 
80
                                self.print_op( rel_file, 'd', '*', dst.type )
78
81
                                os.unlink( dst.file )
79
82
                                shutil.copytree( src.file, dst.file, True )
80
83
 
86
89
 
87
90
                        # if dst entity doesn't exist, copy file
88
91
                        if dst.type == '_':
89
 
                                if the.verbose >= 2: self.print_op( rel_file, 'f>_' )
 
92
                                self.print_op( rel_file, 'f', '*', '_' )
90
93
                                shutil.copy( src.file, dst.file )
91
94
                                shutil.copystat( src.file, dst.file )
92
95
 
93
96
                        # if dst entity is a file, replace it only if it differs
94
97
                        elif dst.type == 'f':
95
98
                                if not filecmp.cmp( src.file, dst.file ):
96
 
                                        if the.verbose >= 2: self.print_op( rel_file, 'f>f' )
 
99
                                        self.print_op( rel_file, 'f', '*', 'f' )
97
100
                                        os.unlink( dst.file )
98
101
                                        shutil.copy( src.file, dst.file )
99
102
                                        shutil.copystat( src.file, dst.file )
100
103
                                else:
101
 
                                        if the.verbose >= 2: self.print_op( rel_file, 'f=f' )
 
104
                                        self.print_op( rel_file, 'f', '=', 'f' )
102
105
 
103
106
                        # if dst entity is a directory, replace it with file
104
107
                        elif dst.type == 'd':
105
 
                                if the.verbose >= 2: self.print_op( rel_file, 'f>d' )
 
108
                                self.print_op( rel_file, 'f', '*', 'd' )
106
109
                                shutil.rmtree( dst.file )
107
110
                                shutil.copy( src.file, dst.file )
108
111
                                shutil.copystat( src.file, dst.file )
109
112
 
110
113
                        # if dst entity is a symlink, replace it with file
111
114
                        elif dst.type == 'l':
112
 
                                if the.verbose >= 2: self.print_op( rel_file, 'f>l' )
 
115
                                self.print_op( rel_file, 'f', '*', 'l' )
113
116
                                os.unlink( dst.file )
114
117
                                shutil.copy( src.file, dst.file )
115
118
                                shutil.copystat( src.file, dst.file )
122
125
 
123
126
                        # if dst entity doesn't exist, copy symlink
124
127
                        if dst.type == '_':
125
 
                                if the.verbose >= 2: self.print_op( rel_file, 'l>_' )
 
128
                                self.print_op( rel_file, 'l', '*', '_' )
126
129
                                os.symlink( os.readlink( src.file ), dst.file )
127
130
 
128
131
                        # if dst entity is a symlink, replace it only if it differs
129
132
                        elif dst.type == 'l':
130
133
                                if os.readlink( src.file ) != os.readlink( dst.file ):
131
 
                                        if the.verbose >= 2: self.print_op( rel_file, 'l>l' )
 
134
                                        self.print_op( rel_file, 'l', '*', 'l' )
132
135
                                        os.unlink( dst.file )
133
136
                                        os.symlink( os.readlink( src.file ), dst.file )
134
137
                                else:
135
 
                                        if the.verbose >= 2: self.print_op( rel_file, 'l=l' )
 
138
                                        self.print_op( rel_file, 'l', '=', 'l' )
136
139
 
137
140
                        # if dst entity is a file, replace it with symlink
138
141
                        elif dst.type == 'f':
139
 
                                if the.verbose >= 2: self.print_op( rel_file, 'l>f' )
 
142
                                self.print_op( rel_file, 'l', '*', 'f' )
140
143
                                os.unlink( dst.file )
141
144
                                os.symlink( os.readlink( src.file ), dst.file )
142
145
 
147
150
                                # acceptable substitute, just recurse
148
151
                                if self.check_src_symlinks and src.link_type == 'd' and \
149
152
                                                the.config.symlinks.matches( rel_file ):
150
 
                                        if the.verbose >= 2: self.print_op( rel_file, 'd@d' )
 
153
                                        self.print_op( rel_file, 'd', '@', 'd' )
151
154
                                        return True
152
155
 
153
156
                                # else replace it with a symlink
154
 
                                if the.verbose >= 2: self.print_op( rel_file, 'l>d' )
 
157
                                self.print_op( rel_file, 'l', '*', 'd' )
155
158
                                shutil.rmtree( dst.file )
156
159
                                os.symlink( os.readlink( src.file ), dst.file )
157
160
 
167
170
 
168
171
                        # if dst entity is a file or symlink, delete it
169
172
                        elif dst.type == 'f' or dst.type == 'l':
170
 
                                if the.verbose >= 2: self.print_op( rel_file, '_>' + dst.type )
 
173
                                self.print_op( rel_file, '_', '*', dst.type )
171
174
                                os.unlink( dst.file )
172
175
 
173
176
                        # if dst entity is a directory, delete it
174
177
                        elif dst.type == 'd':
175
 
                                if the.verbose >= 2: self.print_op( rel_file, '_>d' )
 
178
                                self.print_op( rel_file, '_', '*', 'd' )
176
179
                                shutil.rmtree( dst.file )
177
180
 
178
181
                        else: