/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-08 00:47:23 UTC
  • Revision ID: tim@ed.am-20140308004723-hkl3s2hobsblf72o
added diff command; moved all command to commands subdir; made stage-revert
handle ongoing deployment automatically (now that initial revno is known); made
verbose level incremental; detect obstructing conflicts in ConflictWalker;
handle files deleted from repo during copy-out (update)

Show diffs side-by-side

added added

removed removed

1
 
# copy_out_walker.py
 
1
# copy_out.py
2
2
#
3
3
# Copyright (C) 2013 to 2014 Tim Marston <tim@edm.am>
4
4
#
39
39
 
40
40
        def __init__( self, updated_files = None ):
41
41
                self.src_dir = the.repo.full_dir
42
 
                self.dst_dir = the.full_fsdir
 
42
                self.dst_dir = the.full_home_dir
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
 
52
52
                        # if entity doesn't exist in home dir, create directory (no need to
53
53
                        # recurse, since we're copying the whole directory)
54
54
                        if dst_type == '_':
55
 
                                if the.verbose: print "  _<d " + rel_file
 
55
                                if the.verbose > 1: print "  _<d " + rel_file
56
56
                                os.mkdir( dst_file )
57
57
                                shutil.copystat( src_file, dst_file )
58
58
                                return False
61
61
                        # directory (no need to recurse, since we're copying the whole
62
62
                        # directory)
63
63
                        elif dst_type == 'f' or dst_type == 'l':
64
 
                                if the.verbose: print "  %s<d %s" % ( dst_type, rel_file )
 
64
                                if the.verbose > 1: print "  %s<d %s" % ( dst_type, rel_file )
65
65
                                os.unlink( dst_file )
66
66
                                os.mkdir( dst_file )
67
67
                                shutil.copystat( src_file, dst_file )
71
71
                        # required (and recurse)
72
72
                        elif dst_type == 'd':
73
73
                                # TODO: should check permission and only do as necessary
74
 
                                if the.verbose: print "  d<d " + rel_file
 
74
                                if the.verbose > 1: print "  d<d " + rel_file
75
75
                                shutil.copystat( src_file, dst_file )
76
76
                                return True
77
77
 
83
83
 
84
84
                        # if entity doesn't exist in home dir, copy file
85
85
                        if dst_type == '_':
86
 
                                if the.verbose: print "  _<f " + rel_file
 
86
                                if the.verbose > 1: print "  _<f " + rel_file
87
87
                                shutil.copy( src_file, dst_file )
88
88
                                shutil.copystat( src_file, dst_file )
89
89
 
90
90
                        # if entity is a symlink in home dir, replace it with file
91
91
                        elif dst_type == 'l':
92
 
                                if the.verbose: print "  l<f " + rel_file
 
92
                                if the.verbose > 1: print "  l<f " + rel_file
93
93
                                os.unlink( dst_file )
94
94
                                shutil.copy( src_file, dst_file )
95
95
                                shutil.copystat( src_file, dst_file )
97
97
                        # if entity is a file in home dir, replace it only if it differs
98
98
                        elif dst_type == 'f':
99
99
                                if not filecmp.cmp( src_file, dst_file ):
100
 
                                        if the.verbose: print "  f<f " + rel_file
 
100
                                        if the.verbose > 1: print "  f<f " + rel_file
101
101
                                        os.unlink( dst_file )
102
102
                                        shutil.copy( src_file, dst_file )
103
103
                                        shutil.copystat( src_file, dst_file )
104
104
                                else:
105
 
                                        if the.verbose: print "  f=f " + rel_file
 
105
                                        if the.verbose > 1: print "  f=f " + rel_file
106
106
 
107
107
                        # if entity is a directory in home dir, replace it with file
108
108
                        elif dst_type == 'd':
109
 
                                if the.verbose: print "  d<f " + rel_file
 
109
                                if the.verbose > 1: print "  d<f " + rel_file
110
110
                                shutil.rmtree( dst_file )
111
111
                                shutil.copy( src_file, dst_file )
112
112
                                shutil.copystat( src_file, dst_file )
119
119
 
120
120
                        # if entity doesn't exist in home dir, copy symlink
121
121
                        if dst_type == '_':
122
 
                                if the.verbose: print "  _<l " + rel_file
 
122
                                if the.verbose > 1: print "  _<l " + rel_file
123
123
                                os.symlink( os.readlink( src_file ), dst_file )
124
124
 
125
125
                        # if entity is a symlink in home dir, replace it only if it differs
126
126
                        elif dst_type == 'l':
127
127
                                if os.readlink( src_file ) != os.readlink( dst_file ):
128
 
                                        if the.verbose: print "  l<l " + rel_file
 
128
                                        if the.verbose > 1: print "  l<l " + rel_file
129
129
                                        os.unlink( dst_file )
130
130
                                        os.symlink( os.readlink( src_file ), dst_file )
131
131
                                else:
132
 
                                        if the.verbose: print "  l=l " + rel_file
 
132
                                        if the.verbose > 1: print "  l=l " + rel_file
133
133
 
134
134
                        # if entity is a file in home dir, replace it with file
135
135
                        elif dst_type == 'f':
136
 
                                if the.verbose: print "  f<l " + rel_file
 
136
                                if the.verbose > 1: print "  f<l " + rel_file
137
137
                                os.unlink( dst_file )
138
138
                                os.symlink( os.readlink( src_file ), dst_file )
139
139
 
140
140
                        # if entity is a directory in home dir, replace it with file
141
141
                        elif dst_type == 'd':
142
 
                                if the.verbose: print "  d<l " + rel_file
 
142
                                if the.verbose > 1: print "  d<l " + rel_file
143
143
                                shutil.rmtree( dst_file )
144
144
                                os.symlink( os.readlink( src_file ), dst_file )
145
145
 
146
146
                        else:
147
147
                                raise NotImplementedError()
148
148
 
149
 
                # TODO: handle files missing in repo -- we may or may not want to remove
150
 
                # them from home dir, depending on whether we wanted to delete them
151
 
                # remotely or whether we just wanted to remove them from version control
 
149
                # deleted file
 
150
                if src_type == '_':
 
151
 
 
152
                        # if entity doesn't exist in home dir, we're good
 
153
                        if dst_type == '_':
 
154
                                pass;
 
155
 
 
156
                        # if entity is a file or symlink in home dir, delete it
 
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 )
 
160
 
 
161
                        # if entity is a directory in home dir, delete it
 
162
                        elif dst_type == 'd':
 
163
                                if the.verbose > 1: print "  d<_ " + rel_file
 
164
                                shutil.rmtree( dst_file )
 
165
 
 
166
                        else:
 
167
                                raise NotImplementedError()
152
168
 
153
169
                # non-directories can not be recursed in to
154
170
                return False