Browse Source

py: Get makeqstrdata.py and makeversionhdr.py running under Python 2.6.

These scripts should run under as wide a range of Python versions as
possible.
pull/1298/head
Damien George 10 years ago
parent
commit
26b512ea1b
  1. 21
      py/makeqstrdata.py
  2. 16
      py/makeversionhdr.py

21
py/makeqstrdata.py

@ -1,6 +1,11 @@
"""
Process raw qstr file and output qstr data with length, hash and data bytes.
This script works with Python 2.6, 2.7, 3.3 and 3.4.
"""
from __future__ import print_function from __future__ import print_function
import argparse
import re import re
import sys import sys
@ -97,17 +102,5 @@ def do_work(infiles):
qlen_str = ('\\x%02x' * cfg_bytes_len) % tuple(((qlen >> (8 * i)) & 0xff) for i in range(cfg_bytes_len)) qlen_str = ('\\x%02x' * cfg_bytes_len) % tuple(((qlen >> (8 * i)) & 0xff) for i in range(cfg_bytes_len))
print('QDEF(MP_QSTR_%s, (const byte*)"\\x%02x\\x%02x%s" "%s")' % (ident, qhash & 0xff, (qhash >> 8) & 0xff, qlen_str, qdata)) print('QDEF(MP_QSTR_%s, (const byte*)"\\x%02x\\x%02x%s" "%s")' % (ident, qhash & 0xff, (qhash >> 8) & 0xff, qlen_str, qdata))
return True
def main():
arg_parser = argparse.ArgumentParser(description='Process raw qstr file and output qstr data with length, hash and data bytes')
arg_parser.add_argument('files', nargs='+', help='input file(s)')
args = arg_parser.parse_args()
result = do_work(args.files)
if not result:
print('exiting with error code', file=sys.stderr)
exit(1)
if __name__ == "__main__": if __name__ == "__main__":
main() do_work(sys.argv[1:])

16
py/makeversionhdr.py

@ -1,4 +1,8 @@
# This script works with Python 2 and 3 """
Generate header file with macros defining MicroPython version info.
This script works with Python 2.6, 2.7, 3.3 and 3.4.
"""
from __future__ import print_function from __future__ import print_function
@ -8,6 +12,13 @@ import datetime
import subprocess import subprocess
def get_version_info_from_git(): def get_version_info_from_git():
# Python 2.6 doesn't have check_output, so check for that
try:
subprocess.check_output
subprocess.check_call
except AttributeError:
return None
# Note: git describe doesn't work if no tag is available # Note: git describe doesn't work if no tag is available
try: try:
git_tag = subprocess.check_output(["git", "describe", "--dirty", "--always"], universal_newlines=True).strip() git_tag = subprocess.check_output(["git", "describe", "--dirty", "--always"], universal_newlines=True).strip()
@ -89,4 +100,5 @@ def make_version_header(filename):
with open(filename, 'w') as f: with open(filename, 'w') as f:
f.write(file_data) f.write(file_data)
make_version_header(sys.argv[1]) if __name__ == "__main__":
make_version_header(sys.argv[1])

Loading…
Cancel
Save