Commit 8f972c5e authored by enfo's avatar enfo

Reimplemented Python3 support

parent 713389d9
......@@ -40,7 +40,7 @@ def extract_packages(fname, parsers):
try:
pack = parser.parse_buffer(raw_pack)
except Exception as e:
print 'Could not parse package', e
print('Could not parse package: %s' % e)
continue
except EOFError:
break
......@@ -52,7 +52,7 @@ def extract_packages(fname, parsers):
packages[raw_pack.package_type] = data
for k, v in pack.dict.iteritems():
for k, v in pack.dict.items():
try:
data[k].append(v)
except KeyError:
......@@ -62,19 +62,19 @@ def extract_packages(fname, parsers):
def handle_data_directory(sb_data_dir, parsers, outdir):
global data
for i in xrange(1, 101):
for i in range(1, 101):
if i == 100:
raise IndexError('Could not find proper directory')
odir = outdir + '_%02d' % i
if not os.path.exists(odir):
os.mkdir(odir, 0770)
os.mkdir(odir, 0o0770)
break
if os.listdir(odir) == []:
break
outdir = os.path.abspath(odir)
print('Saving to %s' % outdir)
print
print('')
globname = glob(os.path.join(sb_data_dir, '*.*'))
......@@ -103,14 +103,14 @@ def do_combine_data(data_dir, combined_dir, overwrite, newnames=None):
sensor_files = {}
for pardir in sorted(glob(os.path.join(data_dir, '*_[0-9]*'))):
for p in glob(os.path.join(pardir, '*')):
print 'Handling', os.path.abspath(p)
print('Handling %s' % os.path.abspath(p))
_, fname = os.path.split(p)
try:
sensor_files[fname].append(p)
except KeyError:
sensor_files[fname] = [p]
for n, filelist in sensor_files.iteritems():
for n, filelist in sensor_files.items():
try:
newname = newnames[n]
except KeyError:
......@@ -157,4 +157,4 @@ if __name__ == '__main__':
try:
handle_data_directory(sb_data_dir, parsers, outdir)
finally:
print 'Done'
print('Done')
......@@ -40,7 +40,7 @@ class UbloxPackage(object):
class UbloxPackageRxmRawX(UbloxPackage):
ubx_name = 'RXM-RAWX'
ubx_id = '\x02\x15'
ubx_id = b'\x02\x15'
def __init__(self, ubx_id, tov, package, toa, tot, timestamp):
self._name = self.ubx_name
UbloxPackage.__init__(self, ubx_id, tov, package, toa, tot, timestamp)
......@@ -82,7 +82,7 @@ class UbloxPackageRxmRawX(UbloxPackage):
class UbloxPackageRxmSfrbX(UbloxPackage):
ubx_name = 'RXM-SFRBX'
ubx_id = '\x02\x13'
ubx_id = b'\x02\x13'
def __init__(self, ubx_id, tov, package, toa, tot, timestamp):
self._name = self.ubx_name
......@@ -107,7 +107,7 @@ class UbloxPackageRxmSfrbX(UbloxPackage):
class UbloxPackageRxmMeasX(UbloxPackage):
ubx_name = 'RXM-MEASX'
ubx_id = '\x02\x14'
ubx_id = b'\x02\x14'
def __init__(self, ubx_id, tov, package, toa, tot, timestamp):
self._name = self.ubx_name
UbloxPackage.__init__(self, ubx_id, tov, package, toa, tot, timestamp)
......@@ -145,7 +145,7 @@ class UbloxPackageRxmMeasX(UbloxPackage):
class UbloxPackageNavPosLLH(UbloxPackage):
ubx_name = 'NAV-POSLLH'
ubx_id = '\x01\x02'
ubx_id = b'\x01\x02'
def __init__(self, ubx_id, tov, package, toa, tot, timestamp):
UbloxPackage.__init__(self, ubx_id, tov, package, toa, tot, timestamp)
......@@ -155,7 +155,7 @@ class UbloxPackageNavPosLLH(UbloxPackage):
class UbloxPackageNavPosECEF(UbloxPackage):
ubx_name = 'NAV-POSECEF'
ubx_id = '\x01\x01'
ubx_id = b'\x01\x01'
def __init__(self, ubx_id, tov, package, toa, tot, timestamp):
UbloxPackage.__init__(self, ubx_id, tov, package, toa, tot, timestamp)
......@@ -165,7 +165,7 @@ class UbloxPackageNavPosECEF(UbloxPackage):
class UbloxPackageNavVelEcef(UbloxPackage):
ubx_name = 'NAV-VELECEF'
ubx_id = '\x01\x11'
ubx_id = b'\x01\x11'
def __init__(self, ubx_id, tov, package, toa, tot, timestamp):
UbloxPackage.__init__(self, ubx_id, tov, package, toa, tot, timestamp)
......@@ -175,7 +175,7 @@ class UbloxPackageNavVelEcef(UbloxPackage):
class UbloxPackageNavVelNED(UbloxPackage):
ubx_name = 'NAV-VELNED'
ubx_id = '\x01\x12'
ubx_id = b'\x01\x12'
def __init__(self, ubx_id, tov, package, toa, tot, timestamp):
UbloxPackage.__init__(self, ubx_id, tov, package, toa, tot, timestamp)
......@@ -186,7 +186,7 @@ class UbloxPackageNavVelNED(UbloxPackage):
class UbloxPackagePVT(UbloxPackage):
ubx_name = 'NAV-PVT'
ubx_id = '\x01\x07'
ubx_id = b'\x01\x07'
def __init__(self, ubx_id, tov, package, toa, tot, timestamp):
UbloxPackage.__init__(self, ubx_id, tov, package, toa, tot, timestamp)
......@@ -209,7 +209,7 @@ class UbloxPackagePVT(UbloxPackage):
class UbloxPackageNavClock(UbloxPackage):
ubx_name = 'NAV-CLOCK'
ubx_id = '\x01\x22'
ubx_id = b'\x01\x22'
def __init__(self, ubx_id, tov, package, toa, tot, timestamp):
UbloxPackage.__init__(self, ubx_id, tov, package, toa, tot, timestamp)
......@@ -225,21 +225,21 @@ MSG_TYPES = [UbloxPackageRxmRawX, UbloxPackageNavPosLLH, UbloxPackageRxmSfrbX,
UBX_MSG_TYPES = dict([(t.ubx_id, t) for t in MSG_TYPES])
UBX_MSG_NAMES = {
'\x01\x32': 'NAV-SBAS',
'\x0B\x31': 'AID-EPH',
'\x0B\x01': 'AID-INI',
'\x02\x14': 'RXM-MEASX',
'\x01\x07': 'NAV-PVT',
'\x01\x12': 'NAV-VELNED',
'\x01\x22': 'NAV-CLOCK'
b'\x01\x32': 'NAV-SBAS',
b'\x0B\x31': 'AID-EPH',
b'\x0B\x01': 'AID-INI',
b'\x02\x14': 'RXM-MEASX',
b'\x01\x07': 'NAV-PVT',
b'\x01\x12': 'NAV-VELNED',
b'\x01\x22': 'NAV-CLOCK'
}
UBX_MSG_NAMES.update([(ubx_id, ubx_type.ubx_name) for ubx_id, ubx_type
in UBX_MSG_TYPES.iteritems()])
in UBX_MSG_TYPES.items()])
class UbloxParser(object):
allowed_ids = ['\xB5\x62']
allowed_ids = [b'\xB5\x62']
multipart = True
def parse_buffer(self, buf):
......@@ -276,9 +276,9 @@ class UbloxParser(object):
return ubx_msg_type(ubx_msg_id, buf.tov, ublox_package, buf.toa,
buf.tot, buf.timestamp)
except Exception, e:
except Exception as e:
raise
print e.message
print(e.message)
return None
if __name__ == '__main__':
......@@ -333,10 +333,10 @@ if __name__ == '__main__':
# sys.stdout.write(text + '\tsplinter:\t%d' % reader.splinter_time)
sys.stdout.flush()
i+=1
except Exception, e:
print
print 'Exception:', e
except Exception as e:
print()
print('Exception: %s' % e)
raise
print
print 'Got a total of %d ublox messages' % i
print ids
print()
print('Got a total of %d ublox messages' % i)
print(ids)
......@@ -237,9 +237,9 @@ class SyncboardReader(object):
n_bytes, buf = self._sync_package()
if n_bytes == -1:
return None
if buf[:2] == '^C':
if buf[:2] == b'^C':
including_timestamp = True
buf[1] = 'B'
buf[1] = ord('B')
else:
including_timestamp = False
......@@ -324,4 +324,4 @@ if __name__ == '__main__':
FIRST_PACKAGE = READER.get_package()
SECOND_PACKAGE = READER.get_package()
print FIRST_PACKAGE, SECOND_PACKAGE
print(FIRST_PACKAGE, SECOND_PACKAGE)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment