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