new remove_grandfathered
Browse filesSigned-off-by: Balazs Horvath <acsipont@gmail.com>
- utils/remove_grandfathered.py +18 -34
utils/remove_grandfathered.py
CHANGED
@@ -1,42 +1,26 @@
|
|
1 |
#!/usr/bin/env python
|
2 |
# -*- coding: utf-8 -*-
|
3 |
-
#
|
4 |
-
import os
|
5 |
-
import sys
|
6 |
-
# Add the parent directory to the Python path
|
7 |
-
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
8 |
-
|
9 |
-
from utils.file_processor import FileProcessor, ProcessorOptions
|
10 |
-
import re
|
11 |
-
from pathlib import Path
|
12 |
|
13 |
-
|
14 |
-
def __init__(self, options: ProcessorOptions, pattern: str):
|
15 |
-
super().__init__(options)
|
16 |
-
self.pattern = pattern
|
17 |
-
|
18 |
-
def process_content(self, content: str) -> str:
|
19 |
-
# Remove occurrences of the grandfathered content pattern
|
20 |
-
content = re.sub(self.pattern, '', content)
|
21 |
-
# Normalize whitespace and commas
|
22 |
-
content = re.sub(r'\s+,', ',', content)
|
23 |
-
content = re.sub(r',\s+', ',', content)
|
24 |
-
return re.sub(r'\s+', ' ', content).strip()
|
25 |
|
26 |
-
def
|
27 |
-
|
|
|
28 |
|
29 |
-
|
30 |
-
recursive=True,
|
31 |
-
dry_run=False,
|
32 |
-
file_extensions={'.txt', '.tags'}
|
33 |
-
)
|
34 |
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
|
|
|
|
|
|
40 |
|
41 |
if __name__ == "__main__":
|
42 |
-
|
|
|
|
|
|
|
|
1 |
#!/usr/bin/env python
|
2 |
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
+
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
+
def remove_text_from_file(file_path, text_to_remove):
|
7 |
+
with open(file_path, 'r') as file:
|
8 |
+
content = file.read()
|
9 |
|
10 |
+
content = content.replace(text_to_remove, "")
|
|
|
|
|
|
|
|
|
11 |
|
12 |
+
with open(file_path, 'w') as file:
|
13 |
+
file.write(content)
|
14 |
+
|
15 |
+
def remove_text_from_files(root_dir, text_to_remove):
|
16 |
+
for subdir, _, files in os.walk(root_dir):
|
17 |
+
for file in files:
|
18 |
+
if file.endswith('.txt') or file.endswith('.tags'):
|
19 |
+
file_path = os.path.join(subdir, file)
|
20 |
+
remove_text_from_file(file_path, text_to_remove)
|
21 |
|
22 |
if __name__ == "__main__":
|
23 |
+
root_directory = '.' # Change this to your root directory
|
24 |
+
text_to_remove = "grandfathered content, "
|
25 |
+
remove_text_from_files(root_directory, text_to_remove)
|
26 |
+
|