2020-02-14 20:39:50 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
2020-04-26 20:20:57 +02:00
|
|
|
import pathlib
|
2020-02-14 20:39:50 +01:00
|
|
|
|
|
|
|
license_header = """/* Reflow Oven Controller
|
2020-02-15 22:09:55 +01:00
|
|
|
*
|
|
|
|
* Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2020-02-21 21:22:01 +01:00
|
|
|
* 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/>.
|
|
|
|
*/
|
2020-02-14 20:39:50 +01:00
|
|
|
"""
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
2020-04-26 20:20:57 +02:00
|
|
|
h_define = '__'+hfile.replace('.', '_').replace('-', '_').replace('/', '_').upper()+'__'
|
2020-02-14 20:39:50 +01:00
|
|
|
|
|
|
|
if os.path.exists(cpath) or os.path.exists(hpath):
|
|
|
|
print("File already exists! Abort!")
|
|
|
|
sys.exit()
|
|
|
|
|
|
|
|
print('Creating C file: %s' % (cpath))
|
2020-04-26 20:20:57 +02:00
|
|
|
cfile_folder = os.path.dirname(cpath)
|
|
|
|
pathlib.Path(cfile_folder).mkdir(parents=True, exist_ok=True)
|
2020-02-14 20:39:50 +01:00
|
|
|
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))
|
2020-04-26 20:20:57 +02:00
|
|
|
hfile_folder = os.path.dirname(hpath)
|
|
|
|
pathlib.Path(hfile_folder).mkdir(parents=True, exist_ok=True)
|
2020-02-14 20:39:50 +01:00
|
|
|
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)
|
|
|
|
|
|
|
|
|