#!/usr/bin/env python3 import os import sys import pathlib 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. * * The Reflow Oven Control Firmware 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 the reflow oven controller project. * 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('-', '_').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') f.write('#ifndef %s\n' % h_define) f.write('#define %s\n' % h_define) f.write('\n') f.write('#endif /* %s */\n' % h_define)