Change in gr-gsm[master]: Various python3 related changes

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

ptrkrysik gerrit-no-reply at lists.osmocom.org
Mon May 3 10:24:38 UTC 2021


Hello vvvelichkov,

I'd like you to do a code review. Please visit

    https://gerrit.osmocom.org/c/gr-gsm/+/24063

to review the following change.


Change subject: Various python3 related changes
......................................................................

Various python3 related changes

- Use relative import for grgsm's modules
- Convert map to list
- Remove the hier_block.py workaround as as gnuradio 3.7 is no longer
  supported in this branch

Change-Id: I5ca8fd340823996e8c444aaf18ddacd85c92ab1c
---
M apps/grgsm_decode
M apps/grgsm_scanner
M python/__init__.py
M python/demapping/gsm_bcch_ccch_demapper.py
M python/demapping/gsm_bcch_ccch_sdcch4_demapper.py
M python/demapping/gsm_sdcch8_demapper.py
M python/misc_utils/CMakeLists.txt
M python/misc_utils/clock_offset_corrector_tagged.py
M python/misc_utils/device.py
D python/misc_utils/hier_block.py
M python/qa_txtime_bursts_tagger.py
M python/receiver/fcch_detector.py
M python/receiver/gsm_input.py
M python/transmitter/gsm_gmsk_mod.py
M python/transmitter/txtime_bursts_tagger.py
M python/trx/__init__.py
M python/trx/ctrl_if.py
M python/trx/ctrl_if_bb.py
M python/trx/radio_if.py
M python/trx/radio_if_uhd.py
M python/trx/transceiver.py
21 files changed, 53 insertions(+), 92 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/gr-gsm refs/changes/63/24063/1

diff --git a/apps/grgsm_decode b/apps/grgsm_decode
index 4bd1d95..034014e 100755
--- a/apps/grgsm_decode
+++ b/apps/grgsm_decode
@@ -336,7 +336,7 @@
         parser, 'TCH Options', 'Options for setting Traffic channel decoding parameters.',
     )
     tch_options.add_option("-d", "--speech-codec", dest="speech_codec", default='FR',
-                           type='choice', choices=tch_codecs.keys(),
+                           type='choice', choices=list(tch_codecs.keys()),
                            help="TCH-F speech codec [default=%default]. "
                                 "Valid options are " + ", ".join(tch_codecs.keys()))
     tch_options.add_option("-o", "--output-tch", dest="speech_output_file", default="/tmp/speech.au.gsm",
diff --git a/apps/grgsm_scanner b/apps/grgsm_scanner
index ce33a60..e3d7a61 100755
--- a/apps/grgsm_scanner
+++ b/apps/grgsm_scanner
@@ -40,9 +40,9 @@
 
 # from wideband_receiver import *
 
-class receiver_with_decoder(grgsm.hier_block):
+class receiver_with_decoder(gr.hier_block2):
     def __init__(self, OSR=4, chan_num=0, fc=939.4e6, ppm=0, samp_rate=0.2e6):
-        grgsm.hier_block.__init__(
+        gr.hier_block2.__init__(
             self, "Receiver With Decoder",
             gr.io_signature(1, 1, gr.sizeof_gr_complex * 1),
             gr.io_signature(0, 0, 0),
@@ -132,9 +132,9 @@
         self.samp_rate_out = samp_rate_out
 
 
-class wideband_receiver(grgsm.hier_block):
+class wideband_receiver(gr.hier_block2):
     def __init__(self, OSR=4, fc=939.4e6, samp_rate=0.4e6):
-        grgsm.hier_block.__init__(
+        gr.hier_block2.__init__(
             self, "Wideband receiver",
             gr.io_signature(1, 1, gr.sizeof_gr_complex * 1),
             gr.io_signature(0, 0, 0),
@@ -168,14 +168,14 @@
         # Connections
         ##################################################
         self.connect((self, 0), (self.pfb_channelizer_ccf_0, 0))
-        for chan in xrange(0, self.channels_num):
+        for chan in range(0, self.channels_num):
             self.connect((self.pfb_channelizer_ccf_0, chan), (self.receivers_with_decoders[chan], 0))
             self.msg_connect(self.receivers_with_decoders[chan], 'bursts', self, 'bursts')
             self.msg_connect(self.receivers_with_decoders[chan], 'msgs', self, 'msgs')
 
     def create_receivers(self):
         self.receivers_with_decoders = {}
-        for chan in xrange(0, self.channels_num):
+        for chan in range(0, self.channels_num):
             self.receivers_with_decoders[chan] = receiver_with_decoder(fc=self.fc, OSR=self.OSR, chan_num=chan,
                                                                        samp_rate=self.OSR_PFB * 0.2e6)
 
@@ -207,7 +207,7 @@
         self.ppm = ppm
 
         # if no file name is given process data from rtl_sdr source
-        print "Args=", args
+        print("Args=", args)
         self.rtlsdr_source = osmosdr.source(args="numchan=" + str(1) + " " +
                 str(grgsm.device.get_default_args(args)))
         #self.rtlsdr_source.set_min_output_buffer(int(sample_rate*rec_len)) #this line causes segfaults on HackRF
@@ -261,6 +261,10 @@
         self.neighbours = neighbours
         self.cell_arfcns = cell_arfcns
 
+    def __lt__(self, other):
+        return self.arfcn < other.arfcn
+
+
     def get_verbose_info(self):
         i = "  |---- Configuration: %s\n" % self.get_ccch_conf()
         i += "  |---- Cell ARFCNs: " + ", ".join(map(str, self.cell_arfcns)) + "\n"
@@ -315,7 +319,7 @@
             if not debug:
                 # silence rtl_sdr output:
                 # open 2 fds
-                null_fds = [os.open(os.devnull, os.O_RDWR) for x in xrange(2)]
+                null_fds = [os.open(os.devnull, os.O_RDWR) for x in range(2)]
                 # save the current file descriptors to a tuple
                 save = os.dup(1), os.dup(2)
                 # put /dev/null fds on 1 and 2
@@ -423,10 +427,10 @@
 
     def printfunc(found_list):
         for info in sorted(found_list):
-            print info
+            print(info)
             if options.verbose:
-                print info.get_verbose_info()
-    print ""
+                print(info.get_verbose_info())
+    print("")
     do_scan(options.samp_rate, options.band, options.speed,
             options.ppm, options.gain, options.args, prn = printfunc, debug = options.debug)
 
diff --git a/python/__init__.py b/python/__init__.py
index 8241b01..557a8d6 100644
--- a/python/__init__.py
+++ b/python/__init__.py
@@ -42,24 +42,23 @@
 
 
 # import swig generated symbols into the gsm namespace
-from grgsm_swig import *
+from .grgsm_swig import *
 
 # import any pure python here
 
-from hier_block import hier_block
 #from fcch_burst_tagger import fcch_burst_tagger
 #from sch_detector import sch_detector
 #from fcch_detector import fcch_detector
-from clock_offset_corrector_tagged import clock_offset_corrector_tagged
-from gsm_input import gsm_input
-from gsm_bcch_ccch_demapper import gsm_bcch_ccch_demapper
-from gsm_bcch_ccch_sdcch4_demapper import gsm_bcch_ccch_sdcch4_demapper
-from gsm_sdcch8_demapper import gsm_sdcch8_demapper
-from gsm_gmsk_mod import gsm_gmsk_mod
-from fn_time import *
-from txtime_bursts_tagger import *
-import arfcn
-import device
+from .clock_offset_corrector_tagged import clock_offset_corrector_tagged
+from .gsm_input import gsm_input
+from .gsm_bcch_ccch_demapper import gsm_bcch_ccch_demapper
+from .gsm_bcch_ccch_sdcch4_demapper import gsm_bcch_ccch_sdcch4_demapper
+from .gsm_sdcch8_demapper import gsm_sdcch8_demapper
+from .gsm_gmsk_mod import gsm_gmsk_mod
+from .fn_time import *
+from .txtime_bursts_tagger import *
+from .arfcn import *
+from .device import *
 
 
 #
diff --git a/python/demapping/gsm_bcch_ccch_demapper.py b/python/demapping/gsm_bcch_ccch_demapper.py
index e036831..06baa62 100644
--- a/python/demapping/gsm_bcch_ccch_demapper.py
+++ b/python/demapping/gsm_bcch_ccch_demapper.py
@@ -32,10 +32,10 @@
 import grgsm
 
 
-class gsm_bcch_ccch_demapper(grgsm.hier_block):
+class gsm_bcch_ccch_demapper(gr.hier_block2):
 
     def __init__(self, timeslot_nr=0):
-        grgsm.hier_block.__init__(
+        gr.hier_block2.__init__(
             self, "BCCH + CCCH demapper",
             gr.io_signature(0, 0, 0),
             gr.io_signature(0, 0, 0),
diff --git a/python/demapping/gsm_bcch_ccch_sdcch4_demapper.py b/python/demapping/gsm_bcch_ccch_sdcch4_demapper.py
index bff67a4..f025a70 100644
--- a/python/demapping/gsm_bcch_ccch_sdcch4_demapper.py
+++ b/python/demapping/gsm_bcch_ccch_sdcch4_demapper.py
@@ -32,10 +32,10 @@
 import grgsm
 
 
-class gsm_bcch_ccch_sdcch4_demapper(grgsm.hier_block):
+class gsm_bcch_ccch_sdcch4_demapper(gr.hier_block2):
 
     def __init__(self, timeslot_nr=0):
-        grgsm.hier_block.__init__(
+        gr.hier_block2.__init__(
             self, "BCCH + CCCH + SDCCH/4 demapper",
             gr.io_signature(0, 0, 0),
             gr.io_signature(0, 0, 0),
diff --git a/python/demapping/gsm_sdcch8_demapper.py b/python/demapping/gsm_sdcch8_demapper.py
index b412594..30450bf 100644
--- a/python/demapping/gsm_sdcch8_demapper.py
+++ b/python/demapping/gsm_sdcch8_demapper.py
@@ -32,10 +32,10 @@
 import grgsm
 
 
-class gsm_sdcch8_demapper(grgsm.hier_block):
+class gsm_sdcch8_demapper(gr.hier_block2):
 
     def __init__(self, timeslot_nr=1):
-        grgsm.hier_block.__init__(
+        gr.hier_block2.__init__(
             self, "SDCCH/8 demapper",
             gr.io_signature(0, 0, 0),
             gr.io_signature(0, 0, 0),
diff --git a/python/misc_utils/CMakeLists.txt b/python/misc_utils/CMakeLists.txt
index 76304ca..57ed275 100644
--- a/python/misc_utils/CMakeLists.txt
+++ b/python/misc_utils/CMakeLists.txt
@@ -21,7 +21,6 @@
     FILES
     arfcn.py
     clock_offset_corrector_tagged.py
-    hier_block.py 
     fn_time.py
     device.py
     DESTINATION ${GR_PYTHON_DIR}/grgsm
diff --git a/python/misc_utils/clock_offset_corrector_tagged.py b/python/misc_utils/clock_offset_corrector_tagged.py
index be55212..ea474b1 100644
--- a/python/misc_utils/clock_offset_corrector_tagged.py
+++ b/python/misc_utils/clock_offset_corrector_tagged.py
@@ -33,7 +33,7 @@
 import math
 
 
-class clock_offset_corrector_tagged(grgsm.hier_block):
+class clock_offset_corrector_tagged(gr.hier_block2):
 
     def __init__(self, fc=936.6e6, osr=4, ppm=0, samp_rate_in=1625000.0/6.0*4.0):
         gr.hier_block2.__init__(
diff --git a/python/misc_utils/device.py b/python/misc_utils/device.py
index de967ab..ddd9dec 100644
--- a/python/misc_utils/device.py
+++ b/python/misc_utils/device.py
@@ -40,7 +40,7 @@
     return [dev for dev in devices if not match(dev, filters)]
 
 def get_all_args(hint="nofake"):
-    return map(lambda dev: dev.to_string(), exclude(get_devices(hint)))
+    return list(map(lambda dev: dev.to_string(), exclude(get_devices(hint))))
 
 def get_default_args(args):
     # The presence of GRC_BLOCKS_PATH environment variable indicates that
diff --git a/python/misc_utils/hier_block.py b/python/misc_utils/hier_block.py
deleted file mode 100644
index 0dc9c78..0000000
--- a/python/misc_utils/hier_block.py
+++ /dev/null
@@ -1,41 +0,0 @@
-#!/usr/bin/env python2
-# -*- coding: utf-8 -*-
-# @file
-# @author (C) 2016 by Piotr Krysik <ptrkrysik at gmail.com>
-# @section LICENSE
-#
-# Gr-gsm 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, or (at your option)
-# any later version.
-#
-# Gr-gsm 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 gr-gsm; see the file COPYING.  If not, write to
-# the Free Software Foundation, Inc., 51 Franklin Street,
-# Boston, MA 02110-1301, USA.
-#
-
-from gnuradio import gr
-from distutils.version import LooseVersion as version
-
-#class created to solve incompatibility of reginstration of message inputs
-#that was introduced in gnuradio 3.7.9
-
-class hier_block(gr.hier_block2):
-    def message_port_register_hier_in(self, port_id):
-        if version(gr.version()) >= version('3.7.9'):
-            super(hier_block, self).message_port_register_hier_in(port_id)
-        else:
-            super(hier_block, self).message_port_register_hier_out(port_id)
-
-    def message_port_register_hier_out(self, port_id):
-        if version(gr.version()) >= version('3.7.9'):
-            super(hier_block, self).message_port_register_hier_out(port_id)
-        else:
-            super(hier_block, self).message_port_register_hier_in(port_id)
-
diff --git a/python/qa_txtime_bursts_tagger.py b/python/qa_txtime_bursts_tagger.py
index bdbf1af..fd15b10 100755
--- a/python/qa_txtime_bursts_tagger.py
+++ b/python/qa_txtime_bursts_tagger.py
@@ -64,8 +64,8 @@
         
         tb.start()
         tb.wait()
-        print "Dupa"
-        print sink
+        print("Dupa")
+        print(sink)
         
         
 #        msg1 = make_msg(1,"lol1")
diff --git a/python/receiver/fcch_detector.py b/python/receiver/fcch_detector.py
index 81438e2..9b787c2 100644
--- a/python/receiver/fcch_detector.py
+++ b/python/receiver/fcch_detector.py
@@ -36,10 +36,10 @@
 from gnuradio.filter import firdes
 import grgsm
 
-class fcch_detector(grgsm.hier_block):
+class fcch_detector(gr.hier_block2):
 
     def __init__(self, OSR=4):
-        grgsm.hier_block.__init__(
+        gr.hier_block2.__init__(
             self, "FCCH bursts detector",
             gr.io_signature(1, 1, gr.sizeof_gr_complex*1),
             gr.io_signature(1, 1, gr.sizeof_gr_complex*1),
diff --git a/python/receiver/gsm_input.py b/python/receiver/gsm_input.py
index 8c4ad51..05e323d 100644
--- a/python/receiver/gsm_input.py
+++ b/python/receiver/gsm_input.py
@@ -33,7 +33,7 @@
 import grgsm
 
 
-class gsm_input(grgsm.hier_block):
+class gsm_input(gr.hier_block2):
 
     def __init__(self, fc=940e6, osr=4, ppm=0, samp_rate_in=1e6):
         gr.hier_block2.__init__(
diff --git a/python/transmitter/gsm_gmsk_mod.py b/python/transmitter/gsm_gmsk_mod.py
index e8ecc7a..fec936c 100644
--- a/python/transmitter/gsm_gmsk_mod.py
+++ b/python/transmitter/gsm_gmsk_mod.py
@@ -14,7 +14,7 @@
 from gnuradio.filter import firdes
 import grgsm
 
-class gsm_gmsk_mod(grgsm.hier_block):
+class gsm_gmsk_mod(gr.hier_block2):
 
     def __init__(self, BT=4, pulse_duration=4, sps=4):
         gr.hier_block2.__init__(
diff --git a/python/transmitter/txtime_bursts_tagger.py b/python/transmitter/txtime_bursts_tagger.py
index de42f65..952c8d1 100644
--- a/python/transmitter/txtime_bursts_tagger.py
+++ b/python/transmitter/txtime_bursts_tagger.py
@@ -22,7 +22,7 @@
 # 
 
 from gnuradio import gr
-from fn_time import fn_time_delta
+from .fn_time import fn_time_delta
 import pmt
 import numpy
 
diff --git a/python/trx/__init__.py b/python/trx/__init__.py
index c8bddbe..23042b0 100644
--- a/python/trx/__init__.py
+++ b/python/trx/__init__.py
@@ -20,10 +20,10 @@
 This is a set of helper classes for the grgsm_trx application.
 '''
 
-from udp_link import UDPLink
-from ctrl_if import CTRLInterface
-from ctrl_if_bb import CTRLInterfaceBB
-from radio_if import RadioInterface
-from transceiver import Transceiver
+from .udp_link import UDPLink
+from .ctrl_if import CTRLInterface
+from .ctrl_if_bb import CTRLInterfaceBB
+from .radio_if import RadioInterface
+from .transceiver import Transceiver
 
-from dict_toggle_sign import dict_toggle_sign
+from .dict_toggle_sign import dict_toggle_sign
diff --git a/python/trx/ctrl_if.py b/python/trx/ctrl_if.py
index 1a7c0c3..d7e14f1 100644
--- a/python/trx/ctrl_if.py
+++ b/python/trx/ctrl_if.py
@@ -22,7 +22,7 @@
 # with this program; if not, write to the Free Software Foundation, Inc.,
 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
-from udp_link import UDPLink
+from .udp_link import UDPLink
 
 class CTRLInterface(UDPLink):
 	def handle_rx(self, data, remote):
diff --git a/python/trx/ctrl_if_bb.py b/python/trx/ctrl_if_bb.py
index 4814263..1c21c55 100644
--- a/python/trx/ctrl_if_bb.py
+++ b/python/trx/ctrl_if_bb.py
@@ -22,7 +22,7 @@
 # with this program; if not, write to the Free Software Foundation, Inc.,
 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
-from ctrl_if import CTRLInterface
+from .ctrl_if import CTRLInterface
 
 class CTRLInterfaceBB(CTRLInterface):
 	def __init__(self, trx, *ctrl_if_args):
diff --git a/python/trx/radio_if.py b/python/trx/radio_if.py
index 0d844c0..acbc3cd 100644
--- a/python/trx/radio_if.py
+++ b/python/trx/radio_if.py
@@ -38,7 +38,7 @@
 from gnuradio import filter
 from gnuradio.filter import firdes
 
-from dict_toggle_sign import dict_toggle_sign
+from .dict_toggle_sign import dict_toggle_sign
 
 class RadioInterface(gr.top_block):
 	# PHY specific variables
diff --git a/python/trx/radio_if_uhd.py b/python/trx/radio_if_uhd.py
index ef2e0ed..664a51c 100644
--- a/python/trx/radio_if_uhd.py
+++ b/python/trx/radio_if_uhd.py
@@ -24,7 +24,7 @@
 
 from gnuradio import uhd
 
-from radio_if import RadioInterface
+from .radio_if import RadioInterface
 
 class RadioInterfaceUHD(RadioInterface):
 	# Human-readable description
diff --git a/python/trx/transceiver.py b/python/trx/transceiver.py
index 837a61f..4e706e3 100644
--- a/python/trx/transceiver.py
+++ b/python/trx/transceiver.py
@@ -22,7 +22,7 @@
 # with this program; if not, write to the Free Software Foundation, Inc.,
 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
-from ctrl_if_bb import CTRLInterfaceBB
+from .ctrl_if_bb import CTRLInterfaceBB
 
 class Transceiver:
 	""" Base transceiver implementation.

-- 
To view, visit https://gerrit.osmocom.org/c/gr-gsm/+/24063
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: gr-gsm
Gerrit-Branch: master
Gerrit-Change-Id: I5ca8fd340823996e8c444aaf18ddacd85c92ab1c
Gerrit-Change-Number: 24063
Gerrit-PatchSet: 1
Gerrit-Owner: ptrkrysik <ptrkrysik at gmail.com>
Gerrit-Reviewer: vvvelichkov <vvvelichkov at gmail.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210503/31b66570/attachment.htm>


More information about the gerrit-log mailing list