cleanup pb2py, add debug to emu.sh

pull/25/head
Pavol Rusnak 9 years ago
parent 0a8870f110
commit ee3614ae6a
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D

@ -41,5 +41,8 @@ gdb: ## start remote gdb session which connects to the openocd
load: ## load contents of src into mass storage of trezor
rm -rf /run/media/${USER}/PYBFLASH/*
cp -a src/* /run/media/${USER}/PYBFLASH/
cp -a src/lib /run/media/${USER}/PYBFLASH/
cp -a src/playground /run/media/${USER}/PYBFLASH/
cp -a src/trezor /run/media/${USER}/PYBFLASH/
cp -a src/*.py /run/media/${USER}/PYBFLASH/
sync

@ -1,5 +1,10 @@
#!/bin/bash
cd `dirname $0`/src
rm -f ../pipe.*
../vendor/micropython/unix/micropython $* -O0 -X heapsize=100000 main.py
if [ "$1" == -d ]; then
shift
gdb --args ../vendor/micropython/unix/micropython $* -O0 -X heapsize=100000 main.py
else
../vendor/micropython/unix/micropython $* -O0 -X heapsize=100000 main.py
fi
rm -f ../pipe.*

@ -0,0 +1 @@
[ABCDEFGHIJKLMNOPQRSTUVWXYZ]*.py

@ -28,6 +28,6 @@ BLUE_GRAY = rgbcolor(0x60, 0x7D, 0x8B)
BLACK = rgbcolor(0x00, 0x00, 0x00)
WHITE = rgbcolor(0xFF, 0xFF, 0xFF)
MONO = 0
NORMAL = 1
BOLD = 2
MONO = const(0)
NORMAL = const(1)
BOLD = const(2)

@ -1,9 +1,7 @@
#!/bin/bash
CURDIR=$(pwd)
for i in messages types storage ; do
for i in types messages storage ; do
# Compile .proto files to python2 modules using google protobuf library
cd $CURDIR/../../trezor-common/protob
protoc --python_out=$CURDIR/pb2/ -I/usr/include -I. $i.proto
@ -12,4 +10,3 @@ for i in messages types storage ; do
cd $CURDIR
./pb2py $i ../src/trezor/messages/
done

@ -0,0 +1,2 @@
*_pb2.py
*.pyc

@ -10,19 +10,16 @@ def process_type(t, cls):
out = ["t = p.MessageType()", ]
print("Processing type %s" % t)
print(" * type %s" % t)
TYPE_STRING = 9
TYPE_BYTES = 12
TYPE_MESSAGE = 11
for k, v in cls.DESCRIPTOR.fields_by_name.items():
#print k
for v in sorted(cls.DESCRIPTOR.fields_by_name.values(), key=lambda x: x.number):
number = v.number
fieldname = k
fieldname = v.name
type = None
repeated = v.label == 3
required = v.label == 2
@ -85,7 +82,7 @@ def process_type(t, cls):
def process_enum(t, cls):
out = []
print("Processing enum %s" % t)
print(" * enum %s" % t)
for k, v in cls.items():
# Remove type name from the beginning of the constant
@ -98,11 +95,13 @@ def process_enum(t, cls):
if t.endswith("Type") and k.startswith("%s_" % t.replace("Type", '')):
k = k.replace("%s_" % t.replace("Type", ''), '')
out.append("%s = %s" % (k, v))
out.append("%s = const(%s)" % (k, v))
return out
def process_module(mod, genpath):
print("Processing module %s" % mod.__name__)
types = dict([(name, cls) for name, cls in mod.__dict__.items() if isinstance(cls, type)])
for t, cls in types.iteritems():
@ -118,7 +117,7 @@ def process_module(mod, genpath):
def write_to_file(genpath, t, out):
# Write generated sourcecode to given file
f = open(os.path.join(genpath, "%s.py" % t), 'w')
out = ["# Automatically generated by ./pb2py"] + out
out = ["# Automatically generated by pb2py"] + out
data = "\n".join(out)

Loading…
Cancel
Save