-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTODO_scanner.py
83 lines (66 loc) · 2.99 KB
/
TODO_scanner.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# TODO_scanner.py
# SOURCE
import time
import os
import csv
import shutil
from os import environ, path
from dotenv import load_dotenv
import TODO_scanner
load_dotenv()
def main():
scan_todo_tags()
def scan_todo_tags():
"""creates a CSV file named todo_tags.csv under the data/ folder and writes the following information for each TODO tag found
:param file_name: The name of the file containing the TODO tag
:param project_name: The name of the project (which is the same as the file
name without the .py extension)
:param tag_FOUND: The TODO tag found (e.g., TODO, FIXME, #TODO)
:param tag_message: The message following the TODO tag
:param date_added: The date the TODO tag was added to the file (using the file's creation time)
:param USER_NAME: The username of the user running the script (using the os.environ.get('USER_NAME') function call)
:param
"""
cwd = os.getcwd()
os.environ.get("USER_NAME")
project_path = "/Users/{USER_NAME}/sbox/PycharmProjects/SQL_Template/"
# Create the CSV file and write the header
with open("data/todo_tags.csv", "w", newline="") as csvfile:
writer = csv.writer(csvfile)
writer.writerow(
["file_name", "project_name", "tag_FOUND", "tag_message", "date_added", "user"]
)
# Loop through all files in the current directory
for file_name in os.listdir(cwd):
# Only check Python files
if file_name.endswith(".py"):
# Get the project name
project_name = file_name.split(".")[0]
# Open the file and loop through each line
with open(file_name, "r") as f:
for i, line in enumerate(f):
# Check for TODO tags
if "TODO" in line or "FIXME" in line or "#TODO" in line:
# Get the tag message and date added
tag_message = line.strip()
date_added = os.path.getctime(file_name)
# Write the information to the CSV file
writer.writerow(
[
file_name,
project_name,
line[: line.find(tag_message)],
tag_message,
date_added,
os.environ.get("USERNAME"),
]
)
if __name__ == "__main__":
USER_NAME = environ.get("USER_NAME")
DIRECTORY_PATH = f"/Users/" f"{USER_NAME}/sbox/PycharmProjects/SQL_Template/data/"
DESTINATION_PATH = f"/Users/{USER_NAME}/sbox/PycharmProjects/SQL_Template/data/processed/"
PROJECT_PATH = f"/Users/{USER_NAME}/sbox/PycharmProjects/SQL_Template/"
# Find .env file
basedir = path.abspath(path.dirname(__file__))
load_dotenv(path.join(basedir, ".env"))
main()