/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: 2016-02-28 17:51:29 UTC
  • Revision ID: tim@ed.am-20160228175129-ea341cedv8g3s63m
fixed display of bzr output

Show diffs side-by-side

added added

removed removed

21
21
 
22
22
import filecmp, os, shutil
23
23
from walker import Walker
24
 
from stdhome import the
25
 
from stdhome import util
 
24
import stdhome.the as the
26
25
 
27
26
 
28
27
class CopyBaseWalker( Walker ):
29
28
        """The copy-base walker traverses a walklist ruthlessly mirroring src to dst.
30
29
        It is designed to be the base class of both the copy-in and copy-out walker,
31
30
        both of which are specialisations of this purpose.  See them for more
32
 
        information.  The report method, which can be overridden in derived classes,
33
 
        takes, in addition to the relative filename, a source file type, an
34
 
        operation, and a destination file type.  Valid file types are f (file), l
35
 
        (symlink), d (directory) and _ (non-existant).  Valid operations are *
36
 
        (modify), = (skip: same), @ (skip: symlink substitute) and # (skip:
37
 
        ignored).
38
 
 
 
31
        information.  The print_op method, derived in those classes, takes, in
 
32
        addition to the relative filename, a source file type, an operation, and a
 
33
        sestination file type.  Valid file types are f (file), l (symlink), d
 
34
        (directory) and _ (non-existant).  Valid operations are * (modify), = (skip:
 
35
        same), @ (skip: symlink substitute) and # (skip: ignored).
39
36
        """
40
37
 
41
38
 
43
40
                self.check_src_symlinks = False
44
41
                self.check_dst_symlinks = False
45
42
                self.check_dst_ignores = False
46
 
                self.report = False
47
 
 
48
 
 
49
 
        def print_op( self, rel_file, src, op, dst ):
50
 
 
51
 
                # report changes
52
 
                if self.report and op == '*':
53
 
                        if dst == '_':
54
 
                                print " N  %s" % ( rel_file )
55
 
                        elif src == '_':
56
 
                                print " D  %s" % ( rel_file )
57
 
                        elif src == dst:
58
 
                                print " M  %s" % ( rel_file )
59
 
                        else:
60
 
                                print " K  %s" % ( rel_file )
61
43
 
62
44
 
63
45
        def process( self, rel_file, src, dst ):
70
52
                # src entity is directory
71
53
                if src.type == 'd':
72
54
 
73
 
                        # if dst entity doesn't exist, create it (and recurse)
 
55
                        # if dst entity doesn't exist, create directory (no need to recurse,
 
56
                        # since we're copying the whole directory)
74
57
                        if dst.type == '_':
75
58
                                self.print_op( rel_file, 'd', '*', '_' )
76
 
                                os.mkdir( dst.file )
77
 
                                shutil.copystat( src.file, dst.file )
78
 
                                return True
 
59
                                shutil.copytree( src.file, dst.file, True )
79
60
 
80
61
                        # if dst entity is a directory, copy permissions, as required (and
81
62
                        # recurse)
82
63
                        elif dst.type == 'd':
83
 
                                if os.stat( src.file ).st_mode != os.stat( dst.file ).st_mode:
84
 
                                        self.print_op( rel_file, 'd', '*', 'd' )
85
 
                                        shutil.copystat( src.file, dst.file )
86
 
                                else:
87
 
                                        self.print_op( rel_file, 'd', '=', 'd' )
 
64
                                # TODO: should check permission and only do as necessary
 
65
                                self.print_op( rel_file, 'd', '*', 'd' )
 
66
                                shutil.copystat( src.file, dst.file )
88
67
                                return True
89
68
 
90
69
                        # if dst entity is a symlink to a directory, and this is an