tool: update python scripts to python3

This commit is contained in:
Matthias Ringwald 2020-07-09 16:24:31 +02:00
parent 3404c94120
commit 5c54401929
20 changed files with 55 additions and 56 deletions

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
# #
# Scrape GATT UUIDs from Bluetooth SIG page # Scrape GATT UUIDs from Bluetooth SIG page
# https://www.bluetooth.com/specifications/assigned-numbers/company-identifiers # https://www.bluetooth.com/specifications/assigned-numbers/company-identifiers

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
# #
# Scrape GAP Data Types from Bluetooth SIG page # Scrape GAP Data Types from Bluetooth SIG page
# Copyright 2016 BlueKitchen GmbH # Copyright 2016 BlueKitchen GmbH

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
# #
# Scrape GATT UUIDs from Bluetooth SIG page # Scrape GATT UUIDs from Bluetooth SIG page
# Copyright 2016 BlueKitchen GmbH # Copyright 2016 BlueKitchen GmbH

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
# #
# Scrape GATT UUIDs from Bluetooth SIG page # Scrape GATT UUIDs from Bluetooth SIG page
# https://www.bluetooth.com/specifications/assigned-numbers/logical-link-control/ # https://www.bluetooth.com/specifications/assigned-numbers/logical-link-control/

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
# #
# Scrape SDP UUIDs from Bluetooth SIG page # Scrape SDP UUIDs from Bluetooth SIG page
# Copyright 2017 BlueKitchen GmbH # Copyright 2017 BlueKitchen GmbH
@ -69,11 +69,11 @@ def remove_newlines(remark):
def process_rows(fout, rows, pattern): def process_rows(fout, rows, pattern):
for row in rows: for row in rows:
columns = row.getchildren() columns = row.getchildren()
name = columns[0].text_content().encode('ascii','ignore') name = columns[0].text_content().replace(u'\u2013','').replace(u'\u200b','')
value = columns[1].text_content().encode('ascii','ignore') value = columns[1].text_content().replace(u'\u200b','')
remark = '' remark = ''
if (len(columns) > 2): if (len(columns) > 2):
remark = columns[2].text_content().encode('ascii','ignore') remark = columns[2].text_content().replace(u'\u200b','')
# skip tbody headers # skip tbody headers
if name in ["Protocol Name", "Service Class Name", "Attribute Name", "UUID Name", if name in ["Protocol Name", "Service Class Name", "Attribute Name", "UUID Name",
"Reserved", 'Reserved for HID Attributes', 'Available for HID Language Strings']: "Reserved", 'Reserved for HID Attributes', 'Available for HID Language Strings']:
@ -82,6 +82,11 @@ def process_rows(fout, rows, pattern):
if value.startswith('(Max value '): if value.startswith('(Max value '):
continue continue
name = create_pretty_define(name) name = create_pretty_define(name)
print(name)
if name.endswith("DISPLAY"):
for c in name:
print("ord %c = 0x%x" % (c, ord(c)))
# skip duplicate attributes # skip duplicate attributes
if name in defines: if name in defines:
continue continue

View File

@ -1,5 +1,5 @@
#!/usr/bin/env python
# BlueKitchen GmbH (c) 2014 # BlueKitchen GmbH (c) 2014
#!/usr/bin/env python3
import glob import glob
import re import re
@ -308,7 +308,7 @@ def create_events(events):
else: else:
last_variable_length_field_pos = offset last_variable_length_field_pos = offset
if field_type in 'V': if field_type in 'V':
if last_variable_length_field_pos >= 0: if last_variable_length_field_pos != '':
if offset_is_number: if offset_is_number:
# convert to string # convert to string
offset = '((uint8_t) %u)' % offset offset = '((uint8_t) %u)' % offset

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
import os import os
import sys import sys
@ -107,8 +107,11 @@ hfile_header_end = """
""" """
cfile_header_begin = """ cfile_header_begin = """
#define BTSTACK_FILE__ "btstack_memory.c"
/* /*
* btstack_memory.h * btstack_memory.c
* *
* @brief BTstack memory management via configurable memory pools * @brief BTstack memory management via configurable memory pools
* *

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
# BlueKitchen GmbH (c) 2014 # BlueKitchen GmbH (c) 2014
import re import re

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
import os, sys, getopt, re, pickle import os, sys, getopt, re, pickle
copyright = """/* copyright = """/*

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
# #
# Convert offical Bluetooth GATT Service definitions into BTstack's .gatt format # Convert offical Bluetooth GATT Service definitions into BTstack's .gatt format
# Copyright 2016 BlueKitchen GmbH # Copyright 2016 BlueKitchen GmbH

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
# #
# Create Makefile.inc file for all source folders # Create Makefile.inc file for all source folders
# Copyright 2017 BlueKitchen GmbH # Copyright 2017 BlueKitchen GmbH

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
# BlueKitchen GmbH (c) 2014 # BlueKitchen GmbH (c) 2014
# convert log output to PacketLogger format # convert log output to PacketLogger format
@ -91,7 +91,7 @@ if len(sys.argv) == 1:
print('BTstack Console to PacketLogger converter') print('BTstack Console to PacketLogger converter')
print('Copyright 2014, BlueKitchen GmbH') print('Copyright 2014, BlueKitchen GmbH')
print('') print('')
print('Usage: ', sys.argv[0], 'asci-log-file.txt [hci_dump.pkgl]') print('Usage: ', sys.argv[0], 'ascii-log-file.txt [hci_dump.pklg]')
print('Converted hci_dump.pklg can be viewed with Wireshark and OS X PacketLogger') print('Converted hci_dump.pklg can be viewed with Wireshark and OS X PacketLogger')
exit(0) exit(0)

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
# BlueKitchen GmbH (c) 2014 # BlueKitchen GmbH (c) 2014
# primitive dump for PacketLogger format # primitive dump for PacketLogger format
@ -11,9 +11,7 @@
# uint8_t type; // 0xfc for note # uint8_t type; // 0xfc for note
# } # }
import re
import sys import sys
import time
import datetime import datetime
packet_types = [ "CMD =>", "EVT <=", "ACL =>", "ACL <="] packet_types = [ "CMD =>", "EVT <=", "ACL =>", "ACL <="]
@ -36,14 +34,14 @@ def read_net_32(f):
def as_hex(data): def as_hex(data):
str_list = [] str_list = []
for byte in data: for byte in data:
str_list.append("{0:02x} ".format(ord(byte))) str_list.append("{0:02x} ".format(byte))
return ''.join(str_list) return ''.join(str_list)
if len(sys.argv) == 1: if len(sys.argv) == 1:
print 'Dump PacketLogger file' print ('Dump PacketLogger file')
print 'Copyright 2014, BlueKitchen GmbH' print ('Copyright 2014, BlueKitchen GmbH')
print '' print ('')
print 'Usage: ', sys.argv[0], 'hci_dump.pklg' print ('Usage: ', sys.argv[0], 'hci_dump.pklg')
exit(0) exit(0)
infile = sys.argv[1] infile = sys.argv[1]
@ -66,10 +64,9 @@ with open (infile, 'rb') as fin:
pos = pos + 4 + len pos = pos + 4 + len
time = "[%s.%03u]" % (datetime.datetime.fromtimestamp(ts_sec).strftime("%Y-%m-%d %H:%M:%S"), ts_usec / 1000) time = "[%s.%03u]" % (datetime.datetime.fromtimestamp(ts_sec).strftime("%Y-%m-%d %H:%M:%S"), ts_usec / 1000)
if type == 0xfc: if type == 0xfc:
print time, "LOG", packet print (time, "LOG", packet.decode('ascii'))
continue continue
if type <= 0x03: if type <= 0x03:
print time, packet_types[type], as_hex(packet) print (time, packet_types[type], as_hex(packet))
except TypeError: except TypeError:
print ("Error parsing pklg at offset %u (%x)." % (pos, pos)) print ("Error parsing pklg at offset %u (%x)." % (pos, pos))

View File

@ -1,12 +1,9 @@
#!/usr/bin/env python #!/usr/bin/env python3
# BlueKitchen GmbH (c) 2017 # BlueKitchen GmbH (c) 2017
# primitive dump for .tlv format # primitive dump for .tlv format
import re
import sys import sys
import time
import datetime
def read_net_32(f): def read_net_32(f):
a = f.read(1) a = f.read(1)
@ -26,14 +23,14 @@ def read_net_32(f):
def as_hex(data): def as_hex(data):
str_list = [] str_list = []
for byte in data: for byte in data:
str_list.append("{0:02x} ".format(ord(byte))) str_list.append("{0:02x} ".format(byte))
return ''.join(str_list) return ''.join(str_list)
if len(sys.argv) == 1: if len(sys.argv) == 1:
print 'Dump TLV file' print ('Dump TLV file')
print 'Copyright 2017, BlueKitchen GmbH' print ('Copyright 2017, BlueKitchen GmbH')
print '' print ('')
print 'Usage: ', sys.argv[0], 'file.tlv' print ('Usage: ', sys.argv[0], 'file.tlv')
exit(0) exit(0)
infile = sys.argv[1] infile = sys.argv[1]
@ -65,4 +62,3 @@ with open (infile, 'rb') as fin:
except TypeError: except TypeError:
print ("Error parsing tlv at offset %u (%x)." % (pos, pos)) print ("Error parsing tlv at offset %u (%x)." % (pos, pos))

View File

@ -1,10 +1,6 @@
#!/usr/bin/env python #!/usr/bin/env python3
# BlueKitchen GmbH (c) 2014 # BlueKitchen GmbH (c) 2014
import glob
import re
import sys
import btstack_parser as parser import btstack_parser as parser
print(''' print('''
@ -361,7 +357,7 @@ def create_event_factory(events, subevents, defines):
if not event_supported(event_name): if not event_supported(event_name):
continue continue
class_name = class_name_for_event(event_name) class_name = class_name_for_event(event_name)
print class_name print(class_name)
subcases += java_event_factory_subevent.format(event_type, class_name) subcases += java_event_factory_subevent.format(event_type, class_name)
with open(outfile, 'wt') as fout: with open(outfile, 'wt') as fout:

6
tool/misc/update_copyright.py Normal file → Executable file
View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
import os import os
import re import re
@ -113,8 +113,10 @@ def requiresCopyrightUpdate(file_name):
global copyrightString, onlyDumpDifferentCopyright global copyrightString, onlyDumpDifferentCopyright
exactCopyrightFound = False exactCopyrightFound = False
with open(file_name, "rb") as fin: with open(file_name, "rt") as fin:
print("File: " + file_name)
for line in fin: for line in fin:
print("Line: " + line)
parts = re.match('.*('+copyrightString+').*',line) parts = re.match('.*('+copyrightString+').*',line)
if parts: if parts:
exactCopyrightFound = True exactCopyrightFound = True

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
# BlueKitchen GmbH (c) 2018 # BlueKitchen GmbH (c) 2018
import glob import glob

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
import math import math
import sys import sys
@ -33,8 +33,8 @@ if __name__ == "__main__":
print(usage) print(usage)
sys.exit(1) sys.exit(1)
sine_num_samples = sine_sample_rate/sine_frequency sine_num_samples = int(sine_sample_rate/sine_frequency)
print(type(sine_num_samples).__name__)
print(sine_array.format(sine_sample_rate=sine_sample_rate, sine_frequency=sine_frequency)) print(sine_array.format(sine_sample_rate=sine_sample_rate, sine_frequency=sine_frequency))
items = 0 items = 0
for sample in range(0,sine_num_samples): for sample in range(0,sine_num_samples):
@ -42,9 +42,9 @@ if __name__ == "__main__":
angle = (sample * 360.0) / sine_num_samples angle = (sample * 360.0) / sine_num_samples
sine = math.sin(math.radians(angle)) sine = math.sin(math.radians(angle))
rescaled = int(round(sine * 32767)) rescaled = int(round(sine * 32767))
print ("%6d, " % rescaled), print ("%6d, " % rescaled, end=''),
if items == VALUES_PER_LINE: if items == VALUES_PER_LINE:
items = 0 items = 0
print print("")
print( "};") print( "};")

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
import os import os
import re import re
@ -70,7 +70,7 @@ def update_filename_tag(dir_name, file_name, has_tag):
def get_filename_tag(file_path): def get_filename_tag(file_path):
basename = os.path.basename(file_path) basename = os.path.basename(file_path)
with open(file_path, "rb") as fin: with open(file_path, "rt") as fin:
for line in fin: for line in fin:
parts = re.match(filetag_re,line) parts = re.match(filetag_re,line)
if not parts: if not parts:

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
# #
# Parase and dump UUID128 in various formats # Parase and dump UUID128 in various formats