1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# conflict.py
#
# Copyright (C) 2013 to 2014 Tim Marston <tim@edm.am>
#
# This file is part of stdhome (hereafter referred to as "this program").
# See http://ed.am/dev/stdhome for more information.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import filecmp, os
from walker import Walker
import stdhome.the as the
class ConflictWalker( Walker ):
"""The conflict walker traverses the repo looking for "deployment conflicts"
(i.e., changes in the type of file). This is run prior to running the
copy-out walker and, as such, is given a list of files that were copied-in
and which is can, therefore, safely ignore. It can also be given a list of
files affected by the update (it will walk all repo files otherwise).
Walker source: repo
Walker destination: home dir
Walker traversing: repo
"""
def __init__( self, ignore_files, walk_files = None ):
self.src_dir = the.repo.full_dir
self.dst_dir = the.full_home_dir
self.walk_list = walk_files if walk_files is not None else \
self.generate_walk_list()
self.ignore_files = ignore_files
self.changed = list()
self.obstructed = list()
def process( self, rel_file, src, dst ):
# if entity is missing in home dir, it's ok to copy out (and there's no
# need to recurse)
if dst.type == '_': return False
# if entity was copied-in, it's ok to copy out
elif rel_file in self.ignore_files:
# we recurse only if this is a directory in the home dir, because if
# it isn't copying-out will replace whatever's in the home dir with
# the whole directory from the repo
return dst.type == 'd'
# entity has changed type?
elif src.get_type_name() != dst.get_type_name():
self.changed.append( "%s (%s => %s)" % (
rel_file, src.get_type_name(), dst.get_type_name() ) )
# if an entity has changed to/from a directory, we don't care about
# anything that directory does/did contain
return False
# entity is a file (that wasn't copyied-in)?
elif dst.type == 'f':
# only a problem if its content is different
if not filecmp.cmp( src.file, dst.file ):
self.obstructed.append( rel_file )
return False
# entity is a symlink (that wasn't copied-in)?
if dst.type == 'l':
# only a problem if the symlink is different
if os.readlink( src.file ) != os.readlink( dst.file ):
self.obstructed.append( rel_file )
return False
# nothing to see here
return True
|