updated coresendmsg and core-manage to be 2/3 compliant
This commit is contained in:
parent
6c861a6ff8
commit
f78736ebfd
2 changed files with 31 additions and 31 deletions
|
@ -119,13 +119,13 @@ class FileUpdater(object):
|
|||
search = "emane_models ="
|
||||
elif target == "nodetype":
|
||||
if self.options.userpath is None:
|
||||
raise ValueError, "missing user path"
|
||||
raise ValueError("missing user path")
|
||||
filename = os.path.join(self.options.userpath, "nodes.conf")
|
||||
search = self.data
|
||||
else:
|
||||
raise ValueError, "unknown target"
|
||||
raise ValueError("unknown target")
|
||||
if not os.path.exists(filename):
|
||||
raise ValueError, "file %s does not exist" % filename
|
||||
raise ValueError("file %s does not exist" % filename)
|
||||
return search, filename
|
||||
|
||||
def update_file(self, fn=None):
|
||||
|
@ -236,7 +236,7 @@ def main():
|
|||
try:
|
||||
up = FileUpdater(action, target, data, options)
|
||||
r = up.process()
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
sys.stderr.write("Exception: %s\n" % e)
|
||||
sys.exit(1)
|
||||
if not r:
|
||||
|
|
|
@ -19,9 +19,9 @@ def print_available_tlvs(t, tlv_class):
|
|||
"""
|
||||
Print a TLV list.
|
||||
"""
|
||||
print "TLVs available for %s message:" % t
|
||||
print("TLVs available for %s message:" % t)
|
||||
for tlv in sorted([tlv for tlv in tlv_class.tlv_type_map], key=lambda x: x.name):
|
||||
print "%s:%s" % (tlv.value, tlv.name)
|
||||
print("%s:%s" % (tlv.value, tlv.name))
|
||||
|
||||
|
||||
def print_examples(name):
|
||||
|
@ -52,9 +52,9 @@ def print_examples(name):
|
|||
"srcname=\"./test.log\"",
|
||||
"move a test.log file from host to node 2"),
|
||||
]
|
||||
print "Example %s invocations:" % name
|
||||
print("Example %s invocations:" % name)
|
||||
for cmd, descr in examples:
|
||||
print " %s %s\n\t\t%s" % (name, cmd, descr)
|
||||
print(" %s %s\n\t\t%s" % (name, cmd, descr))
|
||||
|
||||
|
||||
def receive_message(sock):
|
||||
|
@ -68,7 +68,7 @@ def receive_message(sock):
|
|||
data = sock.recv(4096)
|
||||
msghdr = data[:coreapi.CoreMessage.header_len]
|
||||
except KeyboardInterrupt:
|
||||
print "CTRL+C pressed"
|
||||
print("CTRL+C pressed")
|
||||
sys.exit(1)
|
||||
|
||||
if len(msghdr) == 0:
|
||||
|
@ -84,11 +84,11 @@ def receive_message(sock):
|
|||
except KeyError:
|
||||
msg = coreapi.CoreMessage(msgflags, msghdr, msgdata)
|
||||
msg.message_type = msgtype
|
||||
print "unimplemented CORE message type: %s" % msg.type_str()
|
||||
print("unimplemented CORE message type: %s" % msg.type_str())
|
||||
return msg
|
||||
if len(data) > msglen + coreapi.CoreMessage.header_len:
|
||||
print "received a message of type %d, dropping %d bytes of extra data" \
|
||||
% (msgtype, len(data) - (msglen + coreapi.CoreMessage.header_len))
|
||||
print("received a message of type %d, dropping %d bytes of extra data" \
|
||||
% (msgtype, len(data) - (msglen + coreapi.CoreMessage.header_len)))
|
||||
return msgcls(msgflags, msghdr, msgdata)
|
||||
|
||||
|
||||
|
@ -103,15 +103,15 @@ def connect_to_session(sock, requested):
|
|||
smsg = coreapi.CoreSessionMessage.pack(flags, tlvdata)
|
||||
sock.sendall(smsg)
|
||||
|
||||
print "waiting for session list..."
|
||||
print("waiting for session list...")
|
||||
smsgreply = receive_message(sock)
|
||||
if smsgreply is None:
|
||||
print "disconnected"
|
||||
print("disconnected")
|
||||
return False
|
||||
|
||||
sessstr = smsgreply.get_tlv(SessionTlvs.NUMBER.value)
|
||||
if sessstr is None:
|
||||
print "missing session numbers"
|
||||
print("missing session numbers")
|
||||
return False
|
||||
|
||||
# join the first session (that is not our own connection)
|
||||
|
@ -119,7 +119,7 @@ def connect_to_session(sock, requested):
|
|||
sessions = sessstr.split("|")
|
||||
sessions.remove(str(localport))
|
||||
if len(sessions) == 0:
|
||||
print "no sessions to join"
|
||||
print("no sessions to join")
|
||||
return False
|
||||
|
||||
if not requested:
|
||||
|
@ -127,10 +127,10 @@ def connect_to_session(sock, requested):
|
|||
elif requested in sessions:
|
||||
session = requested
|
||||
else:
|
||||
print "requested session not found!"
|
||||
print("requested session not found!")
|
||||
return False
|
||||
|
||||
print "joining session: %s" % session
|
||||
print("joining session: %s" % session)
|
||||
tlvdata = coreapi.CoreSessionTlv.pack(SessionTlvs.NUMBER.value, session)
|
||||
flags = MessageFlags.ADD.value
|
||||
smsg = coreapi.CoreSessionMessage.pack(flags, tlvdata)
|
||||
|
@ -142,12 +142,12 @@ def receive_response(sock, opt):
|
|||
"""
|
||||
Receive and print a CORE message from the given socket.
|
||||
"""
|
||||
print "waiting for response..."
|
||||
print("waiting for response...")
|
||||
msg = receive_message(sock)
|
||||
if msg is None:
|
||||
print "disconnected from %s:%s" % (opt.address, opt.port)
|
||||
print("disconnected from %s:%s" % (opt.address, opt.port))
|
||||
sys.exit(0)
|
||||
print "received message:", msg
|
||||
print("received message: %s" % msg)
|
||||
|
||||
|
||||
def main():
|
||||
|
@ -217,7 +217,7 @@ def main():
|
|||
|
||||
# build a message consisting of TLVs from "type=value" arguments
|
||||
flagstr = ""
|
||||
tlvdata = ""
|
||||
tlvdata = b""
|
||||
for a in args:
|
||||
typevalue = a.split("=")
|
||||
if len(typevalue) < 2:
|
||||
|
@ -255,11 +255,11 @@ def main():
|
|||
try:
|
||||
sock.connect((opt.address, opt.port))
|
||||
except Exception as e:
|
||||
print "Error connecting to %s:%s:\n\t%s" % (opt.address, opt.port, e)
|
||||
print("Error connecting to %s:%s:\n\t%s" % (opt.address, opt.port, e))
|
||||
sys.exit(1)
|
||||
|
||||
if not connect_to_session(sock, opt.session):
|
||||
print "warning: continuing without joining a session!"
|
||||
print("warning: continuing without joining a session!")
|
||||
|
||||
sock.sendall(msg)
|
||||
if opt.listen:
|
||||
|
|
Loading…
Add table
Reference in a new issue