[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[minion-cvs] Add first-show CLI to new list-servers; debug more; doc...
Update of /home/minion/cvsroot/src/minion/lib/mixminion
In directory moria.mit.edu:/tmp/cvs-serv25527/lib/mixminion
Modified Files:
ClientDirectory.py ClientMain.py Config.py
Log Message:
Add first-show CLI to new list-servers; debug more; docs needed.
Note: If you're running a pinger or any other program that uses output
from list-servers, you probably want to change your command to:
mixminion list-servers -c 1 -TT -F caps
to get the closest possible to the previous format.
Or update to parse the newer format; your call.
Index: ClientDirectory.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/ClientDirectory.py,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- ClientDirectory.py 7 Nov 2003 07:29:52 -0000 1.9
+++ ClientDirectory.py 7 Nov 2003 09:07:54 -0000 1.10
@@ -341,7 +341,6 @@
return n
def __rebuildTables(self):
-
"""Helper method. Reconstruct byNickname, byKeyID,
allServers, and byCapability from the internal start of
this object. """
@@ -371,36 +370,7 @@
continue
self.byNickname.setdefault(nn, []).append((info, where))
- def listServers(self):
- """Returns a linewise listing of the current servers and their caps.
- This will go away or get refactored in future versions once we
- have client-level modules.
- """
- lines = []
- nicknames = self.byNickname.keys()
- nicknames.sort()
- if not nicknames:
- return [ "No servers known" ]
- longestnamelen = max(map(len, nicknames))
- fmtlen = min(longestnamelen, 20)
- nnFormat = "%"+str(fmtlen)+"s:%s"
- for n in nicknames:
- nnreal = self.byNickname[n][0][0].getNickname()
- isGood = self.goodServerNicknames.get(n, 0)
- if isGood:
- status = ""
- else:
- status = " (not recommended)"
- lines.append(nnFormat%(nnreal,status))
- for info, where in self.byNickname[n]:
- caps = info.getCaps()
- va = formatDate(info['Server']['Valid-After'])
- vu = formatDate(info['Server']['Valid-Until'])
- line = " [%s to %s] %s"%(va,vu," ".join(caps))
- lines.append(line)
- return lines
-
- def listServers2(self, features, at=None, goodOnly=0):
+ def getFeatureMap(self, features, at=None, goodOnly=0):
"""DOCDOC
Returns a dict from nickname to (va,vu) to feature to value."""
result = {}
@@ -853,25 +823,31 @@
nicknames.sort()
lines = []
if not nicknames: return lines
+ maxnicklen = max([len(nn) for nn in nicknames])
+ nnformat = "%-"+str(maxnicklen)+"s"
for _, nickname in nicknames:
d = featureMap[nickname]
if not d: continue
items = d.items()
items.sort()
if cascade: lines.append("%s:"%nickname)
+ justified_nickname = nnformat%nickname
for (va,vu),fmap in items:
ftime = "%s to %s"%(formatDate(va),formatDate(vu))
- if cascade and showTime:
- lines.append(" %s:"%ftime)
- if cascade:
+ if cascade==1:
+ lines.append(" [%s] %s"%(ftime,
+ sep.join([fmap[f] for f in features])))
+ elif cascade==2:
+ if showTime:
+ lines.append(" [%s]"%ftime)
for f in features:
v = fmap[f]
lines.append(" %s:%s"%(f,v))
elif showTime:
- lines.append("%s:%s:%s" %(nickname,ftime,
+ lines.append("%s:%s:%s" %(justified_nickname,ftime,
sep.join([fmap[f] for f in features])))
else:
- lines.append("%s:%s" %(nickname,
+ lines.append("%s:%s" %(justified_nickname,
sep.join([fmap[f] for f in features])))
return lines
Index: ClientMain.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/ClientMain.py,v
retrieving revision 1.126
retrieving revision 1.127
diff -u -d -r1.126 -r1.127
--- ClientMain.py 7 Nov 2003 07:31:42 -0000 1.126
+++ ClientMain.py 7 Nov 2003 09:07:54 -0000 1.127
@@ -1180,6 +1180,8 @@
Force the client to download/not to download a
fresh directory.
+ DOCDOC Somebody needs to explain this. :)
+
EXAMPLES:
List all currently known servers.
%(cmd)s
@@ -1187,9 +1189,11 @@
def listServers(cmd, args):
"""[Entry point] Print info about """
- options, args = getopt.getopt(args, "hf:D:v",
+ options, args = getopt.getopt(args, "hf:D:vF:c:TVs:",
['help', 'config=', "download-directory=",
- 'verbose'])
+ 'verbose', 'feature=', 'cascade=',
+ 'with-time', "no-collapse", "valid",
+ "separator="])
try:
parser = CLIArgumentParser(options, wantConfig=1,
wantClientDirectory=1,
@@ -1198,18 +1202,73 @@
e.dump()
print _LIST_SERVERS_USAGE % {'cmd' : cmd}
sys.exit(1)
+ features = []
+ cascade = 0
+ showTime = 0
+ validOnly = 0
+ separator = "\t"
+ for opt,val in options:
+ if opt in ('-F', '--feature'):
+ features.append(val)
+ elif opt in ('-c', '--cascade'):
+ try:
+ cascade = int(val)
+ except ValueError:
+ raise UIError("%s requires an integer"%opt)
+ if not (0 <= cascade <= 2):
+ raise UIError("Cascade level must be between 0 and 2")
+ elif opt == ('-T'):
+ showTime += 1
+ elif opt == ('--with-time'):
+ showTime = 1
+ elif opt == ('--no-collapse'):
+ showTime = 2
+ elif opt in ('-V', '--valid'):
+ validOnly = 1
+ elif sep in ('-s', '--separator'):
+ separator = val
+
+ if not features:
+ if validOnly:
+ features = [ 'caps' ]
+ else:
+ features = [ 'caps', 'status' ]
parser.init()
directory = parser.directory
- #for line in directory.listServers():
- # print line
- features = ["caps", "status", "secure-configuration"]
- fm = directory.listServers2(features)
- #fm = mixminion.ClientDirectory.compressServerList(fm)
+ # Look up features in directory.
+ featureMap = directory.getFeatureMap(features,goodOnly=validOnly)
+
+ # If any servers are listed on the command line, restrict to those
+ # servers.
+ if args:
+ lcargs = [ arg.lower() for arg in args ]
+ lcfound = {}
+ restrictedMap = {}
+ for nn,v in featureMap.items():
+ if nn.lower() in lcargs:
+ restrictedMap[nn] = v
+ lcfound[nn.lower()] = 1
+ for arg in args:
+ if not lcfound.has_key(arg.lower()):
+ if validOnly:
+ raise UIError("No recommended descriptors found for %s"%
+ arg)
+ else:
+ raise UIError("No descriptors found for %s"%arg)
+ featureMap = restrictedMap
+
+ # Collapse consecutive server descriptors with matching features.
+ if showTime < 2:
+ featureMap = mixminion.ClientDirectory.compressServerList(
+ featureMap, ignoreGaps=(not showTime), terse=(not showTime))
+
+ # Now display the result.
for line in mixminion.ClientDirectory.formatFeatureMap(
- features,fm,1,cascade=1):
+ features,featureMap,showTime,cascade,separator):
print line
+
_UPDATE_SERVERS_USAGE = """\
Usage: %(cmd)s [options]
Index: Config.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/Config.py,v
retrieving revision 1.62
retrieving revision 1.63
diff -u -d -r1.62 -r1.63
--- Config.py 7 Nov 2003 07:03:28 -0000 1.62
+++ Config.py 7 Nov 2003 09:07:54 -0000 1.63
@@ -893,7 +893,7 @@
"""DOCDOC"""
assert sec not in ("+","-")
parseType = self._syntax[sec].get(name)[1]
- _, unparseFn = self.CODING_FNS[parseType]
+ _, unparseFn = self.CODING_FNS.get(parseType, (None,str))
try:
v = self[sec][name]
except KeyError: