-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsmake.py
More file actions
200 lines (161 loc) · 6.92 KB
/
Copy pathsmake.py
File metadata and controls
200 lines (161 loc) · 6.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#!/usr/bin/env python
#*****************************************************************************
# ______ _ ___ ___ _
# | ___ \(_) | \/ | | |
# | |_/ / _ _ __ __ _ _ __ _ _ | . . | __ _ | | __ ___ _ __
# | ___ \| || '_ \ / _` || '__|| | | | | |\/| | / _` || |/ // _ \| '__|
# | |_/ /| || | | || (_| || | | |_| | | | | || (_| || <| __/| |
# \____/ |_||_| |_| \__,_||_| \__, | \_| |_/ \__,_||_|\_\\___||_|
# __/ |
# |___/
#
# Copyright (C) 2019 Binary Maker - All Rights Reserved
#
# This program and the accompanying materials are made available
# under the terms described in the LICENSE file which accompanies
# this distribution.
# Written by Binary Maker <https://github.com/binarymaker>
#*****************************************************************************
import argparse, uuid
from os import path
from datetime import date
year = str(date.today().year)
copyright_tmpl = \
"""/**\cond
******************************************************************************
* ______ _ ___ ___ _
* | ___ \(_) | \/ | | |
* | |_/ / _ _ __ __ _ _ __ _ _ | . . | __ _ | | __ ___ _ __
* | ___ \| || '_ \ / _` || '__|| | | | | |\/| | / _` || |/ // _ \| '__|
* | |_/ /| || | | || (_| || | | |_| | | | | || (_| || <| __/| |
* \____/ |_||_| |_| \__,_||_| \__, | \_| |_/ \__,_||_|\_\\\\___||_|
* __/ |
* |___/
*
* Copyright (C) """ + year + """ Binary Maker - All Rights Reserved
*
* This program and the accompanying materials are made available
* under the terms described in the LICENSE file which accompanies
* this distribution.
* Written by Binary Maker <https://github.com/binarymaker>
******************************************************************************
\endcond*/
"""
header_incl_tmpl = \
"""
#ifndef %(filename)s_%(uuid)s
#define %(filename)s_%(uuid)s
#ifdef __cplusplus
extern "C" {
#endif
/**
* \\brief Source file version tag
*
* version info: [15:8] main [7:0] beta
*/
#define __%(filename)s_VERSION (0x0001u)
/* Includes ------------------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* Exported macro ------------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
#ifdef __cplusplus
}
#endif
#endif /* %(filename)s_%(uuid)s */
"""
source_tmpl = \
"""
/* Includes ------------------------------------------------------------------*/
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
"""
config_incl_tmpl = \
"""
#ifndef %(filename)s_%(uuid)s
#define %(filename)s_%(uuid)s
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* Exported macro ------------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
#ifdef __cplusplus
}
#endif
#endif /* %(filename)s_%(uuid)s */
"""
def h_create (file_handle, fname):
file_handle.write (copyright_tmpl)
file_handle.write (header_incl_tmpl %
({'uuid': str(uuid.uuid1()).replace('-','_'),
'filename': str(fname).upper().replace('-','_')}),)
file_handle.close ()
def cfg_create (file_handle, fname):
file_handle.write (copyright_tmpl)
file_handle.write (config_incl_tmpl %
({'uuid': str(uuid.uuid1()).replace('-','_'),
'filename': str(fname).upper().replace('-','_')}),)
file_handle.close ()
def src_create (file_handle):
file_handle.write (copyright_tmpl)
file_handle.write (source_tmpl)
file_handle.close ()
def main():
parser = argparse.ArgumentParser (
prog="smake", description="C/C++ source and header file generation tool")
parser.add_argument ("-f", "--file-name",
help="C/C++ header/source file name",
type=str, required=True)
parser.add_argument ("-d", "--directory",
help="C/C++ header/source create directory",
type=str, required=False)
parser.add_argument ("-s", "--smart",
help="C/C++ header/source create in source and config",
type=str, required=False)
args = vars(parser.parse_args ())
if args['directory'] is not None:
path_src = args['directory'] + '/' + args['file_name']
path_cfg = path_src
elif args['smart'] is not None:
path_src = args['smart'] + '/' + 'source' + '/' + args['file_name']
path_cfg = args['smart'] + '/' + 'config' + '/' + args['file_name']
else:
path_src = args['file_name']
path_cfg = path_src
src_path = (path_src+'.c')
if(path.exists(src_path)):
print("file exists", src_path)
else:
c_file = open(src_path,'w')
src_create(c_file)
print("file create", src_path)
src_path = (path_src+'.h')
if(path.exists(src_path)):
print("file exists", src_path)
else:
h_file = open(src_path,'w')
h_create(h_file, args['file_name'])
print("file create", src_path)
src_path = (path_cfg + '-cfg.h')
if(path.exists(src_path)):
print("file exists", src_path)
else:
cfg_file = open(src_path,'w')
cfg_create(cfg_file, args['file_name'])
print("file create", src_path)
src_path = (path_cfg + '-cfg.c')
if(path.exists(src_path)):
print("file exists", src_path)
else:
cfg_src_file = open(src_path,'w')
src_create(cfg_src_file)
print("file create", src_path)
if __name__ == "__main__":
main ()