1
2 """
3 Author: David Malcolm <dmalcolm@redhat.com>
4 """
5 __author__ = """David Malcolm <dmalcolm@redhat.com>"""
6
7
9
10 """
11 Class used by the recording framework (and for more verbose script
12 logging) for identifying nodes in a persistent way, independent of the
13 style of script being written.
14
15 Implemented as a list of (predicate, isRecursive) pairs, giving the
16 'best' way to find the Accessible wrapped by a Node, starting at the
17 root and applying each search in turn.
18
19 This is somewhat analagous to an absolute path in a filesystem, except
20 that some of searches may be recursive, rather than just searching
21 direct children.
22
23 FIXME: try to ensure uniqueness
24 FIXME: need some heuristics to get 'good' searches, whatever
25 that means
26 """
27
30
37
38
40
41
42 if len(self.__list) != len(other.__list):
43
44 return False
45 else:
46 for i in range(len(self.__list)):
47 if self.__list[i] != other.__list[i]:
48 return False
49
50 return True
51
52 - def append(self, predicate, isRecursive):
55
57 return iter(self.__list)
58
60 return len(self.__list)
61
63 """
64 Used by the recording system.
65
66 Generate the Python source code that will carry out this search.
67 """
68 result = ""
69 for (predicate, isRecursive) in self.__list:
70
71
72 result += "." + predicate.makeScriptMethodCall(isRecursive)
73 return result
74
76 """
77 Given another SearchPath instance, if the other is 'below' this
78 one, return a SearchPath that describes how to reach it relative
79 to this one (a copy of the second part of the list). Otherwise
80 return None.
81 """
82 for i in range(len(self.__list)):
83 if self.__list[i] != other.__list[i]:
84 break
85 if i > 0:
86
87 result = SearchPath()
88 result.__list = other.__list[i + 1:]
89
90 if False:
91 print("....................")
92 print("from %s" % self)
93 print("to %s" % other)
94 print("i=%s" % i)
95 print("relative path %s" % result)
96 print("....................")
97
98 return result
99 else:
100 return None
101
103 """
104 Get the first n components of this instance as a new instance
105 """
106 result = SearchPath()
107 for i in range(n):
108 result.__list.append(self.__list[i])
109 return result
110
114