From cf3818040c6a5d339d725480cc615cf1586f016f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Sun, 26 Apr 2020 20:20:57 +0200 Subject: [PATCH] Add support for subdirectories in create-c-file script --- stm-firmware/create-c-file-with-header.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/stm-firmware/create-c-file-with-header.py b/stm-firmware/create-c-file-with-header.py index 67176c1..5ad8c48 100755 --- a/stm-firmware/create-c-file-with-header.py +++ b/stm-firmware/create-c-file-with-header.py @@ -2,6 +2,7 @@ import os import sys +import pathlib license_header = """/* Reflow Oven Controller * @@ -22,7 +23,6 @@ license_header = """/* Reflow Oven Controller * along with the reflow oven controller project. * If not, see . */ - """ project_dir = os.path.dirname(os.path.realpath(__file__)) @@ -37,19 +37,23 @@ cpath = os.path.join(project_dir, sys.argv[1]+'.c') hfile = sys.argv[1]+'.h' hpath = os.path.join(module_include_dir, hfile) -h_define = '__'+hfile.replace('.', '_').replace('-', '_').upper()+'__' +h_define = '__'+hfile.replace('.', '_').replace('-', '_').replace('/', '_').upper()+'__' if os.path.exists(cpath) or os.path.exists(hpath): print("File already exists! Abort!") sys.exit() print('Creating C file: %s' % (cpath)) +cfile_folder = os.path.dirname(cpath) +pathlib.Path(cfile_folder).mkdir(parents=True, exist_ok=True) with open(cpath, 'x') as f: f.write(license_header) f.write('\n') f.write('#include <%s>' % (os.path.join(include_prefix, hfile))) print('Creating H file: %s' % (hpath)) +hfile_folder = os.path.dirname(hpath) +pathlib.Path(hfile_folder).mkdir(parents=True, exist_ok=True) with open(hpath, 'x') as f: f.write(license_header) f.write('\n')