5
5
__author__ = """David Malcolm <dmalcolm@redhat.com>"""
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.
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.
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
21
FIXME: try to ensure uniqueness
22
FIXME: need some heuristics to get 'good' searches, whatever
31
for (predicate, isRecursive) in self.__list:
32
result += "/(%s,%s)"%(predicate.describeSearchResult(), isRecursive)
35
# We need equality to work so that dicts of these work:
36
def __eq__(self, other):
37
# print "eq: self:%s"%self
38
# print " other:%s"%other
39
if len(self.__list) != len(other.__list):
40
# print "nonequal length"
43
for i in range(len(self.__list)):
44
if self.__list[i]!=other.__list[i]:
49
def append(self, predicate, isRecursive):
51
self.__list.append((predicate, isRecursive))
54
return iter(self.__list)
57
return len(self.__list)
59
def makeScriptMethodCall(self):
61
Used by the recording system.
63
Generate the Python source code that will carry out this search.
66
for (predicate, isRecursive) in self.__list:
68
# print self.generateVariableName(predicate)
69
result += "." + predicate.makeScriptMethodCall(isRecursive)
72
def getRelativePath(self, other):
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
79
for i in range(len(self.__list)):
80
if self.__list[i]!=other.__list[i]:
83
# Slice from this point to the end:
85
result.__list = other.__list[i+1:]
88
print "...................."
92
print "relative path %s"%result
93
print "...................."
99
def getPrefix(self, n):
101
Get the first n components of this instance as a new instance
103
result = SearchPath()
105
result.__list.append(self.__list[i])
108
def getPredicate(self, i):
109
(predicate, isRecursive) = self.__list[i]
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.
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.
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
21
FIXME: try to ensure uniqueness
22
FIXME: need some heuristics to get 'good' searches, whatever
31
for (predicate, isRecursive) in self.__list:
32
result += "/(%s,%s)"%(predicate.describeSearchResult(), isRecursive)
35
# We need equality to work so that dicts of these work:
36
def __eq__(self, other):
37
# print "eq: self:%s"%self
38
# print " other:%s"%other
39
if len(self.__list) != len(other.__list):
40
# print "nonequal length"
43
for i in range(len(self.__list)):
44
if self.__list[i]!=other.__list[i]:
49
def append(self, predicate, isRecursive):
51
self.__list.append((predicate, isRecursive))
54
return iter(self.__list)
57
return len(self.__list)
59
def makeScriptMethodCall(self):
61
Used by the recording system.
63
Generate the Python source code that will carry out this search.
66
for (predicate, isRecursive) in self.__list:
68
# print self.generateVariableName(predicate)
69
result += "." + predicate.makeScriptMethodCall(isRecursive)
72
def getRelativePath(self, other):
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
79
for i in range(len(self.__list)):
80
if self.__list[i]!=other.__list[i]:
83
# Slice from this point to the end:
85
result.__list = other.__list[i+1:]
88
print "...................."
92
print "relative path %s"%result
93
print "...................."
99
def getPrefix(self, n):
101
Get the first n components of this instance as a new instance
103
result = SearchPath()
105
result.__list.append(self.__list[i])
108
def getPredicate(self, i):
109
(predicate, isRecursive) = self.__list[i]