package MEPTL; import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import java.util.regex.Matcher; import java.util.regex.Pattern; import cXML.*; import cXML.Run.UserStatus; /** * * @author pablo rodriguez * */ public class commandes { //** Application console par défaut. //** Si la valeur ets false alors c'est une application avec inteface graphique. public static boolean console = true; //** Le node du fichier d'analyse public static node sujet = new node(); //*************************************************** //** Les commandes par défaut à travers la console ** //*************************************************** static String nameSujet = ""; //sujet par défaut public static boolean analyse = false; //analyse des fichiers étudiants public static boolean ecritCode = false; // -write : ecriture du code du sujet public static boolean ecritSujet = false; // -sujet : ecriture 2 du code du sujet, uniquement les nodes évalués public static boolean ecritNodeAnalyse = false; public static boolean ecritNoteCSV = false; // ecriture note.csv public static boolean writefiles = false; // -writefiles permet d'écrire tous les fichiers XML après la lecture en node public static boolean calculLeHashDuFichier = false; // -hash retourne le hash du fichier d'analyse public static boolean sansFeeback = false; // pas de feedback étudiant public static boolean verifHisto = false; // vérification des historiques correspond à la commande -verif public static boolean verifHisto2 = false; // vérification des historiques lorsqu'il y a aussi analyse public static boolean fourniCSV = false; // fourni le fichier CSV contenant la liste des étudiants public static boolean badCommand = false ; //erreur dans les commandes public static boolean noNote =false; // pas de note dans les feedbacks public static boolean noLogo =false; // pas de logo dans les feedbacks public static boolean newLogo=false; // un nouveau logo dans le feedback public static boolean licence = false; // affiche la licence public static boolean zipfeedback = false; // Les feedback dans une archive ZIP public static boolean fichierStudentMoodle = false; // Les fichiers étudiants sont directement dans le dossier courant de l'application. public static cXML.Run.UserStatus Profil = cXML.Run.UserStatus.TEACHER ; //Le profil TEACHER permet de lire dans les dossiers contenus dans le répertoire courant de l'application. Le profil STUDENT permet de lire au niveau du répertoire courant de l'application. public static boolean fourniDossierDestination = false; //répertoire de destination des feedbacks et CSV; public static String nameCSV = ""; //le nom du fichier contenant la liste des étudiants public static String nameSVG =""; //le nom du nouveau logo public static String contenuFichierSVG =""; // Le nouveau logo public static String path =""; public static String pathDestination =""; //Pour le mode console uniquement public static String version ="3.6.1"; // La version actuelle public static String Command =""; //récupère le texte de la commande dans la console //** setting valeur par défaut public static String culture = "FR"; public static int tolerance_characters = 5; public static double tolerance_text = 0.79; public static int number_match = 2; public static int mini_number_modification = 0; public static int nombres_modifications_simultané_maxi = 100; public static int tolerance_rouge = 30; public static int tolerance_vert = 30; public static int tolerance_bleu = 30; //** Variables de mise à jour du fichier d'analyse public static boolean MAJnameAnalysisFile =false; public static boolean MAJFichierAnalyse = false; public static String hash ="0"; //** Variables du fichier d'analyse public static String analyse_culture = "FR"; public static String analyse_metaSujet=""; public static String analyse_auteur=""; public static String analyse_Initial_Creator=""; public static String analyse_version=""; public static String analyse_creationDate=""; public static String analyse_titre=""; public static String analyse_link_sujet=""; public static String analyse_link_help=""; public static String analyse_date=""; public static boolean analyse_historiquePresent=false; public static boolean analyse_presenceMetaSujet=false; public static boolean analyse_controleDateCreation=false; public static boolean analyse_controle_Initial_Creator=false; public static boolean analyse_baremeABC=false; public static double analyse_progression=1; public static double analyse_notefrom=20; public static int analyse_tolerance_characters = 5; public static double analyse_tolerance_text = 0.79; public static int analyse_number_match = 2; public static int analyse_mini_number_modification = 0; public static int analyse_nombres_modifications_simultané_maxi = 100; public static int analyse_tolerance_rouge = 30; public static int analyse_tolerance_vert = 30; public static int analyse_tolerance_bleu = 30; public static long analyse_size = 48000000; public static String analyse_nameZip = "feedbackMoodle"; public static String analyse_hash = ""; //** Variables pour l'interface du logiciel public static String Titre = "analyseWriter"; public static String filename=""; public static boolean fichierAnalyseValide = false; //mise à jour de la valeur dans MEPTL.verificationFichierAnalyse public static String Annee ="2022"; public static int analyse_Nbre_Fichier_Student = 0; public static int analyse_index_Fichier_Student = 0; public static StringBuilder message = new StringBuilder(); /** * * @param args : table des arguments * @param patch : chemin vers le répertoire courant de l'application * @throws IOException * @throws InterruptedException */ public commandes(String[] args, String path) throws IOException, InterruptedException { commandes.path = path; for(int i = 0 ; i < args.length ; i++) { Command = Command + " " +args[i]; } try { if(args.length==0) {badCommand=true; System.out.println("Il doit y avoir une commande.");System.out.println("Vous pouvez saisir les commandes -aide ou -help pour obtenir la liste des commandes.");} for(int i = 0 ; i < args.length ; i++) { if(args[i].equals("-use")) if((i+1)=0){ if(args[i-1].equals("-use")) analyse=true; if(args[i-1].equals("-hash")) calculLeHashDuFichier=true; if(args[i-1].equals("-a")) ecritNodeAnalyse=true; if(!analyse&&!calculLeHashDuFichier&&!ecritNodeAnalyse) { badCommand=true; System.out.println("Les commandes -use ou -hash ou -a doit être suivi du nom du fichier d'analyse."); } } } if(args[i].contains(".csv")) { Matcher m = Pattern.compile("{1,}.csv$").matcher(args[i]); if(m.find()) {fourniCSV=true; nameCSV = args[i];}else {badCommand=true;System.out.println("Il y a un problème avec l'extension du fichier CSV.\nL'extension doit être \".csv\".");} if(!args[i-1].equals("-csv") && !args[i-1].equals("-verifcsv")) {badCommand=true; System.out.println("Les commandes -csv ou -verifcsv doivent être suivies par le fichier CSV contenant les identifiants des étudiants.");} } if(args[i].equals("-csv")) { if(!analyse) {badCommand=true;System.out.println("Vous devez saisir la commande -use suivi du nom du fichier d'analyse et après la commande -csv.");} ecritNoteCSV=true; } if(args[i].contains(".svg")) { Matcher m = Pattern.compile("{1,}.svg$").matcher(args[i]); if(m.find()) {newLogo=true; nameSVG = args[i];}else {badCommand=true;System.out.println("Il y a un problème avec l'extension du fichier SVG.\nL'extension doit être \".svg\".");} if(!args[i-1].equals("-newLogo")) {badCommand=true; System.out.println("La commande -newLogo doit être suivi du nom du fichier SVG.");} } if(args[i].equals("-newLogo")) { if(!analyse) {badCommand=true;System.out.println("Vous devez saisir la commade -use puis le nom du fichier d'analyse et après la commande -newLogo.");} if(noLogo) {badCommand=true;System.out.println("la commande -newLogo et -nologo ne peuvent pas être executées ensemble.");} newLogo=true; } if(args[i].equals("-verifcsv")) { if(verifHisto) {badCommand=true;System.out.println("Les commandes -verifcsv et -verif ne peuvent pas être executées ensemble.");} ecritNoteCSV=true; verifHisto=false; verifHisto2=true; if(!analyse) {badCommand=true;System.out.println("Vous devez saisir la commade -use puis le nom du fichier d'analyse et après la commande -verifcsv.");} } if(args[i].equals("-nofeedback")) { if(zipfeedback) {badCommand=true;System.out.println("Ce n'est pas possible d'executer les commandes -nofeedback et -zipfeedback en même temps.");} sansFeeback=true; } if(args[i].equals("-verif")) { if(verifHisto2) {badCommand=true;System.out.println("Les commandes -verifcsv et -verif ne peuvent pas être executées ensemble.");} verifHisto=true; verifHisto2=false; } if(args[i].equals("-help")) { if(args.length>1) {System.out.println("\n\n***\nLa commande -help doit être la seule commande.\n***");clotureWithError();} helpEN(); clotureWithHelp(); } if(args[i].equals("-aide")) { if(args.length>1) {System.out.println("\n\n***\nLa commande -aide doit être la seule commande.\n***");clotureWithError();} helpFR(); clotureWithHelp(); } if(args[i].equals("-licence")) { if(args.length>1) {System.out.println("\n\n***\nla commande -licence doite être la seule commande..\n***");clotureWithError();} licence(); } if(args[i].equals("-write")) { if(args.length>1) {System.out.println("\n\n***\nLa commande -write doit être la seule commande.\n***");clotureWithError();} ecritCode=true; Profil = UserStatus.STUDENT; } if(args[i].equals("-writefiles")) { if(!(args.length==1 && Command.contains("-writefiles") || args.length==2 && Command.contains("-writefiles")&&Command.contains("-f")) ) {System.out.println("\n\n***\nLa commande -writefiles doit être la seule commande.\nElle peut être suivi de la commande -f uniquement.\n***");clotureWithError();} writefiles=true; } if(args[i].equals("-hash")) { if(args.length>2) {System.out.println("\n\n***\nLa commande -hash suivi du nom du fichier d'analyse doit être la seule commande.\n***");clotureWithError();} calculLeHashDuFichier=true; } if(args[i].equals("-a")) { if(args.length>=3 && !Command.contains("-f")) {System.out.println("\n\n***\nLa commande -a suivi du nom du fichier d'analyse doit être la seule commande, à l'exception de la commande -f.\n***");clotureWithError();} ecritNodeAnalyse=true; } if(args[i].equals("-sujet")) { if(!(analyse&&args.length==3&&Command.contains("-use"))) {badCommand=true; System.out.println("Vous devez saisir la commande -use suivi du fichier d'analyse et après vous pouvez saisir la commande -sujet.");} ecritSujet=true; } if(args[i].equals("-nologo")) { if(!analyse) {badCommand=true;System.out.println("Vous devez saisir la commande -use suivi du fichier d'analyse et après vous pouvez saisir la commande -nologo.");} if(newLogo) {badCommand=true;System.out.println("Les commandes -newlogo et -nologo ne peuvent pas être executées en même temps.");} noLogo=true; } if(args[i].equals("-about")) { if(args.length>1) {System.out.println("\n\n***\nLa commande -about doit être la seule commande.\n***");clotureWithError();} about(); clotureApplication(); } if(args[i].equals("-nonote")) { noNote=true; } if(args[i].equals("-zipfeedback")) { if(!analyse) {badCommand=true;System.out.println("Vous devez saisir la commande -use suivi du fichier d'analyse et après vous pouvez saisir la commande -zipfeedback.");} if(sansFeeback) {badCommand=true;System.out.println("Ce n'est pas possible d'executer les commandes -nofeedback et -zipfeedback en même temps.");} zipfeedback=true; } if(args[i].equals("-f")) { if(Command.contains(" -d ")) {badCommand=true;System.out.println("Les commandes -f et -d ne peuvent pas être executées ensemble.");} fichierStudentMoodle=true; } if(args[i].equals("-dest")) if((i+1) " + path); System.out.println(); System.out.println("P. Rodriguez"); } /** * Message dans la console * @throws IOException * @throws InterruptedException */ private static void helpEN() throws InterruptedException, IOException { CLS(); System.out.println(); System.out.println("**************************************"); System.out.println("* LIST OF ANALYSEWRITER COMMANDS * "); System.out.println("**************************************"); System.out.println(); System.out.println(" -use : \t Used to indicate the analysis file."); System.out.println(" : \t The analysis file (XML format) must be placed just after the command."); System.out.println(" : \t Student files must be in named folders (export from moodle)."); System.out.println(" : \t Student files must be in ODF format with the extension .odt."); System.out.println(); System.out.println(" file.xml : \t The analysis file in XML format."); System.out.println(" : \t file.xml must be placed just after the -use command."); System.out.println(" : \t The file.xml file must be located in the current folder*."); System.out.println(" : \t This file must be obtained with the -write command."); System.out.println(" : \t This file must be manually modified to adapt it to your analysis."); System.out.println(); System.out.println(" -f : \t Indicates that all student files are directly in the current folder."); System.out.println(" : \t By default student files are in named folders."); System.out.println(" : \t Student files must be in ODF format with the extension .odt."); System.out.println(); System.out.println(" -verif : \t Allows you to compare all the modifications between the modification track logs."); System.out.println(" : \t If this is the only command then there is no analysis, no rating, no feedback."); System.out.println(" : \t This command does not depend on an analysis file (independent of subjects)."); System.out.println(" : \t You can analyze the logs even if you do not have an analysis file."); System.out.println(" : \t In the current folder*, you will find the \"Verif.xml\" file."); System.out.println(); System.out.println(" -cvs : \t Allows to import all the notes in a file in CSV format (separator the semicolon)."); System.out.println(" : \t The -use file.xml command must be placed before the -csv command."); System.out.println(" : \t The generated file is located in the current folder*."); System.out.println(" : \t This command can be followed by a file in CSV format containing the list of students."); System.out.println(" : \t If this command is followed by the \"file.csv\" file then retrieves the student IDs."); System.out.println(); System.out.println(" -verifcvs : \t Allows you to compare all the modifications between the modification track logs."); System.out.println(" : \t Allows to import all the notes in a file in CSV format (separator the semicolon)."); System.out.println(" : \t The -use file.xml command must be placed before the -verifcsv command."); System.out.println(" : \t In the current folder, you will find the \"Verif.xml\" file."); System.out.println(" : \t The -verifcsv command can be followed by a file in CSV format containing the list of students."); System.out.println(" : \t If this command is followed by the \"file.csv\" file then retrieves the student IDs."); System.out.println(); System.out.println(" file.csv : \t The file containing the list of students in CSV format."); System.out.println(" : \t The \"file.csv\" file must be placed just after the -csv or -verifcsv command."); System.out.println(" : \t The \"file.csv\" file must be in the current folder*."); System.out.println(" : \t The default separator in the CSV file is the semicolon."); System.out.println(" : \t In this file, there must be the columns \"First name\", \"Last name\", \"Identification number\"and \"Email\"."); System.out.println(" : \t You are exporting this file from the Moodle server (gradebook, exporter)."); System.out.println(); System.out.println(" -write : \t Allows you to write an analysis file."); System.out.println(" : \t The generated file is located in the current folder*."); System.out.println(" : \t The generated file is in XML format."); System.out.println(" : \t You must adapt it by modifying the XML code to perform your own analyzes."); System.out.println(); System.out.println(" -writefiles : \t Allows you to write all files in XML."); System.out.println(" : \t The generated files are located in the current folder*."); System.out.println(" : \t The generated files are in XML format."); System.out.println(); System.out.println(" -zipfeedback : \t Allows you to generate a ZIP archive containing student feedback. "); System.out.println(" : \t The archive is named \"moodleFeedback.zip\"."); System.out.println(" : \t The archive respects the format for importing feedback into Moodle."); System.out.println(); System.out.println(" -nofeedback : \t If TRUE allows you to not generate feedback for the students.."); System.out.println(" : \t Feedbacks are files in HTML format.."); System.out.println(" : \t Feedbacks can be found in the current folder*."); System.out.println(); System.out.println(" -nonote : \t Avoid display in the feedbacks of the grade."); System.out.println(" : \t Avoid placing the student's grade in the file name."); System.out.println(); System.out.println(" -dest : \t Specifies the destination directory for feedbacks and XML and CSV files."); System.out.println(" : \t Example: -dest \"./output/\" destination folder the \"output\" directory."); System.out.println(" : \t The destination directory must be in the current directory of the application."); System.out.println(" : \t There can only be one directory (no subdirectory). "); System.out.println(" : \t The path must begin with \"./\"."); System.out.println(" : \t If the folder name contains the $ symbol, it is ignored by the scan. "); System.out.println(); System.out.println(" -sujet : \t Used to retrieve the scan file containing only the evaluated nodes. "); System.out.println(" : \t The \"sujet.xml\" file is generated from the \"file.xml\" analysis file. "); System.out.println(" : \t The \"subject.xml\" file is located in the current application folder. "); System.out.println(); System.out.println(" -hash : \t Allows you to calculate the hash of a file."); System.out.println(" : \t Allows you to verify that an analysis file has not been mofidized."); System.out.println(); System.out.println(" -about : \t Displays the version, author and license. "); System.out.println(); System.out.println(" -licence : \t Displays the text of the application license. "); System.out.println(); System.out.println(" -aide : \t Display application help in French."); System.out.println(); System.out.println(); System.out.println("---"); System.out.println("* The current folder is the folder in which the application is located \"analyseWriter.jar\".\n" +"Dossier courant -> " + path); System.out.println(); System.out.println("P. Rodriguez"); } /** * Message dans la console * @throws IOException * @throws InterruptedException */ private static void about() throws InterruptedException, IOException { CLS(); int nbespace = 58-version.length(); if (nbespace<0) nbespace=1; System.out.println(); System.out.println("\t\t┌─────────────────────────────────────────────────────────────────────┐"); System.out.println("\t\t│ ANALYSEWRITER (Origin ) │"); System.out.println("\t\t│ Version : " + version+ new String(new char[nbespace]).replace("\0", " ") +"│" ); System.out.println("\t\t│ │"); System.out.println("\t\t│ Mise à jour : https://github.com/1-pablo-rodriguez/analyseWriter │"); System.out.println("\t\t│ Mise à jour : https://forge.chapril.org/pablo/analyseWriter/releases│"); System.out.println("\t\t│ │"); System.out.println("\t\t│ Développeur : pablo Rodriguez │"); System.out.println("\t\t│ │"); System.out.println("\t\t│ LICENCE GNU GENERAL PUBLIC LICENSE │"); System.out.println("\t\t│ Version 3, 29 June 2007 │"); System.out.println("\t\t└─────────────────────────────────────────────────────────────────────┘"); System.out.println(); } /** * Licence de l'application * @throws IOException */ private static void licence() throws IOException { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); InputStream is = classLoader.getResourceAsStream("licence.txt"); Reader initialReader = new BufferedReader(new InputStreamReader(is, "UTF-8")); char[] arr = new char[8 * 1024]; StringBuilder buffer = new StringBuilder(); int numCharsRead; while ((numCharsRead = initialReader.read(arr, 0, arr.length)) != -1) { buffer.append(arr, 0, numCharsRead); } initialReader.close(); System.out.println(buffer.toString()); System.out.println(); System.out.println("\t\t┌─────────────────────────────────────────────┐"); System.out.println("\t\t│ Au-dessus, vous avez la licence. │"); System.out.println("\t\t│ │"); System.out.println("\t\t│ (')_(') │"); System.out.println("\t\t│ ( `.° ) │"); System.out.println("\t\t│ (\")__(\") .. à bientôt, analyseWriter. │"); System.out.println("\t\t└─────────────────────────────────────────────┘"); System.out.println(); System.exit(0); } /** * Clôture avec une erreur de commande */ public static void clotureWithError() { System.out.println(); System.out.println("\t\t┌─────────────────────────────────────────────┐"); System.out.println("\t\t│ Vous avez commis une erreur dans votre │"); System.out.println("\t\t│ commande. │"); System.out.println("\t\t│ │"); System.out.println("\t\t│ Lisez les informations ci-dessus et │"); System.out.println("\t\t│ recommencez. │"); System.out.println("\t\t│ │"); System.out.println("\t\t│ (')_(') │"); System.out.println("\t\t│ ( `.° ) │"); System.out.println("\t\t│ (\")__(\") .. à bientôt, analyseWriter. │"); System.out.println("\t\t└─────────────────────────────────────────────┘"); System.out.println(); System.exit(0); } /** * Bye Bye the application */ public static void clotureApplication() { System.out.println(); System.out.println("\t\t┌────────────────────────────────────────────────────┐"); System.out.println("\t\t│ (')_(') │"); System.out.println("\t\t│ ( `.° ) Bravo, vous avez travaillé très dur! │"); System.out.println("\t\t│ (\")__(\") ... Bye Bye analyseWriter. │"); System.out.println("\t\t└────────────────────────────────────────────────────┘"); System.out.println(); System.exit(0); } /** * */ public static void clotureApplicationAvecErreur() { System.out.println(); System.out.println("\t\t┌────────────────────────────────────────────────────┐"); System.out.println("\t\t│ (')_(') │"); System.out.println("\t\t│ ( ;.; ) Une erreur c'est produite. │"); System.out.println("\t\t│ (\")__(\") ... Bye Bye analyseWriter. │"); System.out.println("\t\t└────────────────────────────────────────────────────┘"); System.out.println(); System.exit(0); } public static void clotureWithHelp() { System.out.println(); System.out.println("\t\t┌─────────────────────────────────────────────────────┐"); System.out.println("\t\t│ Au-dessus, vous avez la liste des commandes. │"); System.out.println("\t\t│ Mais vous avez aussi la documentation sur le │"); System.out.println("\t\t│ le serveur de github ou chapril. │"); System.out.println("\t\t│ │"); System.out.println("\t\t│ (')_(') │"); System.out.println("\t\t│ ( `.° ) │"); System.out.println("\t\t│ (\")__(\") .. à bientôt, analyseWriter. │"); System.out.println("\t\t└─────────────────────────────────────────────────────┘"); System.out.println(); System.exit(0); System.exit(0); } public static void clotureWithErrorFile(String filename) { int nbespace = 30-filename.length(); if (nbespace<0) nbespace=1; System.out.println(); System.out.println("\t\t┌───────────────────────────────────────────────────────────┐"); System.out.println("\t\t│ The file \""+ filename + "\" does not exist." + new String(new char[nbespace]).replace("\0", " ") +"│" ); System.out.println("\t\t│ │"); System.out.println("\t\t│ (')_(') │"); System.out.println("\t\t│ ( `.° ) │"); System.out.println("\t\t│ (\")__(\") .. see you soon, analyseWriter. │"); System.out.println("\t\t└───────────────────────────────────────────────────────────┘"); System.out.println(); commandes.message.append("\n"); commandes.message.append("\n*************************"); commandes.message.append("\nLe fichier \""+ filename + "\" n'existe pas."); commandes.message.append("\n*************************"); commandes.message.append("\n"); if(commandes.console) System.exit(0); } /** * Nettoyage de la console.
*
* @throws InterruptedException * @throws IOException */ public static void CLS() throws InterruptedException, IOException { new ProcessBuilder("cmd", "/c", "cls").inheritIO().start().waitFor(); } }