Add support for subdirectories in create-c-file script

This commit is contained in:
Mario Hüttel 2020-04-26 20:20:57 +02:00
parent 2d3b61550b
commit cf3818040c

View File

@ -2,6 +2,7 @@
import os import os
import sys import sys
import pathlib
license_header = """/* Reflow Oven Controller license_header = """/* Reflow Oven Controller
* *
@ -22,7 +23,6 @@ license_header = """/* Reflow Oven Controller
* along with the reflow oven controller project. * along with the reflow oven controller project.
* If not, see <http://www.gnu.org/licenses/>. * If not, see <http://www.gnu.org/licenses/>.
*/ */
""" """
project_dir = os.path.dirname(os.path.realpath(__file__)) 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' hfile = sys.argv[1]+'.h'
hpath = os.path.join(module_include_dir, hfile) 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): if os.path.exists(cpath) or os.path.exists(hpath):
print("File already exists! Abort!") print("File already exists! Abort!")
sys.exit() sys.exit()
print('Creating C file: %s' % (cpath)) 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: with open(cpath, 'x') as f:
f.write(license_header) f.write(license_header)
f.write('\n') f.write('\n')
f.write('#include <%s>' % (os.path.join(include_prefix, hfile))) f.write('#include <%s>' % (os.path.join(include_prefix, hfile)))
print('Creating H file: %s' % (hpath)) 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: with open(hpath, 'x') as f:
f.write(license_header) f.write(license_header)
f.write('\n') f.write('\n')