mirror of
https://github.com/svpcom/wfb-ng.git
synced 2025-02-15 13:33:48 -04:00
Add support of python3.x
This commit is contained in:
parent
9b2d8df981
commit
8c6f66bec7
2
setup.py
2
setup.py
@ -1,12 +1,12 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
|
||||
import os
|
||||
from setuptools import setup, find_packages, command
|
||||
import distutils.command.bdist_rpm as orig
|
||||
import setuptools.command.bdist_rpm as orig2
|
||||
|
||||
|
||||
class bdist_rpm(orig.bdist_rpm):
|
||||
"""
|
||||
Override the default bdist_rpm behavior to do the following:
|
||||
|
@ -1,3 +1,3 @@
|
||||
[DEFAULT]
|
||||
Depends: python-twisted, libpcap-dev, libsodium-dev, python-pyroute2
|
||||
Depends: python-twisted, libpcap-dev, libsodium-dev, python-pyroute2, python-future, python-configparser
|
||||
Package: wifibroadcast
|
||||
|
@ -18,6 +18,15 @@
|
||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import absolute_import
|
||||
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
|
||||
from builtins import *
|
||||
import sys
|
||||
import curses
|
||||
import curses.textpad
|
||||
@ -33,7 +42,7 @@ from telemetry.conf import settings
|
||||
|
||||
|
||||
class AntennaStat(LineReceiver):
|
||||
delimiter = '\n'
|
||||
delimiter = b'\n'
|
||||
|
||||
def lineReceived(self, line):
|
||||
attrs = json.loads(line)
|
||||
@ -62,7 +71,7 @@ class AntennaStat(LineReceiver):
|
||||
x += len(msg)
|
||||
|
||||
if rssi_d:
|
||||
for i, (k, v) in enumerate(sorted(rssi_d.iteritems())):
|
||||
for i, (k, v) in enumerate(sorted(rssi_d.items())):
|
||||
pkt_s, rssi_min, rssi_avg, rssi_max = v
|
||||
self.factory.window.addstr(i + 4, 0, '%04x: %d pkt/s, rssi %d < %d < %d\n' % (int(k, 16), pkt_s, rssi_min, rssi_avg, rssi_max))
|
||||
else:
|
||||
@ -118,9 +127,9 @@ def init(stdscr, profile):
|
||||
|
||||
height, width = stdscr.getmaxyx()
|
||||
height -= 1
|
||||
w1h = height / 3
|
||||
w1h = height // 3
|
||||
w1w = width
|
||||
w2h = height / 3
|
||||
w2h = height // 3
|
||||
w2w = width
|
||||
w3h = height - w1h - w2h
|
||||
w3w = width
|
||||
@ -163,7 +172,7 @@ def main():
|
||||
stderr = sys.stderr
|
||||
|
||||
if len(sys.argv) != 2:
|
||||
print >> stderr, "Usage: %s <profile>" % (sys.argv[0],)
|
||||
print("Usage: %s <profile>" % (sys.argv[0],), file=stderr)
|
||||
sys.exit(1)
|
||||
|
||||
fd = tempfile.TemporaryFile()
|
||||
|
@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright (C) 2018 Vasily Evseenko <svpcom@p2ptech.org>
|
||||
# Copyright (C) 2018, 2019 Vasily Evseenko <svpcom@p2ptech.org>
|
||||
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
@ -18,6 +18,16 @@
|
||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
from __future__ import absolute_import
|
||||
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
|
||||
from builtins import *
|
||||
|
||||
from twisted.python import log
|
||||
from twisted.internet import reactor, defer, task
|
||||
from telemetry.conf import settings
|
||||
|
@ -1,6 +1,16 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import division
|
||||
from __future__ import absolute_import
|
||||
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
|
||||
from builtins import *
|
||||
|
||||
import os
|
||||
import sys
|
||||
from telemetry import config_parser
|
||||
@ -14,7 +24,7 @@ def _parse_config(telemetry_cfg=None):
|
||||
|
||||
try:
|
||||
settings, cfg_files = _parse_config()
|
||||
except Exception, v:
|
||||
print >>sys.stderr, 'ERROR: Unable to parse config: %s' % (v,)
|
||||
except Exception as v:
|
||||
print('ERROR: Unable to parse config: %s' % (v,), file=sys.stderr)
|
||||
_cfg_files = [ 'master.cfg', 'site.cfg' ]
|
||||
settings, cfg_files = _parse_config()
|
||||
|
@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright (C) 2018 Vasily Evseenko <svpcom@p2ptech.org>
|
||||
# Copyright (C) 2018, 2019 Vasily Evseenko <svpcom@p2ptech.org>
|
||||
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
@ -18,7 +18,18 @@
|
||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
|
||||
import ConfigParser
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
from __future__ import absolute_import
|
||||
from builtins import *
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
|
||||
from builtins import str
|
||||
from builtins import object
|
||||
|
||||
import configparser
|
||||
import ast
|
||||
import copy
|
||||
import glob
|
||||
@ -65,17 +76,17 @@ def parse_config(basedir, cfg_patterns, interpolate=True):
|
||||
used_files = []
|
||||
|
||||
for g in cfg_patterns:
|
||||
for f in (glob.glob(os.path.join(basedir, g)) if isinstance(g, basestring) else [g]):
|
||||
fd = open(f) if isinstance(f, basestring) else f
|
||||
for f in (glob.glob(os.path.join(basedir, g)) if isinstance(g, str) else [g]):
|
||||
fd = open(f) if isinstance(f, str) else f
|
||||
filename = getattr(fd, 'filename', str(fd))
|
||||
|
||||
try:
|
||||
fd.seek(0) # handle case when source config is fd
|
||||
config = ConfigParser.RawConfigParser()
|
||||
config = configparser.RawConfigParser()
|
||||
|
||||
try:
|
||||
config.readfp(fd, filename=filename)
|
||||
except Exception, v:
|
||||
except Exception as v:
|
||||
raise ConfigError(v)
|
||||
|
||||
used_files.append(filename)
|
||||
@ -87,7 +98,7 @@ def parse_config(basedir, cfg_patterns, interpolate=True):
|
||||
for item, value in config.items(section):
|
||||
try:
|
||||
value = ast.literal_eval(value)
|
||||
if interpolate and isinstance(value, basestring):
|
||||
if interpolate and isinstance(value, str):
|
||||
# Interpolate string using current settings
|
||||
value = value % settings
|
||||
except:
|
||||
@ -100,7 +111,7 @@ def parse_config(basedir, cfg_patterns, interpolate=True):
|
||||
s_name=str(section)
|
||||
setattr(settings, s_name, _s)
|
||||
finally:
|
||||
if isinstance(f, basestring):
|
||||
if isinstance(f, str):
|
||||
fd.close()
|
||||
|
||||
return settings, used_files
|
||||
|
@ -1,6 +1,14 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from __future__ import division
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import print_function
|
||||
from __future__ import absolute_import
|
||||
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
from builtins import *
|
||||
import sys
|
||||
import time
|
||||
import struct
|
||||
|
@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright (C) 2018 Vasily Evseenko <svpcom@p2ptech.org>
|
||||
# Copyright (C) 2018, 2019 Vasily Evseenko <svpcom@p2ptech.org>
|
||||
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
@ -18,7 +18,17 @@
|
||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
|
||||
import mavlink
|
||||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
|
||||
from builtins import *
|
||||
|
||||
from . import mavlink
|
||||
from twisted.python import log
|
||||
from twisted.internet import reactor, defer
|
||||
from twisted.internet.protocol import DatagramProtocol
|
||||
@ -52,7 +62,7 @@ class UDPProxyProtocol(DatagramProtocol):
|
||||
if not self.agg_queue_timer.called:
|
||||
self.agg_queue_timer.cancel()
|
||||
self.agg_queue_timer = None
|
||||
self._send_to_peer(''.join(self.agg_queue))
|
||||
self._send_to_peer(b''.join(self.agg_queue))
|
||||
self.agg_queue = []
|
||||
self.agg_queue_size = 0
|
||||
|
||||
@ -85,7 +95,7 @@ class UDPProxyProtocol(DatagramProtocol):
|
||||
self.agg_queue_timer.cancel()
|
||||
self.agg_queue_timer = None
|
||||
|
||||
self._send_to_peer(''.join(self.agg_queue))
|
||||
self._send_to_peer(b''.join(self.agg_queue))
|
||||
self.agg_queue = []
|
||||
self.agg_queue_size = 0
|
||||
|
||||
|
@ -18,6 +18,16 @@
|
||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
|
||||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
|
||||
from builtins import *
|
||||
|
||||
import sys
|
||||
import time
|
||||
import json
|
||||
@ -45,7 +55,8 @@ class ExecError(Exception):
|
||||
|
||||
|
||||
def call_and_check_rc(cmd, *args):
|
||||
def _check_rc((stdout, stderr, rc)):
|
||||
def _check_rc(_args):
|
||||
(stdout, stderr, rc) = _args
|
||||
if rc != 0:
|
||||
err = ExecError('RC %d: %s %s' % (rc, cmd, ' '.join(args)))
|
||||
err.stdout = stdout.strip()
|
||||
@ -87,7 +98,7 @@ class StatisticsProtocol(Protocol):
|
||||
self.factory.sessions.remove(self)
|
||||
|
||||
def send_stats(self, data):
|
||||
self.transport.write(json.dumps(data) + '\n')
|
||||
self.transport.write(json.dumps(data).encode('utf-8') + b'\n')
|
||||
|
||||
|
||||
class AntennaFactory(Factory):
|
||||
@ -110,13 +121,13 @@ class AntennaFactory(Factory):
|
||||
def select_tx_antenna(self, ant_rssi):
|
||||
wlan_rssi = {}
|
||||
for k, grp in groupby(sorted(((int(ant_id, 16) >> 8) & 0xff, rssi_avg) \
|
||||
for ant_id, (pkt_s, rssi_min, rssi_avg, rssi_max) in ant_rssi.iteritems()),
|
||||
for ant_id, (pkt_s, rssi_min, rssi_avg, rssi_max) in ant_rssi.items()),
|
||||
lambda x: x[0]):
|
||||
# Select max average rssi from all wlan's antennas
|
||||
wlan_rssi[k] = max(rssi for _, rssi in grp)
|
||||
|
||||
tx_max = 0
|
||||
for k, v in wlan_rssi.iteritems():
|
||||
for k, v in wlan_rssi.items():
|
||||
if k != tx_max and v > wlan_rssi[tx_max]:
|
||||
tx_max = k
|
||||
|
||||
@ -132,7 +143,7 @@ class AntennaFactory(Factory):
|
||||
mav_rssi = []
|
||||
flags = 0
|
||||
|
||||
for i, (k, v) in enumerate(sorted(ant_rssi.iteritems())):
|
||||
for i, (k, v) in enumerate(sorted(ant_rssi.items())):
|
||||
pkt_s, rssi_min, rssi_avg, rssi_max = v
|
||||
mav_rssi.append(rssi_avg)
|
||||
|
||||
@ -158,7 +169,7 @@ class AntennaFactory(Factory):
|
||||
|
||||
|
||||
class AntennaProtocol(LineReceiver):
|
||||
delimiter = '\n'
|
||||
delimiter = b'\n'
|
||||
|
||||
def __init__(self, antenna_f, rx_id):
|
||||
self.antenna_f = antenna_f
|
||||
@ -167,7 +178,7 @@ class AntennaProtocol(LineReceiver):
|
||||
self.count_all = None
|
||||
|
||||
def lineReceived(self, line):
|
||||
cols = line.strip().split('\t')
|
||||
cols = line.decode('utf-8').strip().split('\t')
|
||||
try:
|
||||
if len(cols) < 2:
|
||||
raise BadTelemetry()
|
||||
@ -183,7 +194,7 @@ class AntennaProtocol(LineReceiver):
|
||||
if len(cols) != 3:
|
||||
raise BadTelemetry()
|
||||
|
||||
p_all, p_dec_err, p_dec_ok, p_fec_rec, p_lost, p_bad = map(int, cols[2].split(':'))
|
||||
p_all, p_dec_err, p_dec_ok, p_fec_rec, p_lost, p_bad = list(int(i) for i in cols[2].split(':'))
|
||||
|
||||
if not self.count_all:
|
||||
self.count_all = (p_all, p_dec_ok, p_fec_rec, p_lost, p_dec_err, p_bad)
|
||||
@ -203,13 +214,13 @@ class AntennaProtocol(LineReceiver):
|
||||
|
||||
|
||||
class DbgProtocol(LineReceiver):
|
||||
delimiter = '\n'
|
||||
delimiter = b'\n'
|
||||
|
||||
def __init__(self, rx_id):
|
||||
self.rx_id = rx_id
|
||||
|
||||
def lineReceived(self, line):
|
||||
log.msg('%s: %s' % (self.rx_id, line))
|
||||
log.msg('%s: %s' % (self.rx_id, line.decode('utf-8')))
|
||||
|
||||
|
||||
class RXProtocol(ProcessProtocol):
|
||||
|
@ -1,6 +1,17 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
from __future__ import absolute_import
|
||||
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
|
||||
from builtins import *
|
||||
from builtins import range
|
||||
|
||||
import time
|
||||
from twisted.python import log
|
||||
from twisted.trial import unittest
|
||||
@ -50,7 +61,7 @@ class UDPProxyTestCase(unittest.TestCase):
|
||||
@defer.inlineCallbacks
|
||||
def test_proxy(self):
|
||||
addr = ('127.0.0.1', 14551)
|
||||
p = SendPacket('test', addr, 10)
|
||||
p = SendPacket(b'test', addr, 10)
|
||||
ep3 = reactor.listenUDP(9999, p)
|
||||
ep4 = reactor.listenUDP(14553, Echo())
|
||||
try:
|
||||
@ -58,7 +69,7 @@ class UDPProxyTestCase(unittest.TestCase):
|
||||
_data, _addr = yield p.df
|
||||
self.assertGreater(time.time() - ts, 1.0)
|
||||
self.assertEqual(_addr, addr)
|
||||
self.assertEqual(_data, 'test' * 10)
|
||||
self.assertEqual(_data, b'test' * 10)
|
||||
finally:
|
||||
ep4.stopListening()
|
||||
ep3.stopListening()
|
||||
@ -66,7 +77,7 @@ class UDPProxyTestCase(unittest.TestCase):
|
||||
@defer.inlineCallbacks
|
||||
def test_rssi_injection(self):
|
||||
addr = ('127.0.0.1', 14551)
|
||||
p = SendPacket('test', addr)
|
||||
p = SendPacket(b'test', addr)
|
||||
|
||||
ep3 = reactor.listenUDP(9999, p)
|
||||
yield df_sleep(0.1)
|
||||
@ -77,6 +88,6 @@ class UDPProxyTestCase(unittest.TestCase):
|
||||
_data, _addr = yield p.df
|
||||
self.assertLess(time.time() - ts, 1.0)
|
||||
self.assertEqual(_addr, addr)
|
||||
self.assertEqual(_data, '\xfd\t\x00\x00\x00\x03\xf2m\x00\x00\x02\x00\x03\x00\x01\x01d\x00\x04\xa8\xad')
|
||||
self.assertEqual(_data, b'\xfd\t\x00\x00\x00\x03\xf2m\x00\x00\x02\x00\x03\x00\x01\x01d\x00\x04\xa8\xad')
|
||||
finally:
|
||||
ep3.stopListening()
|
||||
|
@ -1,6 +1,15 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
from __future__ import absolute_import
|
||||
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
from builtins import *
|
||||
|
||||
import time
|
||||
from twisted.python import log
|
||||
from twisted.trial import unittest
|
||||
@ -26,5 +35,5 @@ class TUNTAPTestCase(unittest.TestCase):
|
||||
|
||||
def test_tuntap(self):
|
||||
# Test manually via "ping -I tuntest1 192.168.77.2" and "tcpdump -i tuntest2 -nn -p icmp"
|
||||
return df_sleep(0)
|
||||
return df_sleep(1)
|
||||
|
||||
|
@ -1,8 +1,35 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright (C) 2018, 2019 Vasily Evseenko <svpcom@p2ptech.org>
|
||||
|
||||
#
|
||||
# This program 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; version 3.
|
||||
#
|
||||
# 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, write to the Free Software Foundation, Inc.,
|
||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
|
||||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
|
||||
from builtins import *
|
||||
|
||||
import os
|
||||
import mavlink
|
||||
from . import mavlink
|
||||
import fcntl
|
||||
import struct
|
||||
|
||||
@ -20,7 +47,7 @@ class TUNTAPTransport(abstract.FileDescriptor):
|
||||
TUNSETIFF = 0x400454ca
|
||||
IFF_NO_PI = 0x1000
|
||||
|
||||
def __init__(self, reactor, protocol, name, addr, dev='/dev/net/tun', mtu=1400, mode=TUN):
|
||||
def __init__(self, reactor, protocol, name, addr, dev=b'/dev/net/tun', mtu=1400, mode=TUN):
|
||||
abstract.FileDescriptor.__init__(self, reactor)
|
||||
self.queue = deque()
|
||||
self.mtu = mtu
|
||||
@ -30,7 +57,7 @@ class TUNTAPTransport(abstract.FileDescriptor):
|
||||
try:
|
||||
# We don't need packet info
|
||||
mode |= self.IFF_NO_PI
|
||||
fcntl.ioctl(self.fd, self.TUNSETIFF, struct.pack('16sH', name, mode))
|
||||
fcntl.ioctl(self.fd, self.TUNSETIFF, struct.pack('16sH', bytes(name, 'ascii'), mode))
|
||||
with closing(IPRoute()) as ip:
|
||||
ifidx = ip.link_lookup(ifname=name)[0]
|
||||
_addr, _mask = addr.split('/')
|
||||
@ -96,8 +123,8 @@ class TUNTAPTransport(abstract.FileDescriptor):
|
||||
return len(self.queue) > 1000
|
||||
|
||||
def write(self, data):
|
||||
if isinstance(data, unicode): # no, really, I mean it
|
||||
raise TypeError("Data must not be unicode")
|
||||
if not isinstance(data, (bytes, type(None))): # no, really, I mean it
|
||||
raise TypeError("Only binary strings are supported")
|
||||
|
||||
if not self.connected or self._writeDisconnected:
|
||||
return
|
||||
@ -129,7 +156,7 @@ class TUNTAPProtocol(Protocol):
|
||||
|
||||
def send_keepalive(self):
|
||||
if self.peer is not None:
|
||||
self.peer.write('')
|
||||
self.peer.write(b'')
|
||||
|
||||
def dataReceived(self, data):
|
||||
self.lc.reset()
|
||||
|
Loading…
Reference in New Issue
Block a user