chiark
/
gitweb
/
~mdw
/
tripe
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
6090fc4
)
peerdb/tripe-newpeers.in: Factor out calculating the parent-section list.
author
Mark Wooding
<mdw@distorted.org.uk>
Sun, 27 May 2018 01:20:47 +0000
(
02:20
+0100)
committer
Mark Wooding
<mdw@distorted.org.uk>
Thu, 14 Jun 2018 11:50:38 +0000
(12:50 +0100)
peerdb/tripe-newpeers.in
patch
|
blob
|
blame
|
history
diff --git
a/peerdb/tripe-newpeers.in
b/peerdb/tripe-newpeers.in
index 2287dabd13cc010631cb742bc172c7cf21438cc7..8b4d800c41f92acb01605845c53a1bb3a23a7dfb 100644
(file)
--- a/
peerdb/tripe-newpeers.in
+++ b/
peerdb/tripe-newpeers.in
@@
-199,6
+199,13
@@
class ConfigSection (object):
string)
return string
string)
return string
+ def _parents(me):
+ """Yield this section's parents."""
+ try: names = me._itemmap['@inherit']
+ except KeyError: return
+ for name in names.replace(',', ' ').split():
+ yield me._cp.section(name)
+
def _get(me, key, map = None, path = None):
"""
Low-level option-fetching method.
def _get(me, key, map = None, path = None):
"""
Low-level option-fetching method.
@@
-235,20
+242,13
@@
class ConfigSection (object):
except KeyError: pass
else: return v, path[:]
except KeyError: pass
else: return v, path[:]
- ## No, apparently, not. Find out our list of parents.
- try:
- parents = [me._cp.section(p) for p in
- me._itemmap['@inherit'].replace(',', ' ').split()]
- except KeyError:
- parents = []
-
## Initially we have no idea.
value = None
winner = None
## Go through our parents and ask them what they think.
map[me.name] = True, None
## Initially we have no idea.
value = None
winner = None
## Go through our parents and ask them what they think.
map[me.name] = True, None
- for p in
parents
:
+ for p in
me._parents()
:
## See whether we get an answer. If not, keep on going.
v, pp = p._get(key, map, path)
## See whether we get an answer. If not, keep on going.
v, pp = p._get(key, map, path)
@@
-293,18
+293,18
@@
class ConfigSection (object):
## Initialize for a depth-first walk of the inheritance graph.
d = {}
visited = {}
## Initialize for a depth-first walk of the inheritance graph.
d = {}
visited = {}
- stack = [me
.name
]
+ stack = [me]
## Visit nodes, collecting their keys. Don't believe the values:
## resolving inheritance is too hard to do like this.
while stack:
## Visit nodes, collecting their keys. Don't believe the values:
## resolving inheritance is too hard to do like this.
while stack:
- sec =
me._cp.section(stack.pop()
)
+ sec =
stack.pop(
)
if sec.name in visited: continue
visited[sec.name] = True
if sec.name in visited: continue
visited[sec.name] = True
+ stack += sec._parents()
- for key, value in sec._itemmap.iteritems():
- if key == '@inherit': stack += value.replace(',', ' ').split()
- else: d[key] = None
+ for key in sec._itemmap.iterkeys():
+ if key != '@inherit': d[key] = None
## And we're done.
return d.iterkeys()
## And we're done.
return d.iterkeys()