Skip to content

Commit fa19646

Browse files
committed
[STAGE] Finished check_author and started check_norme
1 parent 70b5f0f commit fa19646

1 file changed

Lines changed: 50 additions & 7 deletions

File tree

42PyChecker.py

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,63 @@
11
import os
22
import sys
3-
import subprocess
3+
import glob
44

55
def check_author_file(project_path: str):
6+
"""
7+
:param project_path: The path of the project where you want to check the author file
8+
9+
:return: This function will return 0 if everything is ok,
10+
1 if file not found,
11+
2 if there's too many lines in the file,
12+
3 if the newline char is missing in the end of line
13+
"""
614
# @todo: Add a skip if author file set as optional
715
author_fr = project_path + "/auteur"
816
author_us = project_path + "/author"
917
if os.path.exists(author_fr):
10-
output = subprocess.check_output("awk 'END {printf NR}' " + author_fr, shell=True)
18+
count = len(open(author_fr).readlines())
19+
author = "fr"
1120
elif os.path.exists(author_us):
12-
output = subprocess.check_output("awk 'END {printf NR}' " + author_us, shell=True)
21+
count = len(open(author_us).readlines())
22+
author = "us"
1323
else:
1424
print("Author file not found")
15-
sys.exit() # @todo Add message if author file is set as optional
16-
if output != 1:
25+
return 1 # @todo Add message if author file is set as optional
26+
if count != 1:
1727
print("Too many lines in author file (Or the file is empty)")
18-
sys.exit() # @todo Add message if author file is set as optional or if project isn't solo
28+
return 2 # @todo Add message if author file is set as optional or if project isn't solo
29+
if author == "fr":
30+
with open(author_fr, 'r') as file:
31+
content = file.read()
32+
if "\n" not in content:
33+
print("Missing <newline> character at the end of line")
34+
return 3 # @todo: Add message if author file is set as optional and handle multiple authors
35+
elif author == "us":
36+
with open(author_us, 'r') as file:
37+
content = file.read()
38+
if "\n" not in content:
39+
print("Missing <newline> character at the end of line")
40+
return 3 # @todo: Add message if author file is set as optional and handle multiple authors
41+
return 0
42+
43+
44+
def check_norme(project_path: str):
45+
"""
46+
:param project_path: The path of the project where you want to check the author file
47+
48+
:return: Returns 0 if everything is ok,
49+
1 if there isn't any file to check
50+
"""
51+
# @todo: Add a skip if norme is set as optional
52+
files = ""
53+
with open(os.path.dirname(os.path.realpath(__file__)) + "/.mynorme", 'w+') as file:
54+
for filename in glob.iglob(project_path + '/**/*.c', recursive=True):
55+
files = files + ' ' + filename
56+
for filename in glob.iglob(project_path + '/**/*.h', recursive=True):
57+
files = files + ' ' + filename
58+
if file == "":
59+
print("No source file (.c) or header (.h) to check")
60+
return 1
61+
1962

20-
check_author_file("C:/Users/Jules/PycharmProjects/42PyChecker")
63+
sys.exit(check_norme("C:/Users/Jules/Share/ft_printf"))

0 commit comments

Comments
 (0)