mirror of
https://github.com/phodina/ProjectConverter.git
synced 2026-04-30 19:09:16 +08:00
Fixed file generation on Windows platfrom. Added support for .cpp files. Refactored argument parsing.
This commit is contained in:
parent
1016115be1
commit
38a23235c9
23
cmake.py
23
cmake.py
@ -60,7 +60,7 @@ class CMake (object):
|
|||||||
cmake['ass']=[]
|
cmake['ass']=[]
|
||||||
|
|
||||||
for file in self.project['srcs']:
|
for file in self.project['srcs']:
|
||||||
if file.endswith('.c') or file.endswith('.h'):
|
if file.endswith('.c') or file.endswith('.h') or file.endswith('.cpp'):
|
||||||
cmake['files'].append({'path': file,'var':'SRC_FILE' + str(i)})
|
cmake['files'].append({'path': file,'var':'SRC_FILE' + str(i)})
|
||||||
i = i+1
|
i = i+1
|
||||||
|
|
||||||
@ -92,9 +92,10 @@ class CMake (object):
|
|||||||
|
|
||||||
self.context['cmake'] = cmake
|
self.context['cmake'] = cmake
|
||||||
|
|
||||||
self.generateFile('CMakeLists.txt',os.path.join(self.path,'CMakeLists.txt'))
|
abspath = os.path.abspath(os.path.join(self.path,'CMakeLists.txt'))
|
||||||
|
self.generateFile('CMakeLists.txt', abspath)
|
||||||
|
|
||||||
print ('Created file CMakeLists.txt')
|
print ('Created file CMakeLists.txt [{}]'.format(abspath))
|
||||||
|
|
||||||
# def generateFile (self, pathSrc, pathDst='', author='Pegasus', version='v1.0.0', licence='licence.txt', template_dir='../PegasusTemplates'):
|
# def generateFile (self, pathSrc, pathDst='', author='Pegasus', version='v1.0.0', licence='licence.txt', template_dir='../PegasusTemplates'):
|
||||||
def generateFile (self, pathSrc, pathDst='', author='Pegasus', version='v1.0.0', licence='licence.txt', template_dir='.'):
|
def generateFile (self, pathSrc, pathDst='', author='Pegasus', version='v1.0.0', licence='licence.txt', template_dir='.'):
|
||||||
@ -113,15 +114,15 @@ class CMake (object):
|
|||||||
|
|
||||||
generated_code = template.render(self.context)
|
generated_code = template.render(self.context)
|
||||||
|
|
||||||
if platform.system() == 'Window':
|
if platform.system() == 'Windows':
|
||||||
|
|
||||||
with open(pathDst, 'wb') as f:
|
with open(pathDst, 'w') as f:
|
||||||
f.write(generated_code)
|
f.write(generated_code)
|
||||||
|
|
||||||
elif platform.system() == 'Linux':
|
elif platform.system() == 'Linux':
|
||||||
|
|
||||||
with open(pathDst, 'wb') as f:
|
with open(pathDst, 'w') as f:
|
||||||
f.write(str.encode(generated_code))
|
f.write(generated_code)
|
||||||
else:
|
else:
|
||||||
# Different OS than Windows or Linux
|
# Different OS than Windows or Linux
|
||||||
pass
|
pass
|
||||||
@ -141,15 +142,15 @@ class CMake (object):
|
|||||||
|
|
||||||
generated_code = template.render(self.context)
|
generated_code = template.render(self.context)
|
||||||
|
|
||||||
if platform.system() == 'Window':
|
if platform.system() == 'Windows':
|
||||||
|
|
||||||
with open(pathDst, 'wb') as f:
|
with open(pathDst, 'w') as f:
|
||||||
f.write(generated_code)
|
f.write(generated_code)
|
||||||
|
|
||||||
elif platform.system() == 'Linux':
|
elif platform.system() == 'Linux':
|
||||||
|
|
||||||
with open(pathDst, 'wb') as f:
|
with open(pathDst, 'w') as f:
|
||||||
f.write(str.encode(generated_code))
|
f.write(generated_code)
|
||||||
else:
|
else:
|
||||||
# Different OS than Windows or Linux
|
# Different OS than Windows or Linux
|
||||||
pass
|
pass
|
||||||
|
|||||||
11
converter.py
11
converter.py
@ -27,13 +27,14 @@ if __name__ == '__main__':
|
|||||||
""" Parses params and calls the right conversion"""
|
""" Parses params and calls the right conversion"""
|
||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument("format", choices=("ewp", "uvprojx"))
|
||||||
parser.add_argument("path", type=str, help="Root directory of project")
|
parser.add_argument("path", type=str, help="Root directory of project")
|
||||||
parser.add_argument("--ewp", help="Search for *.EWP file in project structure", action='store_true')
|
#"--ewp", help="Search for *.EWP file in project structure", action='store_true')
|
||||||
parser.add_argument("--uvprojx", help="Search for *.UPROJX file in project structure", action='store_true')
|
#parser.add_argument("--uvprojx", help="Search for *.UPROJX file in project structure", action='store_true')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
if os.path.isdir(args.path):
|
if os.path.isdir(args.path):
|
||||||
if args.ewp:
|
if args.format == 'ewp':
|
||||||
print('Looking for *.ewp file in ' + args.path)
|
print('Looking for *.ewp file in ' + args.path)
|
||||||
filename = find_file(args.path, '.ewp')
|
filename = find_file(args.path, '.ewp')
|
||||||
if len(filename):
|
if len(filename):
|
||||||
@ -45,7 +46,7 @@ if __name__ == '__main__':
|
|||||||
cmakefile.populateCMake()
|
cmakefile.populateCMake()
|
||||||
else:
|
else:
|
||||||
print('No project *.ewp file found')
|
print('No project *.ewp file found')
|
||||||
elif args.uvprojx:
|
elif args.format == 'uvprojx':
|
||||||
print('Looking for *.uvprojx file in ' + args.path)
|
print('Looking for *.uvprojx file in ' + args.path)
|
||||||
filename = find_file(args.path, '.uvprojx')
|
filename = find_file(args.path, '.uvprojx')
|
||||||
if len(filename):
|
if len(filename):
|
||||||
@ -58,5 +59,7 @@ if __name__ == '__main__':
|
|||||||
cmakefile.populateCMake()
|
cmakefile.populateCMake()
|
||||||
else:
|
else:
|
||||||
print('No project *.uvprojx file found')
|
print('No project *.uvprojx file found')
|
||||||
|
else:
|
||||||
|
print ('No format specified')
|
||||||
else:
|
else:
|
||||||
print('Not a valid file path')
|
print('Not a valid file path')
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user