never exit, always return errors to user
This commit is contained in:
parent
ec439aff69
commit
526038c7da
3 changed files with 24 additions and 24 deletions
|
@ -28,12 +28,10 @@ def clang_format(file_path: str, style: str) -> tuple[str, str]:
|
||||||
output = e.output
|
output = e.output
|
||||||
except FileNotFoundError as e:
|
except FileNotFoundError as e:
|
||||||
print(f"Commande non trouvé : {e.filename}", file=sys.stderr)
|
print(f"Commande non trouvé : {e.filename}", file=sys.stderr)
|
||||||
print(
|
raise Exception(
|
||||||
"clang est requis pour utilisé ce programme, installé-le via "
|
"clang est requis pour utilisé ce programme, installé-le via "
|
||||||
f"votre gestionnaire de paquet : {e.filename}",
|
f"votre gestionnaire de paquet : {e.filename}"
|
||||||
file=sys.stderr,
|
|
||||||
)
|
)
|
||||||
exit(1)
|
|
||||||
|
|
||||||
return file_path, output
|
return file_path, output
|
||||||
|
|
||||||
|
|
17
src/gui.py
17
src/gui.py
|
@ -1,6 +1,6 @@
|
||||||
import sys
|
|
||||||
from tkinter import Button, Frame, Label, Menu, Tk, Toplevel
|
from tkinter import Button, Frame, Label, Menu, Tk, Toplevel
|
||||||
from tkinter.filedialog import askdirectory, askopenfile
|
from tkinter.filedialog import askdirectory, askopenfile
|
||||||
|
from tkinter.messagebox import showerror
|
||||||
|
|
||||||
from src.clangformat import Style, clang_format, parse_clang_format_output
|
from src.clangformat import Style, clang_format, parse_clang_format_output
|
||||||
from src.errors import ClangError
|
from src.errors import ClangError
|
||||||
|
@ -36,8 +36,7 @@ class GUI:
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
print("Impossible de trouver le fichier", file=sys.stderr)
|
showerror(f"Erreur - {self.name}", "Impossible de trouver le fichier")
|
||||||
exit(1)
|
|
||||||
else:
|
else:
|
||||||
if chemin:
|
if chemin:
|
||||||
self.current_location = chemin.name
|
self.current_location = chemin.name
|
||||||
|
@ -47,8 +46,7 @@ class GUI:
|
||||||
try:
|
try:
|
||||||
chemin = askdirectory()
|
chemin = askdirectory()
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
print("Impossible de trouver le dossier", file=sys.stderr)
|
showerror(f"Erreur - {self.name}", "Impossible de trouver le dossier")
|
||||||
exit(1)
|
|
||||||
else:
|
else:
|
||||||
self.current_location = chemin
|
self.current_location = chemin
|
||||||
return self._analyse(start, chemin)
|
return self._analyse(start, chemin)
|
||||||
|
@ -131,10 +129,19 @@ class GUI:
|
||||||
|
|
||||||
def _analyse(self, start_row: int, path: str) -> None:
|
def _analyse(self, start_row: int, path: str) -> None:
|
||||||
"""Analyse les données"""
|
"""Analyse les données"""
|
||||||
|
try:
|
||||||
files = analyze_args([path])
|
files = analyze_args([path])
|
||||||
|
except Exception as e:
|
||||||
|
showerror(f"Erreur - {self.name}", str(e))
|
||||||
|
else:
|
||||||
data = []
|
data = []
|
||||||
for file in files:
|
for file in files:
|
||||||
|
try:
|
||||||
clang_format_output = clang_format(file, self.style)
|
clang_format_output = clang_format(file, self.style)
|
||||||
|
except Exception as e:
|
||||||
|
showerror(f"Erreur - {self.name}", str(e))
|
||||||
|
return
|
||||||
|
else:
|
||||||
data += parse_clang_format_output(clang_format_output)
|
data += parse_clang_format_output(clang_format_output)
|
||||||
self._pager(1, data, start_row)
|
self._pager(1, data, start_row)
|
||||||
|
|
||||||
|
|
13
src/utils.py
13
src/utils.py
|
@ -1,5 +1,4 @@
|
||||||
import os
|
import os
|
||||||
import sys
|
|
||||||
|
|
||||||
exts_list = {
|
exts_list = {
|
||||||
"CSharp": ["cs"],
|
"CSharp": ["cs"],
|
||||||
|
@ -19,25 +18,21 @@ exts_list = {
|
||||||
def analyze_args(args: list) -> list[str]:
|
def analyze_args(args: list) -> list[str]:
|
||||||
"""Renvoie la liste des fichiers"""
|
"""Renvoie la liste des fichiers"""
|
||||||
if len(args) > 1:
|
if len(args) > 1:
|
||||||
print("Trop d'arguments renseignés.", file=sys.stderr)
|
raise Exception("Trop d'arguments renseignés.")
|
||||||
exit(1)
|
|
||||||
|
|
||||||
if not len(args):
|
if not len(args):
|
||||||
print("Aucun argument renseigné.")
|
raise Exception("Aucun argument renseigné.")
|
||||||
exit(1)
|
|
||||||
|
|
||||||
if os.path.isdir(args[0]):
|
if os.path.isdir(args[0]):
|
||||||
args = iterate_over_directory(args[0])
|
args = iterate_over_directory(args[0])
|
||||||
else:
|
else:
|
||||||
if not list(filter(lambda file: os.path.exists(file), args)):
|
if not list(filter(lambda file: os.path.exists(file), args)):
|
||||||
print("Le fichier n'existe pas.", file=sys.stderr)
|
raise Exception("Le fichier n'existe pas.")
|
||||||
exit(1)
|
|
||||||
|
|
||||||
files = list(filter(check_ext, args))
|
files = list(filter(check_ext, args))
|
||||||
|
|
||||||
if not files:
|
if not files:
|
||||||
print(f"Aucun fichiers supporté ({', '.join(args)}).", file=sys.stderr)
|
raise Exception(f"Aucun fichiers supporté ({', '.join(args)}).")
|
||||||
exit(1)
|
|
||||||
|
|
||||||
return files
|
return files
|
||||||
|
|
||||||
|
|
Reference in a new issue