/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 19:20:06 UTC
  • Revision ID: tim@ed.am-20140405192006-fv0toip4b8m5pc88
fixed bug preventing skipping of subdirectories in walker; also added
walker.File.__str__()

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
                        # if dst entity doesn't exist, create directory (no need to recurse,
45
45
                        # since we're copying the whole directory)
46
46
                        if dst.type == '_':
47
 
                                if the.verbose > 1: self.print_op( rel_file, 'd>_' )
 
47
                                if the.verbose > 1: self.print_cp( rel_file, 'd', '_' )
48
48
                                os.mkdir( dst.file )
49
49
                                shutil.copystat( src.file, dst.file )
50
50
                                return False
53
53
                        # recurse)
54
54
                        elif dst.type == 'd':
55
55
                                # TODO: should check permission and only do as necessary
56
 
                                if the.verbose > 1: self.print_op( rel_file, 'd>d' )
 
56
                                if the.verbose > 1: self.print_cp( rel_file, 'd', 'd' )
57
57
                                shutil.copystat( src.file, dst.file )
58
58
                                return True
59
59
 
60
60
                        # TODO: if dst entity is a symlink to a directory, and rel_file is
61
61
                        # matched by the acceptable symlinks file matcher, just recurse
62
 
                        elif dst.link_type == 'd' and self.accept_list.match( rel_file ):
63
 
                                if the.verbose > 1: self.print_op( rel_file, 'd@d' )
64
 
                                return True
 
62
#                       elif dst.link_type == 'd' and self.accept_list.match( rel_file ):
 
63
#                               if the.verbose > 1: self.print_cp( rel_file, 'd', 'd', '@' )
 
64
#                               return True
65
65
 
66
66
                        # if dst entity is a file or symlink in home dir, replace it with
67
67
                        # directory (no need to recurse, since we're copying the whole
68
68
                        # directory)
69
69
                        elif dst.type == 'f' or dst.type == 'l':
70
 
                                if the.verbose > 1: self.print_op( rel_file, 'd>' + dst.type )
 
70
                                if the.verbose > 1: self.print_cp( rel_file, 'd', dst.type )
71
71
                                os.unlink( dst.file )
72
72
                                os.mkdir( dst.file )
73
73
                                shutil.copystat( src.file, dst.file )
81
81
 
82
82
                        # if dst entity doesn't exist, copy file
83
83
                        if dst.type == '_':
84
 
                                if the.verbose > 1: self.print_op( rel_file, 'f>_' )
 
84
                                if the.verbose > 1: self.print_cp( rel_file, 'f', '_' )
85
85
                                shutil.copy( src.file, dst.file )
86
86
                                shutil.copystat( src.file, dst.file )
87
87
 
88
88
                        # if dst entity is a file, replace it only if it differs
89
89
                        elif dst.type == 'f':
90
90
                                if not filecmp.cmp( src.file, dst.file ):
91
 
                                        if the.verbose > 1: self.print_op( rel_file, 'f>f' )
 
91
                                        if the.verbose > 1: self.print_cp( rel_file, 'f', 'f' )
92
92
                                        os.unlink( dst.file )
93
93
                                        shutil.copy( src.file, dst.file )
94
94
                                        shutil.copystat( src.file, dst.file )
95
95
                                else:
96
 
                                        if the.verbose > 1: self.print_op( rel_file, 'f=f' )
 
96
                                        if the.verbose > 1: self.print_cp( rel_file, 'f', 'f', '=' )
97
97
 
98
98
                        # if dst entity is a directory, replace it with file
99
99
                        elif dst.type == 'd':
100
 
                                if the.verbose > 1: self.print_op( rel_file, 'f>d' )
 
100
                                if the.verbose > 1: self.print_cp( rel_file, 'f', 'd' )
101
101
                                shutil.rmtree( dst.file )
102
102
                                shutil.copy( src.file, dst.file )
103
103
                                shutil.copystat( src.file, dst.file )
104
104
 
105
105
                        # if dst entity is a symlink, replace it with file
106
106
                        elif dst.type == 'l':
107
 
                                if the.verbose > 1: self.print_op( rel_file, 'f>l' )
 
107
                                if the.verbose > 1: self.print_cp( rel_file, 'f', 'l' )
108
108
                                os.unlink( dst.file )
109
109
                                shutil.copy( src.file, dst.file )
110
110
                                shutil.copystat( src.file, dst.file )
117
117
 
118
118
                        # if dst entity doesn't exist, copy symlink
119
119
                        if dst.type == '_':
120
 
                                if the.verbose > 1: self.print_op( rel_file, 'l>_' )
 
120
                                if the.verbose > 1: self.print_cp( rel_file, 'l', '_' )
121
121
                                os.symlink( os.readlink( src.file ), dst.file )
122
122
 
123
123
                        # if dst entity is a symlink, replace it only if it differs
124
124
                        elif dst.type == 'l':
125
125
                                if os.readlink( src.file ) != os.readlink( dst.file ):
126
 
                                        if the.verbose > 1: self.print_op( rel_file, 'l>l' )
 
126
                                        if the.verbose > 1: self.print_cp( rel_file, 'l', 'l' )
127
127
                                        os.unlink( dst.file )
128
128
                                        os.symlink( os.readlink( src.file ), dst.file )
129
129
                                else:
130
 
                                        if the.verbose > 1: self.print_op( rel_file, 'l=l' )
 
130
                                        if the.verbose > 1: self.print_cp( rel_file, 'l', 'l', '=' )
131
131
 
132
132
                        # if dst entity is a file, replace it with symlink
133
133
                        elif dst.type == 'f':
134
 
                                if the.verbose > 1: self.print_op( rel_file, 'l>f' )
 
134
                                if the.verbose > 1: self.print_cp( rel_file, 'l', 'f' )
135
135
                                os.unlink( dst.file )
136
136
                                os.symlink( os.readlink( src.file ), dst.file )
137
137
 
138
138
                        # if dst entity is a directory, replace it with symlink
139
139
                        elif dst.type == 'd':
140
 
                                if the.verbose > 1: self.print_op( rel_file, 'l>d' )
 
140
                                if the.verbose > 1: self.print_cp( rel_file, 'l', 'd' )
141
141
                                shutil.rmtree( dst.file )
142
142
                                os.symlink( os.readlink( src.file ), dst.file )
143
143
 
152
152
                                pass;
153
153
 
154
154
                        # if dst entity is a file or symlink, delete it
155
 
                        elif dst.type == 'f' or dst.type == 'l':
156
 
                                if the.verbose > 1: self.print_op( rel_file, '_>' + dst.type )
 
155
                        if dst.type == 'f' or dst.type == 'l':
 
156
                                if the.verbose > 1: self.print_cp( rel_file, '_', dst.type )
157
157
                                os.unlink( dst.file )
158
158
 
159
159
                        # if dst entity is a directory, delete it
160
160
                        elif dst.type == 'd':
161
 
                                if the.verbose > 1: self.print_op( rel_file, '_>d' )
 
161
                                if the.verbose > 1: self.print_cp( rel_file, '_', 'd' )
162
162
                                shutil.rmtree( dst.file )
163
163
 
164
164
                        else: