Cleaned python scripts
This commit is contained in:
parent
5a124c7e36
commit
f6bf7f5f95
|
@ -3,7 +3,7 @@
|
||||||
__author__ = 'Fabien Poussin'
|
__author__ = 'Fabien Poussin'
|
||||||
__version__ = '0.1'
|
__version__ = '0.1'
|
||||||
|
|
||||||
from os.path import expanduser, sep, dirname, abspath
|
from os.path import dirname, abspath
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
|
|
@ -4,21 +4,19 @@ __author__ = 'Fabien Poussin'
|
||||||
__version__ = '0.1'
|
__version__ = '0.1'
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import re
|
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
from traceback import print_exc
|
|
||||||
from shutil import copy
|
from shutil import copy
|
||||||
|
|
||||||
|
|
||||||
parser = ArgumentParser(description='Generate ChibiOS-Contrib config and Makefiles from ChibiOS')
|
parser = ArgumentParser(description='Generate ChibiOS-Contrib config and Makefiles from ChibiOS')
|
||||||
parser.add_argument('-s', '--src', default='../../ChibiOS', type=str, help="ChibiOS folder")
|
parser.add_argument('-s', '--src', default='../../ChibiOS', type=str, help="ChibiOS folder")
|
||||||
parser.add_argument('-d', '--dst', default='..', type=str, help='ChibiOS-Contrib folder')
|
parser.add_argument('-d', '--dst', default='..', type=str, help='ChibiOS-Contrib folder')
|
||||||
|
|
||||||
FOLDERS = ['testhal']
|
FOLDERS = ['testhal']
|
||||||
|
|
||||||
|
|
||||||
def makefile(lines):
|
def makefile(lines):
|
||||||
|
|
||||||
for l in range(len(lines)):
|
for l in range(len(lines)):
|
||||||
|
|
||||||
if 'CHIBIOS =' in lines[l]:
|
if 'CHIBIOS =' in lines[l]:
|
||||||
lines[l] = lines[l][:-1] + '/../ChibiOS\n'
|
lines[l] = lines[l][:-1] + '/../ChibiOS\n'
|
||||||
lines.insert(l + 1, 'CHIBIOS_CONTRIB = $(CHIBIOS)/../ChibiOS-Contrib\n')
|
lines.insert(l + 1, 'CHIBIOS_CONTRIB = $(CHIBIOS)/../ChibiOS-Contrib\n')
|
||||||
|
@ -31,7 +29,6 @@ def makefile(lines):
|
||||||
|
|
||||||
|
|
||||||
def halconf(lines):
|
def halconf(lines):
|
||||||
|
|
||||||
idx_end = lines.index('#endif /* HALCONF_H */\n')
|
idx_end = lines.index('#endif /* HALCONF_H */\n')
|
||||||
lines.insert(idx_end - 1, '\n')
|
lines.insert(idx_end - 1, '\n')
|
||||||
lines.insert(idx_end - 1, '#include "halconf_community.h"')
|
lines.insert(idx_end - 1, '#include "halconf_community.h"')
|
||||||
|
@ -41,7 +38,6 @@ def halconf(lines):
|
||||||
|
|
||||||
|
|
||||||
def mcuconf(lines):
|
def mcuconf(lines):
|
||||||
|
|
||||||
idx_end = lines.index('#endif /* MCUCONF_H */\n')
|
idx_end = lines.index('#endif /* MCUCONF_H */\n')
|
||||||
lines.insert(idx_end - 1, '\n')
|
lines.insert(idx_end - 1, '\n')
|
||||||
lines.insert(idx_end - 1, '#include "mcuconf_community.h"')
|
lines.insert(idx_end - 1, '#include "mcuconf_community.h"')
|
||||||
|
|
|
@ -1,24 +1,14 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
__author__ = 'Fabien Poussin'
|
||||||
|
__version__ = '0.1'
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description='Project upgrade script for ChibiOS')
|
verbose = False
|
||||||
parser.add_argument('-p', '--path', dest='path', help='Where project files are located', required=True)
|
|
||||||
parser.add_argument('-c', '--chibios', dest='chpath', help='Where ChibiOS is located', required=True)
|
|
||||||
parser.add_argument('-v', '--verbose', dest='verbose', action='store_true')
|
|
||||||
args = parser.parse_args()
|
|
||||||
|
|
||||||
verbose = args.verbose
|
|
||||||
|
|
||||||
if not os.path.exists(args.chpath):
|
|
||||||
print('Invalid Chibios path', args.chpath)
|
|
||||||
exit(1)
|
|
||||||
|
|
||||||
new_chconf = os.path.abspath('{}/os/rt/templates/chconf.h'.format(args.chpath))
|
|
||||||
new_nilconf = os.path.abspath('{}/os/nil/templates/chconf.h'.format(args.chpath))
|
|
||||||
new_halconf = os.path.abspath('{}/os/hal/templates/halconf.h'.format(args.chpath))
|
|
||||||
|
|
||||||
def find(name, path):
|
def find(name, path):
|
||||||
ret = []
|
ret = []
|
||||||
|
@ -44,7 +34,7 @@ def get_values(path):
|
||||||
line_num = 0
|
line_num = 0
|
||||||
for l in f.readlines():
|
for l in f.readlines():
|
||||||
if l.startswith('#define') or continuation != None:
|
if l.startswith('#define') or continuation != None:
|
||||||
if continuation == None:
|
if continuation is None:
|
||||||
words = l.split(' ')
|
words = l.split(' ')
|
||||||
if len(words) > 2:
|
if len(words) > 2:
|
||||||
defname = words[1]
|
defname = words[1]
|
||||||
|
@ -56,7 +46,7 @@ def get_values(path):
|
||||||
else:
|
else:
|
||||||
values[continuation]['data'].append(l)
|
values[continuation]['data'].append(l)
|
||||||
# multi line define
|
# multi line define
|
||||||
if l.rstrip().endswith('\\') and continuation == None:
|
if l.rstrip().endswith('\\') and continuation is None:
|
||||||
continuation = defname
|
continuation = defname
|
||||||
# one line define
|
# one line define
|
||||||
elif not l.rstrip().endswith('\\'):
|
elif not l.rstrip().endswith('\\'):
|
||||||
|
@ -116,35 +106,54 @@ def write_changes(path, source, values):
|
||||||
with open(path, 'w') as f:
|
with open(path, 'w') as f:
|
||||||
f.write(''.join(file_lines))
|
f.write(''.join(file_lines))
|
||||||
|
|
||||||
new_chconf_values = get_values(new_chconf)
|
|
||||||
new_nilconf_values = get_values(new_nilconf)
|
|
||||||
new_halconf_values = get_values(new_halconf)
|
|
||||||
|
|
||||||
chconf_files = find('chconf.h', args.path)
|
if __name__ == '__main__':
|
||||||
halconf_files = find('halconf.h', args.path)
|
|
||||||
|
parser = argparse.ArgumentParser(description='Project upgrade script for ChibiOS')
|
||||||
|
parser.add_argument('-p', '--path', dest='path', help='Where project files are located', required=True)
|
||||||
|
parser.add_argument('-c', '--chibios', dest='chpath', help='Where ChibiOS is located', required=True)
|
||||||
|
parser.add_argument('-v', '--verbose', dest='verbose', action='store_true')
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
verbose = args.verbose
|
||||||
|
|
||||||
|
if not os.path.exists(args.chpath):
|
||||||
|
print('Invalid Chibios path', args.chpath)
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
new_chconf = os.path.abspath('{}/os/rt/templates/chconf.h'.format(args.chpath))
|
||||||
|
new_nilconf = os.path.abspath('{}/os/nil/templates/chconf.h'.format(args.chpath))
|
||||||
|
new_halconf = os.path.abspath('{}/os/hal/templates/halconf.h'.format(args.chpath))
|
||||||
|
|
||||||
|
new_chconf_values = get_values(new_chconf)
|
||||||
|
new_nilconf_values = get_values(new_nilconf)
|
||||||
|
new_halconf_values = get_values(new_halconf)
|
||||||
|
|
||||||
|
chconf_files = find('chconf.h', args.path)
|
||||||
|
halconf_files = find('halconf.h', args.path)
|
||||||
|
|
||||||
|
for c in chconf_files:
|
||||||
|
values = get_values(c)
|
||||||
|
if verbose:
|
||||||
|
print(c)
|
||||||
|
for k, v in values.items():
|
||||||
|
print(k, v)
|
||||||
|
if is_nil(c):
|
||||||
|
new_format = new_nilconf_values.copy()
|
||||||
|
set_values(values, new_format)
|
||||||
|
write_changes(c, new_nilconf, new_format)
|
||||||
|
else:
|
||||||
|
new_format = new_chconf_values.copy()
|
||||||
|
set_values(values, new_format)
|
||||||
|
write_changes(c, new_chconf, new_format)
|
||||||
|
|
||||||
|
for h in halconf_files:
|
||||||
|
values = get_values(h)
|
||||||
|
if verbose:
|
||||||
|
print(h)
|
||||||
|
for k, v in values.items():
|
||||||
|
print(k, v)
|
||||||
|
new_format = new_halconf_values.copy()
|
||||||
|
|
||||||
for c in chconf_files:
|
|
||||||
values = get_values(c)
|
|
||||||
if verbose:
|
|
||||||
print(c)
|
|
||||||
for k, v in values.items():
|
|
||||||
print(k, v)
|
|
||||||
if is_nil(c):
|
|
||||||
new_format = new_nilconf_values.copy()
|
|
||||||
set_values(values, new_format)
|
set_values(values, new_format)
|
||||||
write_changes(c, new_nilconf, new_format)
|
write_changes(h, new_halconf, new_format)
|
||||||
else:
|
|
||||||
new_format = new_chconf_values.copy()
|
|
||||||
set_values(values, new_format)
|
|
||||||
write_changes(c, new_chconf, new_format)
|
|
||||||
|
|
||||||
for h in halconf_files:
|
|
||||||
values = get_values(h)
|
|
||||||
if verbose:
|
|
||||||
print(h)
|
|
||||||
for k, v in values.items():
|
|
||||||
print(k, v)
|
|
||||||
new_format = new_halconf_values.copy()
|
|
||||||
|
|
||||||
set_values(values, new_format)
|
|
||||||
write_changes(h, new_halconf, new_format)
|
|
Loading…
Reference in New Issue