From ebb95b902cdd55b11977f37356d863de27fc18f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Fri, 14 Feb 2020 20:39:50 +0100 Subject: [PATCH] Add python script that creates matching c and h files --- stm-firmware/create-c-file-with-header.py | 59 +++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100755 stm-firmware/create-c-file-with-header.py diff --git a/stm-firmware/create-c-file-with-header.py b/stm-firmware/create-c-file-with-header.py new file mode 100755 index 0000000..f8bc191 --- /dev/null +++ b/stm-firmware/create-c-file-with-header.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python3 + +import os +import sys + +license_header = """/* Reflow Oven Controller + * + * Copyright (C) 2020 Mario Hüttel + * + * This file is part of the reflow Oven Controller Project. + * + * The reflow oven controller is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * GDSII-Converter is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GDSII-Converter. If not, see . + */ +""" + +project_dir = os.path.dirname(os.path.realpath(__file__)) +include_prefix = 'reflow-controller' +module_include_dir = os.path.join(project_dir, os.path.join('include', include_prefix)) + +if len(sys.argv) < 2: + print('Supply module name') + sys.exit() + +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()+'__' + +if os.path.exists(cpath) or os.path.exists(hpath): + print("File already exists! Abort!") + sys.exit() + +print('Creating C file: %s' % (cpath)) +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)) +with open(hpath, 'x') as f: + f.write(license_header) + f.write('\n') + f.write('#ifndef %s\n' % h_define) + f.write('#define %s\n' % h_define) + f.write('\n') + f.write('#endif /* %s */\n' % h_define) + +