reflow-oven-control-sw/stm-firmware/create-c-file-with-header.py

66 lines
2.0 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
import os
import sys
import pathlib
license_header = """/* Reflow Oven Controller
2020-02-15 22:09:55 +01:00
*
2022-09-22 21:16:07 +02:00
* Copyright (C) 2022 Mario Hüttel <mario.huettel@gmx.net>
2020-02-15 22:09:55 +01:00
*
* 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,
2020-02-15 22:09:55 +01:00
* 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 <http://www.gnu.org/licenses/>.
*/
"""
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)
2022-09-22 21:16:07 +02:00
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)