mirror of https://gerrit.osmocom.org/libusrp
migrate to python3
Let's move to python3, it's 2020 and the conversion seemed actually rather trivial (famous last words). Change-Id: Ib1604b36c32630e1360e06567cbd5f63a78df547
This commit is contained in:
parent
cdc0ed783c
commit
d40ef8f001
|
@ -29,11 +29,7 @@ BuildRequires: gcc-c++
|
||||||
BuildRequires: libtool
|
BuildRequires: libtool
|
||||||
BuildRequires: pkgconfig
|
BuildRequires: pkgconfig
|
||||||
BuildRequires: sdcc
|
BuildRequires: sdcc
|
||||||
%if 0%{?suse_version} < 1320
|
BuildRequires: python3
|
||||||
BuildRequires: python
|
|
||||||
%else
|
|
||||||
BuildRequires: python2
|
|
||||||
%endif
|
|
||||||
BuildRequires: pkgconfig(libusb-1.0)
|
BuildRequires: pkgconfig(libusb-1.0)
|
||||||
%if 0%{?suse_version} > 1325
|
%if 0%{?suse_version} > 1325
|
||||||
BuildRequires: libboost_date_time-devel
|
BuildRequires: libboost_date_time-devel
|
||||||
|
|
|
@ -9,7 +9,7 @@ Build-Depends: debhelper (>=9),
|
||||||
doxygen,
|
doxygen,
|
||||||
libtool,
|
libtool,
|
||||||
pkg-config,
|
pkg-config,
|
||||||
python,
|
python3,
|
||||||
sdcc,
|
sdcc,
|
||||||
libusb-1.0-0-dev,
|
libusb-1.0-0-dev,
|
||||||
libboost-all-dev
|
libboost-all-dev
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#!/usr/bin/env python2
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import os, os.path
|
import os, os.path
|
||||||
import re
|
import re
|
||||||
|
@ -8,7 +8,7 @@ import sys
|
||||||
# set srcdir to the directory that contains Makefile.am
|
# set srcdir to the directory that contains Makefile.am
|
||||||
try:
|
try:
|
||||||
srcdir = os.environ['srcdir']
|
srcdir = os.environ['srcdir']
|
||||||
except KeyError, e:
|
except KeyError as e:
|
||||||
srcdir = "."
|
srcdir = "."
|
||||||
srcdir = srcdir + '/'
|
srcdir = srcdir + '/'
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#!/usr/bin/env python2
|
#!/usr/bin/env python3
|
||||||
#
|
#
|
||||||
# Copyright 2004,2006 Free Software Foundation, Inc.
|
# Copyright 2004,2006 Free Software Foundation, Inc.
|
||||||
#
|
#
|
||||||
|
@ -24,6 +24,7 @@ import re
|
||||||
import sys
|
import sys
|
||||||
import os, os.path
|
import os, os.path
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
from functools import reduce
|
||||||
|
|
||||||
# USB Vendor and Product ID's
|
# USB Vendor and Product ID's
|
||||||
|
|
||||||
|
@ -33,7 +34,7 @@ PID = 0x0002 # Universal Software Radio Peripheral
|
||||||
|
|
||||||
def hex_to_bytes (s):
|
def hex_to_bytes (s):
|
||||||
if len (s) & 0x1:
|
if len (s) & 0x1:
|
||||||
raise ValueError, "Length must be even"
|
raise ValueError("Length must be even")
|
||||||
r = []
|
r = []
|
||||||
for i in range (0, len(s), 2):
|
for i in range (0, len(s), 2):
|
||||||
r.append (int (s[i:i+2], 16))
|
r.append (int (s[i:i+2], 16))
|
||||||
|
@ -59,17 +60,17 @@ class ihx_file (object):
|
||||||
for line in file:
|
for line in file:
|
||||||
line = line.strip().upper ()
|
line = line.strip().upper ()
|
||||||
if not self.pat.match (line):
|
if not self.pat.match (line):
|
||||||
raise ValueError, "Invalid hex record format"
|
raise ValueError("Invalid hex record format")
|
||||||
bytes = hex_to_bytes (line[1:])
|
bytes = hex_to_bytes (line[1:])
|
||||||
sum = reduce (lambda x, y: x + y, bytes, 0) % 256
|
sum = reduce (lambda x, y: x + y, bytes, 0) % 256
|
||||||
if sum != 0:
|
if sum != 0:
|
||||||
raise ValueError, "Bad hex checksum"
|
raise ValueError("Bad hex checksum")
|
||||||
lenx = bytes[0]
|
lenx = bytes[0]
|
||||||
addr = (bytes[1] << 8) + bytes[2]
|
addr = (bytes[1] << 8) + bytes[2]
|
||||||
type = bytes[3]
|
type = bytes[3]
|
||||||
data = bytes[4:-1]
|
data = bytes[4:-1]
|
||||||
if lenx != len (data):
|
if lenx != len (data):
|
||||||
raise ValueError, "Invalid hex record (bad length)"
|
raise ValueError("Invalid hex record (bad length)")
|
||||||
if type != 0:
|
if type != 0:
|
||||||
break;
|
break;
|
||||||
r.append (ihx_rec (addr, type, data))
|
r.append (ihx_rec (addr, type, data))
|
||||||
|
@ -83,7 +84,7 @@ def get_code (filename):
|
||||||
f = open (filename, 'r')
|
f = open (filename, 'r')
|
||||||
ifx = ihx_file ()
|
ifx = ihx_file ()
|
||||||
r = ifx.read (f)
|
r = ifx.read (f)
|
||||||
r.sort (lambda a,b: a.addr - b.addr)
|
r.sort (key=lambda a: a.addr)
|
||||||
code_start = r[0].addr
|
code_start = r[0].addr
|
||||||
code_end = r[-1].addr + len (r[-1].data)
|
code_end = r[-1].addr + len (r[-1].data)
|
||||||
code_len = code_end - code_start
|
code_len = code_end - code_start
|
||||||
|
@ -153,7 +154,7 @@ def build_shell_script (out, ihx_filename, rev, prefix):
|
||||||
i2c_addr = 0x50
|
i2c_addr = 0x50
|
||||||
rom_addr = 0x00
|
rom_addr = 0x00
|
||||||
|
|
||||||
hex_image = map (lambda x : "%02x" % (x,), image)
|
hex_image = ["%02x" % (x,) for x in image]
|
||||||
|
|
||||||
while (len (hex_image) > 0):
|
while (len (hex_image) > 0):
|
||||||
l = min (len (hex_image), 16)
|
l = min (len (hex_image), 16)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python3
|
||||||
# -*- Python -*-
|
# -*- Python -*-
|
||||||
#
|
#
|
||||||
# Copyright 2003 Free Software Foundation, Inc.
|
# Copyright 2003 Free Software Foundation, Inc.
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python3
|
||||||
# -*- Python -*-
|
# -*- Python -*-
|
||||||
#
|
#
|
||||||
# Copyright 2003 Free Software Foundation, Inc.
|
# Copyright 2003 Free Software Foundation, Inc.
|
||||||
|
|
Loading…
Reference in New Issue