forked from KhronosGroup/OpenXR-Tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheoc-archs-rm-tags.py
53 lines (42 loc) · 1.11 KB
/
eoc-archs-rm-tags.py
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
# Copyright 2023, The Khronos Group Inc.
#
# SPDX-License-Identifier: Apache-2.0
#https://stackoverflow.com/questions/44977441/delete-line-from-text-file-if-line-contains-one-of-few-specified-strings-python
import os
import sys
import getopt
def StringIsFoundInLine(line, strings):
return any([string in line for string in strings])
def main(argv):
filepath=""
opts, args = getopt.getopt(argv, "hf:")
for opt, arg in opts:
if opt == "-h":
print("usage: eoc-archs-rm-tags.py -f <filepath>")
sys.exit(0)
elif opt in "-f":
filepath = arg
else:
continue
if not filepath:
print("ERROR: No filepath provide in the command line arguments.")
sys.exit(0)
else:
filepath = os.path.abspath(filepath.strip())
newLines = []
tags = ["XR_DOCS_TAG_"]
file = open(filepath, "r")
for line in file:
if StringIsFoundInLine(line, tags):
continue
else:
newLines.append(line)
file.close()
filepath_temp = filepath + ".tmp"
w_file = open(filepath_temp, "w")
w_file.writelines(newLines)
w_file.close()
os.remove(filepath)
os.rename(filepath_temp, filepath)
if __name__ == "__main__":
main(sys.argv[1:])