-
-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
elecpower
committed
Jan 19, 2024
1 parent
fb3a87a
commit 05c79a2
Showing
2 changed files
with
63 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import argparse | ||
import glob | ||
from os import path | ||
|
||
def main(jsondir, template, placeholder, output): | ||
if not path.isdir(jsondir): | ||
raise Exception(jsondir + " is not a directory") | ||
|
||
try: | ||
tmplt = open(template, "r") | ||
except: | ||
raise Exception("Unable to open template file " + template) | ||
|
||
try: | ||
qrc = open(output, "w") | ||
except: | ||
raise Exception("Unable to open " + output + " for writing") | ||
|
||
line = tmplt.readline() | ||
|
||
while placeholder not in line and line != '': | ||
qrc.write(line) | ||
line = tmplt.readline() | ||
|
||
for f in sorted(glob.iglob(path.join(jsondir, '*.json'), recursive = False)): | ||
fname = path.basename(f) | ||
qrc.write(' <file alias="' + fname + '">' + f + '</file>' + '\n') | ||
|
||
line = tmplt.readline() | ||
|
||
while line != '': | ||
qrc.write(line) | ||
line = tmplt.readline() | ||
|
||
tmplt.close() | ||
qrc.close() | ||
|
||
|
||
if __name__ == "__main__": | ||
|
||
parser = argparse.ArgumentParser(description='Generate hardware definitions resource file') | ||
parser.add_argument('-d', metavar='json files directory', required=True) | ||
parser.add_argument('-t', metavar='template file', required=True) | ||
parser.add_argument('-p', metavar='placeholder', required=True) | ||
parser.add_argument('-o', metavar='qrc file', required=True) | ||
|
||
args = parser.parse_args() | ||
|
||
main(args.d, args.t, args.p, args.o) |