Преглед на файлове

Merge branch 'fix-peerstats' of git://github.com/interfect/cjdns into crashey

Caleb James DeLisle преди 6 години
родител
ревизия
9c3cba21d3
променени са 2 файла, в които са добавени 21 реда и са изтрити 12 реда
  1. 1 1
      contrib/python/cjdnsadmin/adminTools.py
  2. 20 11
      contrib/python/cjdnsadmin/cjdnsadmin.py

+ 1 - 1
contrib/python/cjdnsadmin/adminTools.py

@@ -102,7 +102,7 @@ def peerStats(cjdns,up=False,verbose=False,human_readable=False):
 
     i = 0;
     while True:
-        ps = cjdns.InterfaceController_peerStats(i);
+        ps = cjdns.InterfaceController_peerStats(page=i);
         peers = ps['peers']
         for p in peers:
             p.update(parseAddr(p['addr']))

+ 20 - 11
contrib/python/cjdnsadmin/cjdnsadmin.py

@@ -173,32 +173,38 @@ def _getMessage(session, txid):
                 print "message with no txid: " + str(next)
 
 
-def _functionFabric(func_name, argList, oargs, password):
+def _functionFabric(func_name, argList, oargs, oargNames, password):
     """Function fabric for Session class"""
 
     def functionHandler(self, *args, **kwargs):
         call_args = {}
-
+        
         pos = 0
         for value in args:
             if (pos < len(argList)):
                 call_args[argList[pos]] = value
                 pos += 1
+            elif (pos < len(argList) + len(oargNames)):
+                call_args[oargNames[pos - len(argList)]] = value
+            else:
+                print("warning: extraneous argument passed to function",func_name,value)
 
         for (key, value) in kwargs.items():
-            if not key in oargs:
-                # probably a positional argument, given a keyword name
-                # that happens in python
-                if pos < len(argList) and argList[pos] == key:
+            if key not in oargs:
+                if key in argList:
+                    # this is a positional argument, given a keyword name
+                    # that happens in python.
+                    # TODO: we can't handle this along with unnamed positional args.
+                    pos = argList.index(key)
                     call_args[argList[pos]] = value
-                    pos += 1
                     continue
                 else:
                     print("warning: not an argument to this function",func_name,key)
                     print(oargs)
-            # TODO: check oargs[key] type matches value
-            # warn, if doesn't
-            call_args[key] = value
+            else:
+                # TODO: check oargs[key] type matches value
+                # warn, if doesn't
+                call_args[key] = value
 
         return _callFunc(self, func_name, password, call_args)
 
@@ -246,15 +252,18 @@ def connect(ipAddr, port, password):
         argList = []
         # optional args
         oargs = {}
+        # order of optional args for python-style calling
+        oargNames = []
         
         for (arg,atts) in items:
             if atts['required']:
                 argList.append(arg)
             else:
                 oargs[arg] = atts['type']
+                oargNames.append(arg)
 
         setattr(Session, i, _functionFabric(
-            i, argList, oargs, password))
+            i, argList, oargs, oargNames, password))
 
         funcArgs[i] = argList
         funcOargs[i] = oargs