Skip to content
This repository has been archived by the owner on Apr 14, 2024. It is now read-only.

make python-ostinato python3 compliant (work in progress) #181

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions binding/core.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
from __future__ import absolute_import
from builtins import object
# Copyright (C) 2014 Srivats P.
#
#
# This file is part of "Ostinato"
#
#
# This is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>

import os
from rpc import OstinatoRpcChannel, OstinatoRpcController, RpcError
import protocols.protocol_pb2 as ost_pb
from __init__ import __version__
from .rpc import OstinatoRpcChannel, OstinatoRpcController, RpcError
from .protocols import protocol_pb2 as ost_pb
from .__init__ import __version__

class DroneProxy(object):

Expand Down Expand Up @@ -47,7 +49,7 @@ def connect(self):
ver.version = __version__
compat = self.checkVersion(ver)
if compat.result == ost_pb.VersionCompatibility.kIncompatible:
raise RpcError('incompatible version %s (%s)' %
raise RpcError('incompatible version %s (%s)' %
(ver.version, compat.notes))

def disconnect(self):
Expand Down
25 changes: 14 additions & 11 deletions binding/example.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
#! /usr/bin/env python

# standard modules
from __future__ import print_function
from __future__ import absolute_import
from builtins import input
import logging
import os
import sys
import time

# ostinato modules
# ostinato modules
# (user scripts using the installed package should prepend ostinato. i.e
# ostinato.core and ostinato.protocols)
from core import ost_pb, DroneProxy
from protocols.mac_pb2 import mac
from protocols.ip4_pb2 import ip4, Ip4
from .core import ost_pb, DroneProxy
from .protocols.mac_pb2 import mac
from .protocols.ip4_pb2 import ip4, Ip4

# initialize defaults
use_defaults = False
Expand Down Expand Up @@ -51,14 +54,14 @@
print('')

if not use_defaults:
s = raw_input('Drone\'s Hostname/IP [%s]: ' % (host_name))
s = input('Drone\'s Hostname/IP [%s]: ' % (host_name))
host_name = s or host_name

drone = DroneProxy(host_name)

try:
# connect to drone
log.info('connecting to drone(%s:%d)'
log.info('connecting to drone(%s:%d)'
% (drone.hostName(), drone.portNumber()))
drone.connect()

Expand All @@ -74,22 +77,22 @@
log.warning('drone has no ports!')
sys.exit(1)

# print port list and get tx/rx port id
# print port list and get tx/rx port id
print('Port List')
print('---------')
for port in port_config_list.port:
print('%d.%s (%s)' % (port.port_id.id, port.name, port.description))
# use a loopback port as default tx/rx port
# use a loopback port as default tx/rx port
if ('lo' in port.name or 'loopback' in port.description.lower()):
tx_port_number = port.port_id.id
rx_port_number = port.port_id.id

if not use_defaults:
p = raw_input('Tx Port Id [%d]: ' % (tx_port_number))
p = input('Tx Port Id [%d]: ' % (tx_port_number))
if p:
tx_port_number = int(p)

p = raw_input('Rx Port Id [%d]: ' % (rx_port_number))
p = input('Rx Port Id [%d]: ' % (rx_port_number))
if p:
rx_port_number = int(p)

Expand Down Expand Up @@ -165,7 +168,7 @@

#log.info('--> (tx_stats)' + tx_stats.__str__())
#log.info('--> (rx_stats)' + rx_stats.__str__())
log.info('tx pkts = %d, rx pkts = %d' %
log.info('tx pkts = %d, rx pkts = %d' %
(tx_stats.port_stats[0].tx_pkts, rx_stats.port_stats[0].rx_pkts))

# retrieve and dump received packets
Expand Down
18 changes: 10 additions & 8 deletions binding/rpc.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
from __future__ import print_function
from builtins import str
# Copyright (C) 2014 Srivats P.
#
#
# This file is part of "Ostinato"
#
#
# This is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>

Expand All @@ -21,7 +23,7 @@
import logging
import socket
import struct
import sys


class PeerClosedConnError(Exception):
def __init__(self, msg):
Expand Down Expand Up @@ -78,7 +80,7 @@ def CallMethod(self, method, controller, request, response_class, done):

error = ''
try:
self.log.info('invoking RPC %s(%s): %s', method.name,
self.log.info('invoking RPC %s(%s): %s', method.name,
type(request).__name__, response_class.__name__)
if not request.IsInitialized():
raise RpcError('missing required fields in request')
Expand Down Expand Up @@ -112,7 +114,7 @@ def CallMethod(self, method, controller, request, response_class, done):

# verify response method is same as the one requested
if method_index != method.index:
raise RpcMismatchError('RPC mismatch',
raise RpcMismatchError('RPC mismatch',
expected = method.index, received = method_index)

if msg_type == MSG_TYPE_RESPONSE:
Expand All @@ -122,7 +124,7 @@ def CallMethod(self, method, controller, request, response_class, done):
elif msg_type == MSG_TYPE_BLOB:
response = resp
elif msg_type == MSG_TYPE_ERROR:
raise RpcError(unicode(resp, 'utf-8'))
raise RpcError(str(resp, 'utf-8'))
else:
raise RpcError('unknown RPC msg type %d' % msg_type)

Expand Down
9 changes: 5 additions & 4 deletions binding/setup.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
#!/usr/bin/env python
# Copyright (C) 2014 Srivats P.
#
#
# This file is part of "Ostinato"
#
#
# This is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>

from __future__ import print_function
import json
import os
import shutil
Expand Down