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

  • Committer: Tim Marston
  • Date: 2014-04-04 22:28:49 UTC
  • Revision ID: tim@ed.am-20140404222849-32apy1i949qaq2na
walker now passes Walker.File objects to process(), which includes file name,
type and the type of file it points to when it's a symlink

Show diffs side-by-side

added added

removed removed

42
42
                self.changed = list()
43
43
 
44
44
 
45
 
        def process( self, rel_file, src_file, src_type, dst_file, dst_type ):
 
45
        def process( self, rel_file, src, dst ):
46
46
 
47
47
                # directory (in repo)
48
 
                if dst_type == 'd':
 
48
                if dst.type == 'd':
49
49
 
50
50
                        # if entity doesn't exist in home dir, delete directory in repo (and
51
51
                        # don't recurse, obviously!)
52
 
                        if src_type == '_':
 
52
                        if src.type == '_':
53
53
                                if the.verbose > 1: print "  _>d " + rel_file
54
 
                                shutil.rmtree( dst_file )
 
54
                                shutil.rmtree( dst.file )
55
55
                                return False
56
56
 
57
57
                        # if entity is a directory in home dir, copy permissions to
58
58
                        # diurectory in repo, as necessary, and recurse
59
 
                        elif src_type == 'd':
 
59
                        elif src.type == 'd':
60
60
                                # TODO: should check permissions and only do as necessary
61
61
                                if the.verbose > 1: print "  d>d " + rel_file
62
 
                                shutil.copystat( src_file, dst_file )
 
62
                                shutil.copystat( src.file, dst.file )
63
63
                                return True
64
64
 
65
 
                        # TODO: serious differences in between ~/ and repo (e.g., files in
66
 
                        # one that are directories in the other) should be ignored (e.g.,
67
 
                        # not copied-in).  And the stuff that is ignored during copy-in
68
 
                        # should also be ignored during copy-out and must not be added to
69
 
                        # the deploy_files list.  Since these ignored files/directories are
70
 
                        # transparent to the user, they should have to explicitly permit
71
 
                        # them via an ignore file (e.g., ~/.stdhome/.ignore, akin to bzr's
72
 
                        # .bzrignore file).  If these serious differences are not matched by
73
 
                        # the ignore file, an error should show (which will requie a
74
 
                        # separate "check" walk of the repo, as is done in copy_out).
 
65
                        # TODO: if entity is a directory symlink in the home direcotry,
 
66
                        # silently accept it if it is explicitly matched by the accept list.
 
67
                        # In which case, we'll also need to add this rel_file to a
 
68
                        # not_deployed file list so that, after this walk, we can remove it
 
69
                        # from the deployment's deploy_list.  If we don't, the directory in
 
70
                        # the repo will get copied-out.
 
71
#                       elif src.link_type == 'd' and self.accept_list.matches( rel_file ):
 
72
#                               if the.verbose > 1: print "  d@d " + rel_file
 
73
#                               return True
 
74
 
 
75
                        # TODO: serious differences between ~/ and repo (e.g., files in one
 
76
                        # that are directories in the other) should be ignored (e.g., not
 
77
                        # copied-in).  And the stuff that is ignored during copy-in should
 
78
                        # also be ignored during copy-out and must not be added to the
 
79
                        # deployment's deploy_files list.  Since these ignored files and
 
80
                        # directories are transparent to the user, they must be explicitly
 
81
                        # permitted via an "ignore list" in ~/.stdhomerc.  If these serious
 
82
                        # differences are not matched by the ignore list, an error should be
 
83
                        # shown (which will require a separate "check" walk of the repo, as
 
84
                        # is done in copy_out).
75
85
                        else:
76
 
                                self.changed.append( "%s (now %s)" % (
77
 
                                        rel_file, self.name_of_type( src_type ) ) )
 
86
                                self.changed.append( "%s (%s => %s)" % ( rel_file,
 
87
                                        dst.get_type_name(), src.get_type_name() ) )
78
88
                                return False
79
89
 
80
90
                # file (in repo)
81
 
                elif dst_type == 'f':
 
91
                elif dst.type == 'f':
82
92
 
83
93
                        # if entity doesn't exist in home dir, delete file in repo
84
 
                        if src_type == '_':
 
94
                        if src.type == '_':
85
95
                                if the.verbose > 1: print "  _>f " + rel_file
86
 
                                os.unlink( dst_file )
 
96
                                os.unlink( dst.file )
87
97
 
88
98
                        # if entity in home dir is a symlink, replace file in repo
89
 
                        elif src_type == 'l':
 
99
                        elif src.type == 'l':
90
100
                                if the.verbose > 1: print "  l>f " + rel_file
91
 
                                os.unlink( dst_file )
92
 
                                os.symlink( os.readlink( src_file ), dst_file )
 
101
                                os.unlink( dst.file )
 
102
                                os.symlink( os.readlink( src.file ), dst.file )
93
103
 
94
104
                        # if entity in home dir is a file, replace file in repo only if it
95
105
                        # differs
96
 
                        elif src_type == 'f':
97
 
                                if not filecmp.cmp( src_file, dst_file ):
 
106
                        elif src.type == 'f':
 
107
                                if not filecmp.cmp( src.file, dst.file ):
98
108
                                        if the.verbose > 1: print "  f>f " + rel_file
99
 
                                        os.unlink( dst_file )
100
 
                                        shutil.copy( src_file, dst_file )
101
 
                                        shutil.copystat( src_file, dst_file )
 
109
                                        os.unlink( dst.file )
 
110
                                        shutil.copy( src.file, dst.file )
 
111
                                        shutil.copystat( src.file, dst.file )
102
112
                                else:
103
113
                                        if the.verbose > 1: print "  f=f " + rel_file
104
114
 
105
 
                        # TODO: serious differences in between ~/ and repo (e.g., files in
106
 
                        # one that are directories in the other) should be ignored (e.g.,
107
 
                        # not copied-in).  And the stuff that is ignored during copy-in
108
 
                        # should also be ignored during copy-out and must not be added to
109
 
                        # the deploy_files list.  Since these ignored files/directories are
110
 
                        # transparent to the user, they should have to explicitly permit
111
 
                        # them via an ignore file (e.g., ~/.stdhome/.ignore, akin to bzr's
112
 
                        # .bzrignore file).  If these serious differences are not matched by
113
 
                        # the ignore file, an error should show (which will requie a
114
 
                        # separate "check" walk of the repo, as is done in copy_out).
 
115
                        # TODO: serious differences between ~/ and repo (e.g., files in one
 
116
                        # that are directories in the other) should be ignored (e.g., not
 
117
                        # copied-in).  And the stuff that is ignored during copy-in should
 
118
                        # also be ignored during copy-out and must not be added to the
 
119
                        # deployment's deploy_files list.  Since these ignored files and
 
120
                        # directories are transparent to the user, they must be explicitly
 
121
                        # permitted via an "ignore list" in ~/.stdhomerc.  If these serious
 
122
                        # differences are not matched by the ignore list, an error should be
 
123
                        # show (which will require a separate "check" walk of the repo, as
 
124
                        # is done in copy_out).
115
125
                        else:
116
 
                                self.changed.append( "%s (now %s)" % (
117
 
                                        rel_file, self.name_of_type( src_type ) ) )
 
126
                                self.changed.append( "%s (%s => %s)" % ( rel_file,
 
127
                                        dst.get_type_name(), src.get_type_name() ) )
118
128
 
119
129
                # symlink (in repo)
120
 
                elif dst_type == 'l':
 
130
                elif dst.type == 'l':
121
131
 
122
132
                        # if entity doesn't exist in home dir, delete symlink in repo
123
 
                        if src_type == '_':
 
133
                        if src.type == '_':
124
134
                                if the.verbose > 1: print "  _>l " + rel_file
125
 
                                os.unlink( dst_file )
 
135
                                os.unlink( dst.file )
126
136
 
127
137
                        # if entity in home dir is a symlink, replace symlink in repo only
128
138
                        # if it differs
129
 
                        elif src_type == 'l':
130
 
                                if os.readlink( src_file ) != os.readlink( dst_file ):
 
139
                        elif src.type == 'l':
 
140
                                if os.readlink( src.file ) != os.readlink( dst.file ):
131
141
                                        if the.verbose > 1: print "  l>l " + rel_file
132
 
                                        os.unlink( dst_file )
133
 
                                        os.symlink( os.readlink( src_file ), dst_file )
 
142
                                        os.unlink( dst.file )
 
143
                                        os.symlink( os.readlink( src.file ), dst.file )
134
144
                                else:
135
145
                                        if the.verbose > 1: print "  l=l " + rel_file
136
146
 
137
147
                        # if entity in home dir is a file, replace symlink in repo
138
 
                        elif src_type == 'f':
 
148
                        elif src.type == 'f':
139
149
                                if the.verbose > 1: print "  f>l " + rel_file
140
 
                                os.unlink( dst_file )
141
 
                                shutil.copy( src_file, dst_file )
142
 
                                shutil.copystat( src_file, dst_file )
 
150
                                os.unlink( dst.file )
 
151
                                shutil.copy( src.file, dst.file )
 
152
                                shutil.copystat( src.file, dst.file )
143
153
 
144
 
                        # TODO: serious differences in between ~/ and repo (e.g., files in
145
 
                        # one that are directories in the other) should be ignored (e.g.,
146
 
                        # not copied-in).  And the stuff that is ignored during copy-in
147
 
                        # should also be ignored during copy-out and must not be added to
148
 
                        # the deploy_files list.  Since these ignored files/directories are
149
 
                        # transparent to the user, they should have to explicitly permit
150
 
                        # them via an ignore file (e.g., ~/.stdhome/.ignore, akin to bzr's
151
 
                        # .bzrignore file).  If these serious differences are not matched by
152
 
                        # the ignore file, an error should show (which will requie a
153
 
                        # separate "check" walk of the repo, as is done in copy_out).
 
154
                        # TODO: serious differences between ~/ and repo (e.g., files in one
 
155
                        # that are directories in the other) should be ignored (e.g., not
 
156
                        # copied-in).  And the stuff that is ignored during copy-in should
 
157
                        # also be ignored during copy-out and must not be added to the
 
158
                        # deployment's deploy_files list.  Since these ignored files and
 
159
                        # directories are transparent to the user, they must be explicitly
 
160
                        # permitted via an "ignore list" in ~/.stdhomerc.  If these serious
 
161
                        # differences are not matched by the ignore list, an error should be
 
162
                        # show (which will require a separate "check" walk of the repo, as
 
163
                        # is done in copy_out).
154
164
                        else:
155
 
                                self.changed.append( "%s (now %s)" % (
156
 
                                        rel_file, self.name_of_type( src_type ) ) )
 
165
                                self.changed.append( "%s (%s => %s)" % ( rel_file,
 
166
                                        dst.get_type_name(). src.get_type_name() ) )
157
167
 
158
168
                # can not recurse on a non-directory
159
169
                return False