/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-12 12:53:54 UTC
  • Revision ID: tim@ed.am-20140412125354-64aysxvaz7nnk8hm
make verbose levels clearer

Show diffs side-by-side

added added

removed removed

42
42
                        # if dst entity doesn't exist, create directory (no need to recurse,
43
43
                        # since we're copying the whole directory)
44
44
                        if dst.type == '_':
45
 
                                if the.verbose > 1: self.print_op( rel_file, 'd>_' )
 
45
                                if the.verbose >= 2: self.print_op( rel_file, 'd>_' )
46
46
                                shutil.copytree( src.file, dst.file, True )
47
47
 
48
48
                        # if dst entity is a directory, copy permissions, as required (and
49
49
                        # recurse)
50
50
                        elif dst.type == 'd':
51
51
                                # TODO: should check permission and only do as necessary
52
 
                                if the.verbose > 1: self.print_op( rel_file, 'd>d' )
 
52
                                if the.verbose >= 2: self.print_op( rel_file, 'd>d' )
53
53
                                shutil.copystat( src.file, dst.file )
54
54
                                return True
55
55
 
57
57
                        # acceptable substitute, just recurse
58
58
                        elif dst.link_type == 'd' and \
59
59
                                        self.accept_list and self.accept_list.match( rel_file ):
60
 
                                if the.verbose > 1: self.print_op( rel_file, 'd@d' )
 
60
                                if the.verbose >= 2: self.print_op( rel_file, 'd@d' )
61
61
                                return True
62
62
 
63
63
                        # if dst entity is a file or symlink in home dir, replace it with
64
64
                        # directory (no need to recurse, since we're copying the whole
65
65
                        # directory)
66
66
                        elif dst.type == 'f' or dst.type == 'l':
67
 
                                if the.verbose > 1: self.print_op( rel_file, 'd>' + dst.type )
 
67
                                if the.verbose >= 2: self.print_op( rel_file, 'd>' + dst.type )
68
68
                                os.unlink( dst.file )
69
69
                                shutil.copytree( src.file, dst.file, True )
70
70
 
76
76
 
77
77
                        # if dst entity doesn't exist, copy file
78
78
                        if dst.type == '_':
79
 
                                if the.verbose > 1: self.print_op( rel_file, 'f>_' )
 
79
                                if the.verbose >= 2: self.print_op( rel_file, 'f>_' )
80
80
                                shutil.copy( src.file, dst.file )
81
81
                                shutil.copystat( src.file, dst.file )
82
82
 
83
83
                        # if dst entity is a file, replace it only if it differs
84
84
                        elif dst.type == 'f':
85
85
                                if not filecmp.cmp( src.file, dst.file ):
86
 
                                        if the.verbose > 1: self.print_op( rel_file, 'f>f' )
 
86
                                        if the.verbose >= 2: self.print_op( rel_file, 'f>f' )
87
87
                                        os.unlink( dst.file )
88
88
                                        shutil.copy( src.file, dst.file )
89
89
                                        shutil.copystat( src.file, dst.file )
90
90
                                else:
91
 
                                        if the.verbose > 1: self.print_op( rel_file, 'f=f' )
 
91
                                        if the.verbose >= 2: self.print_op( rel_file, 'f=f' )
92
92
 
93
93
                        # if dst entity is a directory, replace it with file
94
94
                        elif dst.type == 'd':
95
 
                                if the.verbose > 1: self.print_op( rel_file, 'f>d' )
 
95
                                if the.verbose >= 2: self.print_op( rel_file, 'f>d' )
96
96
                                shutil.rmtree( dst.file )
97
97
                                shutil.copy( src.file, dst.file )
98
98
                                shutil.copystat( src.file, dst.file )
99
99
 
100
100
                        # if dst entity is a symlink, replace it with file
101
101
                        elif dst.type == 'l':
102
 
                                if the.verbose > 1: self.print_op( rel_file, 'f>l' )
 
102
                                if the.verbose >= 2: self.print_op( rel_file, 'f>l' )
103
103
                                os.unlink( dst.file )
104
104
                                shutil.copy( src.file, dst.file )
105
105
                                shutil.copystat( src.file, dst.file )
112
112
 
113
113
                        # if dst entity doesn't exist, copy symlink
114
114
                        if dst.type == '_':
115
 
                                if the.verbose > 1: self.print_op( rel_file, 'l>_' )
 
115
                                if the.verbose >= 2: self.print_op( rel_file, 'l>_' )
116
116
                                os.symlink( os.readlink( src.file ), dst.file )
117
117
 
118
118
                        # if dst entity is a symlink, replace it only if it differs
119
119
                        elif dst.type == 'l':
120
120
                                if os.readlink( src.file ) != os.readlink( dst.file ):
121
 
                                        if the.verbose > 1: self.print_op( rel_file, 'l>l' )
 
121
                                        if the.verbose >= 2: self.print_op( rel_file, 'l>l' )
122
122
                                        os.unlink( dst.file )
123
123
                                        os.symlink( os.readlink( src.file ), dst.file )
124
124
                                else:
125
 
                                        if the.verbose > 1: self.print_op( rel_file, 'l=l' )
 
125
                                        if the.verbose >= 2: self.print_op( rel_file, 'l=l' )
126
126
 
127
127
                        # if dst entity is a file, replace it with symlink
128
128
                        elif dst.type == 'f':
129
 
                                if the.verbose > 1: self.print_op( rel_file, 'l>f' )
 
129
                                if the.verbose >= 2: self.print_op( rel_file, 'l>f' )
130
130
                                os.unlink( dst.file )
131
131
                                os.symlink( os.readlink( src.file ), dst.file )
132
132
 
134
134
                        # directory, and this is an acceptable substitute, just recurse
135
135
                        elif dst.type == 'd' and src.link_type == 'd' and \
136
136
                                        self.accept_list and self.accept_list.match( rel_file ):
137
 
                                if the.verbose > 1: self.print_op( rel_file, 'd@d' )
 
137
                                if the.verbose >= 2: self.print_op( rel_file, 'd@d' )
138
138
                                return True
139
139
 
140
140
                        # if dst entity is a directory, replace it with symlink
141
141
                        elif dst.type == 'd':
142
 
                                if the.verbose > 1: self.print_op( rel_file, 'l>d' )
 
142
                                if the.verbose >= 2: self.print_op( rel_file, 'l>d' )
143
143
                                shutil.rmtree( dst.file )
144
144
                                os.symlink( os.readlink( src.file ), dst.file )
145
145
 
155
155
 
156
156
                        # if dst entity is a file or symlink, delete it
157
157
                        elif dst.type == 'f' or dst.type == 'l':
158
 
                                if the.verbose > 1: self.print_op( rel_file, '_>' + dst.type )
 
158
                                if the.verbose >= 2: self.print_op( rel_file, '_>' + dst.type )
159
159
                                os.unlink( dst.file )
160
160
 
161
161
                        # if dst entity is a directory, delete it
162
162
                        elif dst.type == 'd':
163
 
                                if the.verbose > 1: self.print_op( rel_file, '_>d' )
 
163
                                if the.verbose >= 2: self.print_op( rel_file, '_>d' )
164
164
                                shutil.rmtree( dst.file )
165
165
 
166
166
                        else: