-
Notifications
You must be signed in to change notification settings - Fork 15
Open
Description
Possible script for automatic replacing
#!/usr/bin/env python3
import os
import re
import sys
assert sys.version_info >= (3, 5)
#######################################################
def process_file(filepath):
print("** processing file {}".format(filepath))
content = open(filepath,'r').read()
lines = content.split('\n')
newlines = list()
for line in lines:
res = re.search(r"#ifndef __OPENFLUID_.*_HPP__",line)
if res:
#print("Remove line : {}".format(line))
pass
else:
res = re.search(r"#define __OPENFLUID_.*_HPP__",line)
if res:
#print("Replace line : {}".format(line))
newlines.append("#pragma once")
else:
res = re.search(r"#endif .+ __OPENFLUID_.*_HPP__.+",line)
if res:
#print("Remove line : {}".format(line))
pass
else:
newlines.append(line)
#print("\n".join(newlines))
open(filepath,'w').write("\n".join(newlines))
#######################################################
paths_to_explore = ["src"]
files_to_process = list()
for path in paths_to_explore:
print(path)
for dirname, dirnames, filenames in os.walk(path):
for filename in filenames:
filepath = os.path.join(dirname,filename)
if os.path.isfile(filepath) and (filepath.endswith(".hpp") or filepath.endswith(".hpp.in")):
files_to_process.append(filepath)
for file in files_to_process:
process_file(file)