Add support for subdirectories in create-c-file script
This commit is contained in:
		@@ -2,6 +2,7 @@
 | 
			
		||||
 | 
			
		||||
import os
 | 
			
		||||
import sys
 | 
			
		||||
import pathlib
 | 
			
		||||
 | 
			
		||||
license_header = """/* Reflow Oven Controller
 | 
			
		||||
*
 | 
			
		||||
@@ -22,7 +23,6 @@ license_header = """/* Reflow Oven Controller
 | 
			
		||||
* along with the reflow oven controller project.
 | 
			
		||||
* If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
"""
 | 
			
		||||
 | 
			
		||||
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'
 | 
			
		||||
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):
 | 
			
		||||
	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')
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user