diff --git a/install/install_bins.sh b/install/install_bins.sh index cde4406..58aac8c 100755 --- a/install/install_bins.sh +++ b/install/install_bins.sh @@ -1,68 +1,68 @@ #!/bin/bash # Set SNAME, SDIR and SPATH if [ -h $0 ]; then SNAME=$(readlink $0); else SNAME=$0; fi SDIR=$(dirname $SNAME) if [[ "$SDIR" =~ ^/ ]]; then SPATH=$SDIR; else SPATH=$(realpath $(pwd)/$SDIR); fi # Set DIR_LIB DIR_LIB=$(realpath $SPATH/../lib/bash) # Source libs source $DIR_LIB/colors.sh source $DIR_LIB/io.sh # Set DESTINATION if [ -n "$1" ]; then DESTINATION="$(realpath $1)" else DESTINATION=$(realpath ${HOME}/bin) fi if [ ! -d $DESTINATION/ ]; then error_echo "'$DESTINATION' is not a valid directory." exit 1 fi info_echo "Using '$DESTINATION' as binary directory." function link_to_binaries() { for bin in $(echo $BINS); do if [ -r $DESTINATION/$bin ]; then if [ -h $DESTINATION/$bin ]; then OLD=$(realpath $DESTINATION/$bin) if [ "$OLD" == "$DIR_BIN/$bin" ]; then color_echo_n "Command '$bin' already exists... " else color_echo_n "Moving command '$bin' from '$OLD' to '$DIR_BIN/$bin'... " rm $DESTINATION/$bin ln -s $DIR_BIN/$bin $DESTINATION/$bin fi else error_echo "A similar command already exists: '$OLD'" exit 2 fi else color_echo_n "Installing command '$bin' to '$DESTINATION/'... " ln -s $DIR_BIN/$bin $DESTINATION/$bin fi [ -h $DESTINATION/$bin ] check_rc_echo $? if [ $(which $bin 2> /dev/null | wc -l) -eq 0 ]; then warning_echo "Make sure '$DESTINATION' is in your \$PATH variable. (Looks like it is not the case.)"; fi done } DIR_BIN=$(realpath $SPATH/../bin) BINS='bamc' link_to_binaries DIR_BIN=$(realpath $SPATH/../local/epfl) -BINS='search-epfl' +BINS='search-epfl check-scipers' link_to_binaries # RIP exit 0 diff --git a/lib/bash/bamc_configuration.sh b/lib/bash/bamc_configuration.sh index 7eb83b1..a900900 100644 --- a/lib/bash/bamc_configuration.sh +++ b/lib/bash/bamc_configuration.sh @@ -1,24 +1,24 @@ #!/bin/bash # Read global configuration DIR_CONF=$SPATH/../conf/ FILE_CONF=$DIR_CONF/$(basename $0).conf if [ ! -r $FILE_CONF ]; then echo "Could not read configuration file ($FILE_CONF)" exit 1; fi source $FILE_CONF # Source local configuration (on request) -function source_workspace_configuration() { +function source_local_configuration() { # Check workspace assert_workspace "quiet"; if [ $? -eq 1 ]; then return 1; fi local FILE_LOCAL_CONF=$DIR_WORKSPACE/$(basename $FILE_CONF) if [ -r $FILE_LOCAL_CONF ]; then source $FILE_LOCAL_CONF fi } # EOF diff --git a/lib/bash/cmdline_parser.sh b/lib/bash/cmdline_parser.sh index 05f2769..fed82ce 100644 --- a/lib/bash/cmdline_parser.sh +++ b/lib/bash/cmdline_parser.sh @@ -1,133 +1,134 @@ #!/bin/bash # Reusable command line parser # USAGE: [in the calling script] # 1) set the global variables: $DEFAULT_ITEMS, $DEFAULT_PARAMS and $DEFAULT_ACTIONS # 2) set the global variable: $CALLBACK_PREFIX (default: cb_ ) # 3) implement each the callback: e.g. function cb_list() { ... } to implement the list action # 4) call: run $@ ACTIONS='' PARAMS='' ITEMS='' CALLBACK_PREFIX=${CALLBACK_PREFIX:-cb_} function parse_args() { while [ $# -gt 0 ]; do case $1 in "-o"|"--only") shift ITEMS=$1 shift continue ;; "-p"|"--params") shift PARAMS=$1 shift continue ;; *) if [ -z "$ACTIONS" ]; then ACTIONS=$1; else ACTIONS="$ACTIONS $1"; fi shift ;; esac done # Source local configuration (if any) - source_workspace_configuration + function_exists 'source_local_configuration' + if [ $? -eq 0 ]; then source_local_configuration; fi # Compute final ITEMS if [ -z "$ITEMS" ]; then ITEMS=$(get_default_items); fi if [ -z "$ITEMS" ]; then ITEMS='~no~items~'; fi # Compute final ACTIONS if [ -z "$ACTIONS" ]; then ACTIONS=$(get_default_actions); fi if [ -z "$ACTIONS" ]; then ACTIONS='help'; fi # Compute final PARAMS PARAMS=$(echo $PARAMS,$(get_default_params) | tr "," "\n" | sort -u | grep -v '^$' | tr "\n" "," | sed 's/,$//') debug "End of command line parsing. ACTIONS: '$ACTIONS' | ITEMS: '$ITEMS' | PARAMS: '$PARAMS'" } function get_items() { echo "$ITEMS" | sed "s/,/\n/g" } function get_actions() { echo "$ACTIONS" | sed "s/ /\n/g" } function get_params() { echo "$PARAMS" | sed "s/,/\n/g" } function get_parameter() { key=$1 # Key alone line=$(echo $PARAMS | sed "s/,/\n/g" | grep "^$key$") if [ -n "$line" ]; then echo "set"; return; fi # Key + value line=$(echo $PARAMS | sed "s/,/\n/g" | grep "^$key=" | cut -d '=' -f 2-) if [ -n "$line" ]; then echo $line; return; fi # unset echo "unset" } function is_set() { param=$1 value=$(get_parameter $param) if [ "$value" != "unset" ]; then return 1; else return 0; fi } function run() { local action local item local global_rc=0 rc parse_args $@ for action in $(get_actions); do rc=0 main_switch $action $item rc=$? if [ $rc -ne 0 ]; then echo "rc: $rc"; fi global_rc=$((rc+$rc)) done if [ $global_rc -ne 0 ]; then echo "global_rc: $global_rc"; fi return $global_rc } function get_default_items() { echo $DEFAULT_ITEMS } function get_default_params() { echo $DEFAULT_PARAMS } function get_default_actions() { echo $DEFAULT_ACTIONS } function check_action() { function_exists $1 return $? } function main_switch() { local action=$1 local function_to_call="${CALLBACK_PREFIX}${action}" check_action $function_to_call if [ $? -eq 0 ]; then debug "Calling action '$action' => '$function_to_call' on item(s) '$(get_items)'" $function_to_call $(get_items) return $? else error "invalid action: '$action' => '${CALLBACK_PREFIX}${action}' (not implemented ?)" return 1 fi return 0 } # EOF diff --git a/local/epfl/check-scipers b/local/epfl/check-scipers new file mode 100755 index 0000000..ff9513a --- /dev/null +++ b/local/epfl/check-scipers @@ -0,0 +1,133 @@ +#!/bin/bash + +# Set SNAME, SDIR and SPATH +if [ -h $0 ]; then SNAME=$(readlink $0); else SNAME=$0; fi +SDIR=$(dirname $SNAME) +if [[ "$SDIR" =~ ^/ ]]; then SPATH=$SDIR; else SPATH=$(realpath $(pwd)/$SDIR); fi + +#================================= +# Set DIR_LIB and source libs +DIR_LIB=$(realpath $SPATH/../../lib/bash) +source $DIR_LIB/tools.sh +source $DIR_LIB/io.sh +source $DIR_LIB/cmdline_parser.sh +source $DIR_LIB/debugging.sh + +# Set DIR_CACHE +DIR_CACHE=$(realpath $SPATH/cache/) + +DEFAULT_ACTIONS="help" +DEFAULT_PARAMS="name=1,sciper=2" +DEFAULT_ITEMS="$(find . -type f -name '*\.csv' | sort)" + +function usage() { + echo "USAGE: $(basename $SNAME) --only scipers_1.csv[,scipers_2.csv] --params name=1,sciper=2,[refetch] [help|fetch|csv]"; +} + +function cb_help() { + usage + return 0 +} + +function cb_fetch() { + local csv + local id sciper email section name status found l + for csv in $(echo $@); do + check_file_exists $csv + if [ $? -ne 0 ]; then usage; exit 1; fi + perma "[FETCH] Processing file $(basename $csv)" + + # Process file + id=0 + local old_IFS=$IFS + local IFS=$'\n' + for l in $(cat $csv); do + ((id++)) + sciper=$(echo $l | cut -d ',' -f $(get_parameter 'sciper')) + fetch_data $sciper + found=$(get_field 'found') + if [ "$found" = "1" ]; then + verbose "$id: found" + else + verbose "$id: not found" + fi + done + IFS=$old_IFS + done + return 0 +} + +function cb_csv() { + local csv + local id sciper email section name status found l + for csv in $(echo $@); do + check_file_exists $csv + if [ $? -ne 0 ]; then usage; exit 1; fi + + # Process file + id=0 + echo 'ID,SCIPER,NAME,SECTION,EMAIL,STATUS' + local old_IFS=$IFS + local IFS=$'\n' + for l in $(cat $csv); do + ((id++)) + sciper=$(echo $l | cut -d ',' -f $(get_parameter 'sciper')) + fetch_data $sciper + found=$(get_field 'found') + if [ "$found" = "1" ]; then + status="OK"; + email=$(get_field 'email') + section=$(get_field 'section') + name=$(get_field 'cname_usual_reversed') + else + status="NOT FOUND" + email='unknown@epfl.ch' + section='XXX' + name=$(echo $l | cut -d ',' -f $(get_parameter 'name')) + fi + echo "$id,$sciper,$name,$section,$email,$status" + continue + done + IFS=$old_IFS + done + return 0 +} + +function fetch_data() { + local sciper=$1 + local fetch=0 + local cache_file="$DIR_CACHE/${sciper}.txt" + is_set 'refetch' + if [ $? -eq 1 ]; then + fetch=1 + else + check_file_exists $cache_file 2> /dev/null + if [ $? -eq 1 ]; then + fetch=1 + else + if [ $(cat $cache_file | wc -l) -eq 0 ]; then + fetch=1 + fi + fi + fi + + + if [ $fetch -eq 1 ]; then + search-epfl -s $sciper > $cache_file + DATA=$(search-epfl -s $sciper | tr '\n' '~'); + else + DATA=$(cat $cache_file | tr '\n' '~') + fi +} + +function get_field() { + local field=$1 + echo $DATA | tr '~' '\n' | grep "^$field:" | cut -d ':' -f 2- +} + +run $@ + +# RIP +exit 0 + + diff --git a/local/epfl/check_list b/local/epfl/check_list deleted file mode 100755 index d5b50ad..0000000 --- a/local/epfl/check_list +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/bash - -function USAGE() { - echo "USAGE: $0 csv_list.csv"; - exit 1 -} - -SOURCE=$1 -if [ ! -r $SOURCE ]; then echo "File not found: $SOURCE" >2; USAGE; fi - -function fetch_data() { - local sciper=$1 - local cache_file="./cache/${sciper}.txt" - if [ ! -f $cache_file ]; then - ./search-epfl -s $sciper > $cache_file - DATA=$(./search-epfl -s $sciper | tr '\n' '~'); - fi - DATA=$(cat $cache_file | tr '\n' '~') -} - -function get_field() { - local field=$1 - echo $DATA | tr '~' '\n' | grep "^$field:" | cut -d ':' -f 2- -} - -IFS=$'\n' -id=0 -for l in $(cat $1); do - ((id++)) - sciper=$(echo $l | cut -d ',' -f 1) - rest=$(echo $l | cut -d ',' -f 2-) - fetch_data $sciper - section=$(get_field 'section') - name=$(get_field 'cname_usual') - status="OK"; - if [ -z "$section" ] ; then section=$(echo $l | cut -d ',' -f 3); status="NOT FOUND"; fi - if [ -z "$name" ] ; then name=$(echo $l | cut -d ',' -f 2); fi - echo "$id,$sciper,$name,$section,$status,$rest" -done diff --git a/local/epfl/liste.csv b/local/epfl/liste.csv deleted file mode 100644 index 64b308d..0000000 --- a/local/epfl/liste.csv +++ /dev/null @@ -1,219 +0,0 @@ -247893,Abboud Robert,GC -240822,Albanese Leopoldo Costantino Ercole,GC -235706,Albutra Nasseem,GC -250646,Ansermet Robin Brian,GC -247777,Azélart Henri Bernard Vincent,GC -237979,Badarani Louise Simone Flore,GC -249696,Badoux Sophia Claire,GC -246138,Bahchouch Hamza,GC -245913,Barre Pierre Stéphane Denis,GC -236760,Baudry Inès Marie Anne Véronique,GC -238346,Bellamlih Mamou Ali,GC -236362,Bembarek Mohammed-Amine,GC -234779,Bensaid Younes,GC -224796,Benzakour Hamza,GC -249902,Berquand Cecile Anne,GC -247180,Bhouri Adem,GC -237985,Borremans Noé,GC -247453,Bösch Felix Samuel,GC -249807,Brault Victoire Thérèse Marie,GC -240894,Brunner Kim Tan Quang,GC -237074,Buqaj Gentian,GC -247815,Burckhardt Valérie Claudia,GC -233683,Casanova Michela,GC -246679,Cassina Lisa,GC -246210,Charif Linah,GC -246830,Couturier Alexia,GC -237591,Curis Gabriel François Marie Laurent,GC -250002,D'Annunzio Lorn Douglas,GC -228280,De Franceschini Cesare,GC -247244,Decoppet Jean-Baptiste Luc Hubert,GC -236097,Delannoy Louis Marc Bruno,GC -251757,Delfino Arnaud,GC -237169,Delvaille Guillaume André,GC -246687,Dépraz Mathieu,GC -246077,Descombes Albane Bénédicte,GC -237110,Dorrio Alves Gonzalo Paulo Enrique,GC -250747,Dorthe Titouan,GC -240604,Drouin Thomas Pierre Jacques,GC -239398,Durussel Shad Ali,GC -236135,El Kafil Youssef,GC -246556,El Ouazzani Touhami Yassine,GC -250790,Favre Simon,GC -237126,Ferrari Paolo Angelo,GC -247221,Fink Arthur Guillaume,GC -239433,Fiocconi Clara Sylvie Bernadette Gisèle,GC -247082,Florez Diego,GC -247749,Fontugne Augustin Jean Hugo,GC -237132,Fraigedo Marco,GC -240605,Framery Luis-Angel Charles,GC -247867,Freiburghaus Sylvain,GC -236718,Fuchs Michael Hubert,GC -247483,Fuselier Héloïse Manon,GC -233834,Gandy Lucas Christophe Mathieu,GC -235013,Gasparovic Sergej,GC -239503,Gautier Louis Pierre Robert,GC -231100,Gillet Maxime Loris,GC -236407,Giovanola Vincent,GC -246021,Glatz Tobias Bruno,GC -249835,Gratier De Saint-Louis Romain Essy Théo,GC -234738,Gros Julie Noémie Marie,GC -247030,Haan Julien Johan,GC -203117,Haddadi Sasan,GC -234847,Halleux Arthur,GC -250669,Hatem Nicolas Fernand Joseph,GC -239440,Herbin Océane Elisa Victoire Ildegarde,GC -244982,Heredia Rosa Diego Isidoro,GC -246698,Hourse Laetitia Marie Frédérique,GC -250855,Hoxha Hamid,GC -250446,Imperatori Lisa,GC -250895,Jaber Mehdi,GC -236654,Jacot-Descombes Fabien Jérôme,GC -238028,Jamet Gregoire Aurelien Marie,GC -239626,Joseph Quentin,GC -242532,Keller Paul Alexandre Mario,GC -235333,Kitane Youssef,GC -227442,Kohler David,GC -247288,Labrosse Lucas,GC -246884,Lafaye Chloé Gisèle Christiane,GC -249909,Lafkihi Youssef,GC -235210,Lamrani Alaoui Othmane,GC -237830,Lao Kevin Okynawa,GC -239394,Lemghari Salma,GC -247803,Liechti Simon Jean Marie,GC -236727,Mariller Nicolas Loic Dorian,GC -241602,Matthews Salmon Scott David,GC -246713,Matthey Valériane,GC -244962,Maye Robin Daniel Etienne,GC -250935,Mermod Paul Victor Augustin,GC -241337,Meroni Gabriele Leandro,GC -246972,Michel Stanislas Hugo Werner,GC -234759,Minault Edgar Paul,GC -235570,Mock Pascal Jérémie,GC -247210,Mockers Antoine Valentin,GC -234500,Mohr Mathieu,GC -247494,Monetta Fiona,GC -240666,Monneron Armand Quy Kim,GC -246619,Morim Dany,GC -247798,Mosena Dan,GC -250956,Mudry Grégoire Samuel,GC -246907,Némethy Nicolas Karol Doctoré,GC -245814,Nicolet Adrien,GC -247797,Olsen Nils Frédérik Heiden,GC -250613,Oswald Zora,GC -250587,Padovani Christopher Anthony Marius,GC -238531,Perard Arthur Stéphane,GC -246251,Perruchoud Valentin,GC -245360,Pfister Mélanie,GC -233770,Ponce De Leon Bezerra Amanda Cristina,GC -250632,Pouzere Marie-Lys Ella Dawa,GC -236070,Prébandier Christophe,GC -246979,Pugin Madeline,GC -238323,Rahmaty Abdu,GC -240671,Ramalhoto Penela Joel António,GC -225733,Ramusat Romain Patrick Stéphane,GC -229194,Reyes Samuel Emmanuel,GC -235832,Richard Nicolas Paul,GC -228105,Sahibi Ahmed Wassim,GC -247669,Saint-Supéry Santiago,GC -250866,Salvadé Nicolas Jean,GC -247792,Schneider Romain,GC -223539,Schöpfer Olivier Henri,GC -251192,Schucany Hervé Robert Eugène,GC -237729,Schürch Ursula Esther,GC -235750,Senglet Côme Roland Gérard,GC -247400,Senser Loic,GC -244989,Sessa Ludovica,GC -245842,Siganos Ioannis,GC -236194,Silva Brites Loris,GC -246529,Storz Jordi,GC -247911,Stuber Thomas,GC -249856,Tedeschi Julien Brian,GC -236330,Thillaye Du Boullay Cyril Marie Régis,GC -247038,Valentin Axel Olivier,GC -234512,Velasquez Emmanuel Pablo,GC -235259,Vermot Maeva Tran Tien Lac,GC -250392,Vernay François,GC -245828,Vernet Arthur Maximilien,GC -235606,Viviant Jean Lou Marin,GC -250429,Vuilleumier Violaine,GC -234761,Walid Mahmoud Helmy Nadeem Mohamed,GC -235072,Weibel Amine,GC -238719,Woehner Monia,GC -228073,Woerle Nicolas Pierre Antoine,GC -201838,Wojnarowicz Matthias,GC -238920,Yassafi Amine-Reda,GC -224808,Adel Sonia,SIE -237657,Alaoui Hiba,SIE -240569,Andreetti Alice,SIE -234661,Arnaudon Lucie,SIE -250155,Barbe Emile,SIE -246453,Barbey Léa,SIE -236496,Bergqvist Miriam Christine,SIE -250158,Bernegger Arline Andrea,SIE -250302,Berteaux Adrien Pierre-Alain Boris,SIE -236741,Bielser Florian Adrien,SIE -250598,Bissel Laura Emilie,SIE -238271,Bodmer Timon,SIE -235142,Bonzi Patrick,SIE -250252,Bouche Léopold Antoine Joanny,SIE -250264,Bouvresse Déborah Michèle Albertine,SIE -236472,Brand Florian,SIE -247108,Bretton Aude Marie Dorothée,SIE -236296,Brouillet Constance,SIE -250689,Brunner Lena,SIE -238204,Buchwalder Xavier Louis Maurice,SIE -247605,Burg David Joël,SIE -247225,Caby Theodore Leopold Marie,SIE -236711,Camplani Nathalie Teresina,SIE -235221,Chalak Chirine,SIE -247814,Chappelier Coralie,SIE -246680,Chatelan Elsa Jöelle,SIE -236714,Collins Fiona Claire,SIE -247326,Décosterd Bertil,SIE -239479,Delessert Pauline Charlotte,SIE -250337,Ellero Alicia Mélanie,SIE -250142,Fetzer Aline Sophie,SIE -247021,Franziskakis Johann,SIE -247727,Girardet Lina Elodie Klara,SIE -237757,Hariki Maryam,SIE -239763,Ismaïl Ayoub,SIE -245773,Joris Guillaume Philippe Benoit,SIE -247918,Jouberton Achille Pierre,SIE -247232,Jullien Nicolas,SIE -247701,Keller Cloé,SIE -213505,Klein Louis Xavier,SIE -238503,Kowalski Coralie Jazz,SIE -249748,Krey Vassiliki,SIE -234856,Krzyzostaniak Théo Marek,SIE -249920,Labenets Elena,SIE -235335,Laroui Yassine Klaus,SIE -250546,Locatelli Maxence Valentin,SIE -249236,Lugrin René,SIE -250915,Maeder Ivan,SIE -249690,Manetti Nicolas,SIE -246712,Matthey-Junod Anaïs,SIE -252025,Meskaldji Amir Sami,SIE -236271,Morandini Léonard Elliot,SIE -248153,Neuenschwander Philipp,SIE -240888,Nyffeler Cécile,SIE -249546,Obrecht Jolan César,SIE -250612,Ott Lucas,SIE -247430,Pellaton Louise Diane,SIE -250967,Perez Loïc,SIE -247863,Perna Michael,SIE -236801,Perret Antoine,SIE -250607,Petit Maximilien Jean André,SIE -239467,Quilici Andrea Vittorio,SIE -223888,Rabbath Laura,SIE -235752,Reymond-Joubin Maric Yannick Xavier,SIE -237732,Romero Grass Maëlle,SIE -248127,Sanchez Del Rio Kandel David,SIE -251722,Tahiri Reda,SIE -250383,Tournefier Alan Lucas,SIE -235649,Vallotton Amandine,SIE -245912,Vaucher Nadège,SIE -246644,Viennot-Bourgin Pauline Marie,SIE -247563,Vogel Mégane,SIE -249614,Vogel Michael,SIE -234516,Vruggink Marc,SIE