Skip to content

Commit 052166f

Browse files
Fix issue in genfiles.py + add help text
1 parent 96bddde commit 052166f

File tree

1 file changed

+27
-3
lines changed
  • csharp/ql/test/query-tests/Security Features/CWE-079/XSSRazorPages

1 file changed

+27
-3
lines changed

csharp/ql/test/query-tests/Security Features/CWE-079/XSSRazorPages/gen_files.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
import sys
44
import os
55

6-
work_dir = os.path.dirname(sys.argv[0])
6+
work_dir = os.path.abspath(os.path.dirname(sys.argv[0]))
77
gen_dir = f"{work_dir}/Generated"
88
with open(f"{gen_dir}/Template.g") as f:
99
template = f.read()
1010

11+
verbose = False
12+
1113

1214
def process_file(path: str):
1315
"""
@@ -21,9 +23,13 @@ def process_file(path: str):
2123

2224
gen = template.replace("$PATHSLASH", path).replace("$PATHUNDER", path_under)
2325

24-
with open(f"{gen_dir}/{path_under}.cshtml.g.cs", "w") as f:
26+
out_path = f"{gen_dir}/{path_under}.cshtml.g.cs"
27+
with open(out_path, "w") as f:
2528
f.write(gen)
2629

30+
if verbose:
31+
print(out_path)
32+
2733

2834
def process_dir(path: str):
2935
"""
@@ -43,4 +49,22 @@ def process_dir(path: str):
4349
process_dir(sub_rel)
4450

4551

46-
process_dir("")
52+
def print_usage():
53+
print("""Usage: python3 gen_files.py [-v] [--verbose] [-h] [--help]
54+
55+
Generates files from .cshtml files found in the directory tree of this script's parent folder, mimicking the C# compiler.
56+
`.testproj` is ignored.
57+
58+
-h, --help: Displays this message and exits.
59+
-v, --verbose: Prints the name of each file generated.""")
60+
61+
62+
if __name__ == "__main__":
63+
if "-h" in sys.argv or "--help" in sys.argv:
64+
print_usage()
65+
exit()
66+
67+
if "-v" in sys.argv or "--verbose" in sys.argv:
68+
verbose = True
69+
70+
process_dir("")

0 commit comments

Comments
 (0)