|
1 | 1 | import os |
2 | 2 | import sys |
3 | 3 | import glob |
| 4 | +import subprocess |
| 5 | + |
4 | 6 |
|
5 | 7 | def check_author_file(project_path: str): |
6 | 8 | """ |
@@ -46,18 +48,28 @@ def check_norme(project_path: str): |
46 | 48 | :param project_path: The path of the project where you want to check the author file |
47 | 49 |
|
48 | 50 | :return: Returns 0 if everything is ok, |
49 | | - 1 if there isn't any file to check |
| 51 | + 1 if there isn't any file to check, |
| 52 | + 2 if some errors/warnings were found |
50 | 53 | """ |
51 | 54 | # @todo: Add a skip if norme is set as optional |
52 | 55 | 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 == "": |
| 56 | + for filename in glob.iglob(project_path + '/**/*.c', recursive=True): |
| 57 | + files = files + ' ' + filename |
| 58 | + for filename in glob.iglob(project_path + '/**/*.h', recursive=True): |
| 59 | + files = files + ' ' + filename |
| 60 | + if files == "": |
59 | 61 | print("No source file (.c) or header (.h) to check") |
60 | 62 | return 1 |
| 63 | + with open(os.path.dirname(os.path.realpath(__file__)) + "/.mynorme", 'w+') as file: |
| 64 | + result = subprocess.run('norminette' + files, shell=True, stdout=subprocess.PIPE).stdout.decode('utf-8') |
| 65 | + file.write(result) |
| 66 | + error_count = result.count('Error') |
| 67 | + warning_count = result.count('Warning') |
| 68 | + if error_count != 0 and warning_count != 0: |
| 69 | + print("Found {} errors and {} warnings".format(error_count, warning_count)) |
| 70 | + return 2 |
| 71 | + print("Normed passed") |
| 72 | + return 0 |
61 | 73 |
|
62 | 74 |
|
63 | | -sys.exit(check_norme("C:/Users/Jules/Share/ft_printf")) |
| 75 | +sys.exit(check_norme("/Users/jlasne/Clion/libft")) |
0 commit comments