from __future__ import print_function
import os
import sys
import subprocess
mRoot = "."
if len(sys.argv) > 1:
mRoot = sys.argv[1]
binPrefix = os.path.join(
os.path.dirname(os.path.abspath(__file__)), '..', 'bin', 'net')
for root, dirs, files in os.walk(mRoot):
if ".svn" in dirs:
dirs.remove(".svn")
for file in files:
if file.endswith(".netccfg") or file.endswith(".netgcfg"):
exe = binPrefix + "generate"
if file.endswith(".netccfg"):
exe = binPrefix + "convert"
print("----------------------------------")
print("Rebuilding config: " + os.path.join(root, file))
sys.stdout.flush()
curDir = os.getcwd()
os.chdir(root)
subprocess.call([exe, "--save-configuration", file +
".tmp", "-c", file], stdout=sys.stdout, stderr=sys.stderr)
sys.stdout.flush()
os.remove(file)
os.rename(file + ".tmp", file)
os.chdir(curDir)
print("Running: " + file)
sys.stdout.flush()
subprocess.call(
[exe, "-v", "-c", os.path.join(root, file)], stdout=sys.stdout, stderr=sys.stderr)
sys.stdout.flush()
print("----------------------------------\n")