/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_out.py

  • Committer: Tim Marston
  • Date: 2014-03-19 20:01:06 UTC
  • Revision ID: tim@ed.am-20140319200106-ou5y1nat6y2auaue
removed square brackets from AC_INIT parameter

Show diffs side-by-side

added added

removed removed

43
43
                self.walk_list = updated_files if updated_files is not None else \
44
44
                                                 self.generate_walk_list( the.repo.full_dir )
45
45
 
46
 
                self.accept_symlinks = list()
47
 
 
48
 
 
49
 
        def process( self, rel_file, src, dst ):
 
46
 
 
47
        def process( self, rel_file, src_file, src_type, dst_file, dst_type ):
50
48
 
51
49
                # directory (in repo)
52
 
                if src.type == 'd':
 
50
                if src_type == 'd':
53
51
 
54
52
                        # if entity doesn't exist in home dir, create directory (no need to
55
53
                        # recurse, since we're copying the whole directory)
56
 
                        if dst.type == '_':
 
54
                        if dst_type == '_':
57
55
                                if the.verbose > 1: print "  _<d " + rel_file
58
 
                                os.mkdir( dst.file )
59
 
                                shutil.copystat( src.file, dst.file )
 
56
                                os.mkdir( dst_file )
 
57
                                shutil.copystat( src_file, dst_file )
 
58
                                return False
 
59
 
 
60
                        # if entity is a file or symlink in home dir, replace it with
 
61
                        # directory (no need to recurse, since we're copying the whole
 
62
                        # directory)
 
63
                        elif dst_type == 'f' or dst_type == 'l':
 
64
                                if the.verbose > 1: print "  %s<d %s" % ( dst_type, rel_file )
 
65
                                os.unlink( dst_file )
 
66
                                os.mkdir( dst_file )
 
67
                                shutil.copystat( src_file, dst_file )
60
68
                                return False
61
69
 
62
70
                        # if entity is a directory in home dir, copy permissions, as
63
71
                        # required (and recurse)
64
 
                        elif dst.type == 'd':
 
72
                        elif dst_type == 'd':
65
73
                                # TODO: should check permission and only do as necessary
66
74
                                if the.verbose > 1: print "  d<d " + rel_file
67
 
                                shutil.copystat( src.file, dst.file )
 
75
                                shutil.copystat( src_file, dst_file )
68
76
                                return True
69
77
 
70
 
                        # TODO: if entity is a symlink to a directory, and this is
71
 
                        # acceptable, just recurse
72
 
#                       elif dst.link_type == 'd' and self.accept_list.match( rel_file ):
73
 
#                               if the.verbose > 1: print "  d@=d " + rel_file
74
 
#                               return True
75
 
 
76
 
                        # if entity is a file or symlink in home dir, replace it with
77
 
                        # directory (no need to recurse, since we're copying the whole
78
 
                        # directory)
79
 
                        elif dst.type == 'f' or dst.type == 'l':
80
 
                                if the.verbose > 1: print "  %s<d %s" % ( dst.type, rel_file )
81
 
                                os.unlink( dst.file )
82
 
                                os.mkdir( dst.file )
83
 
                                shutil.copystat( src.file, dst.file )
84
 
                                return False
85
 
 
86
78
                        else:
87
79
                                raise NotImplementedError()
88
80
 
89
81
                # file (in repo)
90
 
                if src.type == 'f':
 
82
                if src_type == 'f':
91
83
 
92
84
                        # if entity doesn't exist in home dir, copy file
93
 
                        if dst.type == '_':
 
85
                        if dst_type == '_':
94
86
                                if the.verbose > 1: print "  _<f " + rel_file
95
 
                                shutil.copy( src.file, dst.file )
96
 
                                shutil.copystat( src.file, dst.file )
 
87
                                shutil.copy( src_file, dst_file )
 
88
                                shutil.copystat( src_file, dst_file )
 
89
 
 
90
                        # if entity is a symlink in home dir, replace it with file
 
91
                        elif dst_type == 'l':
 
92
                                if the.verbose > 1: print "  l<f " + rel_file
 
93
                                os.unlink( dst_file )
 
94
                                shutil.copy( src_file, dst_file )
 
95
                                shutil.copystat( src_file, dst_file )
97
96
 
98
97
                        # if entity is a file in home dir, replace it only if it differs
99
 
                        elif dst.type == 'f':
100
 
                                if not filecmp.cmp( src.file, dst.file ):
 
98
                        elif dst_type == 'f':
 
99
                                if not filecmp.cmp( src_file, dst_file ):
101
100
                                        if the.verbose > 1: print "  f<f " + rel_file
102
 
                                        os.unlink( dst.file )
103
 
                                        shutil.copy( src.file, dst.file )
104
 
                                        shutil.copystat( src.file, dst.file )
 
101
                                        os.unlink( dst_file )
 
102
                                        shutil.copy( src_file, dst_file )
 
103
                                        shutil.copystat( src_file, dst_file )
105
104
                                else:
106
105
                                        if the.verbose > 1: print "  f=f " + rel_file
107
106
 
108
107
                        # if entity is a directory in home dir, replace it with file
109
 
                        elif dst.type == 'd':
 
108
                        elif dst_type == 'd':
110
109
                                if the.verbose > 1: print "  d<f " + rel_file
111
 
                                shutil.rmtree( dst.file )
112
 
                                shutil.copy( src.file, dst.file )
113
 
                                shutil.copystat( src.file, dst.file )
114
 
 
115
 
                        # if entity is a symlink in home dir, replace it with file
116
 
                        elif dst.type == 'l':
117
 
                                if the.verbose > 1: print "  l<f " + rel_file
118
 
                                os.unlink( dst.file )
119
 
                                shutil.copy( src.file, dst.file )
120
 
                                shutil.copystat( src.file, dst.file )
 
110
                                shutil.rmtree( dst_file )
 
111
                                shutil.copy( src_file, dst_file )
 
112
                                shutil.copystat( src_file, dst_file )
121
113
 
122
114
                        else:
123
115
                                raise NotImplementedError()
124
116
 
125
117
                # link (in repo)
126
 
                if src.type == 'l':
 
118
                if src_type == 'l':
127
119
 
128
120
                        # if entity doesn't exist in home dir, copy symlink
129
 
                        if dst.type == '_':
 
121
                        if dst_type == '_':
130
122
                                if the.verbose > 1: print "  _<l " + rel_file
131
 
                                os.symlink( os.readlink( src.file ), dst.file )
 
123
                                os.symlink( os.readlink( src_file ), dst_file )
132
124
 
133
125
                        # if entity is a symlink in home dir, replace it only if it differs
134
 
                        elif dst.type == 'l':
135
 
                                if os.readlink( src.file ) != os.readlink( dst.file ):
 
126
                        elif dst_type == 'l':
 
127
                                if os.readlink( src_file ) != os.readlink( dst_file ):
136
128
                                        if the.verbose > 1: print "  l<l " + rel_file
137
 
                                        os.unlink( dst.file )
138
 
                                        os.symlink( os.readlink( src.file ), dst.file )
 
129
                                        os.unlink( dst_file )
 
130
                                        os.symlink( os.readlink( src_file ), dst_file )
139
131
                                else:
140
132
                                        if the.verbose > 1: print "  l=l " + rel_file
141
133
 
142
134
                        # if entity is a file in home dir, replace it with file
143
 
                        elif dst.type == 'f':
 
135
                        elif dst_type == 'f':
144
136
                                if the.verbose > 1: print "  f<l " + rel_file
145
 
                                os.unlink( dst.file )
146
 
                                os.symlink( os.readlink( src.file ), dst.file )
 
137
                                os.unlink( dst_file )
 
138
                                os.symlink( os.readlink( src_file ), dst_file )
147
139
 
148
140
                        # if entity is a directory in home dir, replace it with file
149
 
                        elif dst.type == 'd':
 
141
                        elif dst_type == 'd':
150
142
                                if the.verbose > 1: print "  d<l " + rel_file
151
 
                                shutil.rmtree( dst.file )
152
 
                                os.symlink( os.readlink( src.file ), dst.file )
 
143
                                shutil.rmtree( dst_file )
 
144
                                os.symlink( os.readlink( src_file ), dst_file )
153
145
 
154
146
                        else:
155
147
                                raise NotImplementedError()
156
148
 
157
 
                # deleted file (in repo)
158
 
                if src.type == '_':
 
149
                # deleted file
 
150
                if src_type == '_':
159
151
 
160
152
                        # if entity doesn't exist in home dir, we're good
161
 
                        if dst.type == '_':
 
153
                        if dst_type == '_':
162
154
                                pass;
163
155
 
164
156
                        # if entity is a file or symlink in home dir, delete it
165
 
                        if dst.type == 'f' or dst.type == 'l':
166
 
                                if the.verbose > 1: print "  %s<_ %s" % ( dst.type, rel_file )
167
 
                                os.unlink( dst.file )
 
157
                        if dst_type == 'f' or dst_type == 'l':
 
158
                                if the.verbose > 1: print "  %s<_ %s" % ( dst_type, rel_file )
 
159
                                os.unlink( dst_file )
168
160
 
169
161
                        # if entity is a directory in home dir, delete it
170
 
                        elif dst.type == 'd':
 
162
                        elif dst_type == 'd':
171
163
                                if the.verbose > 1: print "  d<_ " + rel_file
172
 
                                shutil.rmtree( dst.file )
 
164
                                shutil.rmtree( dst_file )
173
165
 
174
166
                        else:
175
167
                                raise NotImplementedError()