-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreatePlugin.py
More file actions
executable file
·57 lines (46 loc) · 1.71 KB
/
createPlugin.py
File metadata and controls
executable file
·57 lines (46 loc) · 1.71 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
#!/usr/bin/env python
import sys
import os
import json
def replaceString(inputStr, params):
'''
'''
outputStr = str(inputStr)
for key, value in params.iteritems():
outputStr = outputStr.replace(key.upper(), value)
return outputStr
def replaceInFile(filepath, params):
'''
'''
with open(filepath, 'r') as dataFileIn:
inputStr = dataFileIn.read()
outputStr = replaceString(inputStr, params)
if inputStr != outputStr:
with open(filepath, 'w') as dataFileOut:
dataFileOut.write(outputStr)
def renameFile(filepath, params):
'''
'''
folder, filename = os.path.split(filepath)
newFilename = replaceString(filename, params)
newFilepath = os.path.join(folder, newFilename)
if filename != newFilename:
os.rename(filepath, newFilepath)
return newFilepath
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser(description='Rename the template files to create a new OpenFX Plugin.')
parser.add_argument('params', help='JSON files with parameters')
parser.add_argument('path', help='Path to the OFX template')
args = parser.parse_args()
with open(args.params, 'r') as paramsFile:
params = json.load(paramsFile)
# print "args.params:", args.params
# print "args.path:", args.path
for root, folders, filenames in os.walk(args.path):
# do not enter into hidden folders and openfx folder
folders[:] = [folder for folder in folders if folder[0] != '.' and folder != 'openfx']
for filename in filenames:
filepath = os.path.join(root, filename)
newFilepath = renameFile(filepath, params)
replaceInFile(newFilepath, params)