epita-std
/
ACU
Archived
1
0
Fork 0

Add migration tools

This commit is contained in:
Mercier Pierre-Olivier 2013-09-02 19:13:32 +02:00
parent 21e54466e4
commit f978072748
3 changed files with 495 additions and 0 deletions

148
defenses/defense_converter.pl Executable file
View File

@ -0,0 +1,148 @@
#! /usr/bin/env perl
use v5.10.1;
use strict;
use warnings;
use Getopt::Long;
use Pod::Usage;
use XML::LibXML;
# Parse arguments
my $input; my $output; my $compact;
my $help; my $man;
GetOptions ("output|O=s" => \$output,
"compact" => \$compact,
"help|h|?" => \$help,
"man" => \$man,
"" => \$input)
or pod2usage(2);
pod2usage(1) if $help;
pod2usage(-exitval => 0, -verbose => 2) if $man;
# Open old defense XML file
my $xmlin;
if (defined $input || $#ARGV == -1) {
$xmlin = *STDIN;
}
else {
open $xmlin, "<", $ARGV[0] or die $!;
}
binmode $xmlin;
my $dom = XML::LibXML->load_xml(IO => $xmlin);
close $xmlin unless $xmlin eq *STDIN;
my $new = XML::LibXML->createDocument;
my $root = $new->createElement( "defense" );
$new->setDocumentElement( $root );
$root->setAttributeNode( $new->createAttribute( "duration", "420" ) );
my $last_grp;
foreach my $group ($dom->getElementsByTagName("group"))
{
$last_grp = $new->createElement( "group" );
$root->appendChild( $last_grp );
$last_grp->setAttributeNode( $new->createAttribute( "title", $group->getElementsByTagName("title")->shift->textContent ) );
my $last_qst;
foreach my $question ($group->getElementsByTagName("question"))
{
$last_qst = $new->createElement( "question" );
$last_grp->appendChild( $last_qst );
$last_qst->setAttributeNode( $new->createAttribute( "title", $question->getElementsByTagName("description")->shift->textContent ) );
if ($question->getElementsByTagName("kind")->shift->textContent =~ "QCM") {
$last_qst->setAttributeNode( $new->createAttribute( "type", "qcm" ) );
}
my $ask = $new->createElement( "ask" );
$ask->appendChild( $dom->createTextNode( $question->getElementsByTagName("intitule")->shift->textContent ) );
$last_qst->appendChild( $ask );
foreach my $answer ($question->getElementsByTagName("answer"))
{
my $ans = $new->createElement( "answer" );
if ($answer->getElementsByTagName("str")->shift->textContent =~ ">|<") {
$ans->appendChild( $dom->createCDATASection( $answer->getElementsByTagName("str")->shift->textContent ) );
}
else {
$ans->appendChild( $dom->createTextNode( $answer->getElementsByTagName("str")->shift->textContent ) );
}
$last_qst->appendChild( $ans );
}
if ($question->getElementsByTagName("good_answer")->shift) {
my $expln = $new->createElement( "explanation" );
if ($question->getElementsByTagName("good_answer")->shift->textContent =~ ">|<") {
$expln->appendChild( $dom->createCDATASection( $question->getElementsByTagName("good_answer")->shift->textContent ) );
}
else {
$expln->appendChild( $dom->createTextNode( $question->getElementsByTagName("good_answer")->shift->textContent ) );
}
$last_qst->appendChild( $expln );
}
}
}
# Save defense XML file
my $xmlout;
if (defined $output) {
open $xmlout, '>', $output;
binmode $xmlout;
}
else {
$xmlout = *STDOUT;
}
print {$xmlout} $new->toString(0) if ($compact);
print {$xmlout} $new->toString(1) if (! $compact);
close $xmlout unless $xmlout eq *STDOUT;
__END__
=head1 NAME
defense_converter.pl - Convert old style defense XML to new style
=head1 SYNOPSIS
defense_converter.pl [options] [file]
=head1 DESCRIPTION
Parse the XML file given (or stdin if no file is given) and convert it to the new XML defense form.
Options:
-output=file.xml save new XML to this location
-compact product a non-idented XML
-help brief help message
-man full documentation
=head1 OPTIONS
=over 8
=item B<-output=file.xml>
Save the new style XML to a file instead of printing it on standard output.
=item B<-compact>
Product a non-idented XML.
=item B<-help>
Print a brief help message and exits.
=item B<-man>
Prints the manual page and exits.
=back
=cut

46
migration/get_keys.sh Executable file
View File

@ -0,0 +1,46 @@
#! /usr/bin/env bash
BDIR="/sgoinfre/public"
YAKAS="anselm_j aurier_j baud_a beneul_a bounth_j bourg_m bourge_c chotar_a covola_b crepea_b escoba_c farbos_a godard_m houdeb_k huyghe_k kiffer_r lannel_r le-dan_c meny_n metivi_h mirzai_v sanche_g sellem_t seure-_a sztern_k tarral_m tavare_m thach_a vermor_c yeh_j"
ACUS="lefort_f derboi_a challe_a cleyma_s provos_b gourve_l pelleg_c tram_v grand_x lepage_a johann_t tissey_j beaudu_s genite_n thierr_j frotti_b lopez_b launet_a rodrig_b wils_r chen_a mercie_d cokela_s derboi_c boisse_r lecuye_c freche_j amirau_k rouaul_c zanott_b latrou_v pre_q"
DEST=`mktemp -d`
valid()
{
if [ -f "$1" ]
then
TYPE=`file "$1" | cut -d " " -f 2-`
case "$TYPE" in
"ASCII text, with very long lines")
if [ `ssh-keygen -l -f "$1" | cut -d " " -f 1` == 4096 ]
then
cp "$1" "$DEST/$2.pub"
echo ">>> Key found for $2"
else
echo "Too small key for $2"
fi
return 0
;;
"PEM RSA private key")
echo "WARNING: private key detected: $1"
return 2
;;
*)
echo "UNKNOWN file type: $1: $TYPE"
;;
esac
fi
return 1
}
for LOGIN in $YAKAS $ACUS
do
valid "$BDIR/$LOGIN/id_rsa" "$LOGIN"
valid "$BDIR/$LOGIN/id_rsa.pub" "$LOGIN"
valid "$BDIR/$LOGIN/$LOGIN" "$LOGIN"
valid "$BDIR/$LOGIN/$LOGIN.pub" "$LOGIN"
done
echo
echo "`ls $DEST | wc -l` valid keys copied to $DEST"

301
migration/repo.sh Executable file
View File

@ -0,0 +1,301 @@
#! /usr/bin/env bash
if [ -z "$1" ]
then
echo "Please provide a repo to clone"
exit 1
fi
clean_tex()
{
for f in data Makefile images/acu.pdf images/assistants.pdf images/assistants-subject.pdf images/assistants-slides.pdf images/assistants.png images/epita.pdf images/epita.png images/epita-invert.pdf images/assistants-invert.pdf images/epita-invert.png *.cls *.sty *.tex
do
if [ -f "$f" ]
then
git rm -f "$f" > /dev/null
elif [ -d "$f" ]
then
git rm -fr "$f" > /dev/null
fi
done
cd include
for i in `find -type f -name '*.tex'`
do
bi=`basename "$i"`
echo -e "\e[1;34m>>>\e[1;37m Trying to convert $i to Markdown...\e[0m"
sed -Ei 's/\\include *\{([^}]+)}/\\verb+~include(\1)+/gi' "$i"
sed -Ei 's/\\input *\{([^}]+)}/\\verb+~include(\1)+/gi' "$i"
sed -Ei 's/\{\\include *([^}]+)}/\\verb+~include(\1)+/gi' "$i"
sed -Ei 's/\{\\input *([^}]+)}/\\verb+~include(\1)+/gi' "$i"
sed -Ei 's/\\lstinline *\{([^}]+)}/\\verb+\1+/gi' "$i"
sed -Ei 's/\\begin *\{correction\}/\\begin\{verbatim\}/g' "$i"
sed -Ei 's/\\end *\{correction\}/\\end\{verbatim\}/g' "$i"
sed -Ei 's/\\begin *\{prompt\}/\\begin\{verbatim\}/g' "$i"
sed -Ei 's/\\end *\{prompt\}/\\end\{verbatim\}/g' "$i"
sed -Ei 's/\\begin *\{script\}/\\begin\{verbatim\}/g' "$i"
sed -Ei 's/\\end *\{script\}/\\end\{verbatim\}/g' "$i"
sed -Ei 's/\\begin *\{cartouche\}/\\begin\{verbatim\}/g' "$i"
sed -Ei 's/\\end *\{cartouche\}/\\end\{verbatim\}/g' "$i"
sed -Ei 's/\\begin *\{cartouche_nospaces\}/\\begin\{verbatim\}/g' "$i"
sed -Ei 's/\\end *\{cartouche_nospaces\}/\\end\{verbatim\}/g' "$i"
# Convert Beamer
sed -Ei 's/\\begin\[[^]]+\]\{frame\}\{([^}]+)\}/\\subsection\{\1\}/g' "$i"
sed -Ei 's/\\begin\{frame\}\{([^}]+)\}\[[^]]+\]/\\subsection\{\1\}/g' "$i"
sed -Ei 's/\\begin\{frame\}\{([^}]+)\}/\\subsection\{\1\}/g' "$i"
sed -Ei 's/\\begin(\[[^]]+\])?\{frame\}(\[[^]]+\])?//g' "$i"
sed -Ei 's/\\begin\{block\}\{([^}]+)\}/\\subsubsection\{\1\}/g' "$i"
sed -Ei 's/\\begin\{block\}/\\subsubsection\{~\}/g' "$i"
sed -Ei 's/\\end(\[[^]]+\])?\{frame\}(\[[^]]+\])?//g' "$i"
sed -Ei 's/\\end(\[[^]]+\])?\{block\}(\[[^]]+\])?//g' "$i"
sed -Ei 's/\\frametitle *\{/\\subsection\{/g' "$i"
sed -Ei 's/\\framesubtitle *\{/\\subsubsection\{/g' "$i"
sed -Ei 's/\\(sub)*section *\{\}//g' "$i"
sed -Ei 's/\\frame *\{/\{/g' "$i"
sed -Ei 's/\\frame//g' "$i"
sed -Ei 's/\\item( *)<[^>]+>/\\item\1/g' "$i"
if pandoc -o ../${bi%%.tex}.md $i
then
git add ../${bi%%.tex}.md
git checkout "$i"
git rm -f "$i" > /dev/null
fi
sed -Ei 's/`~?include\(([^)]+)\)`/~include(\1)/gi' "../${bi%%.tex}.md"
done
if [ `find | wc -l` -gt 1 ]
then
git mv * ..
fi
cd ..
if [ -f "mySubject.md" ]
then
git mv "mySubject.md" "main.md"
elif [ -f "mySlide.md" ]
then
git mv "mySlide.md" "main.md"
elif [ -f "mySlides.md" ]
then
git mv "mySlides.md" "main.md"
elif [ -f "myTutorial.md" ]
then
git mv "myTutorial.md" "main.md"
fi
rmdir include
}
TMPDIR=`mktemp -d`
cd $TMPDIR
rmdir repo.git
if ! ( mkdir repo.git &&
cd repo.git &&
git init --bare &&
cd .. )
then
echo "Unable to create git final repository"
exit 2
fi
if ! hg clone "https://cpp.acu.epita.fr/projects/$1"
then
echo "Unable to clone $1 mercurial repository"
exit 3
fi
cd "$1"
if ! hg push "$TMPDIR/repo.git"
then
echo "Unable to convert Mercurial to Git repository"
exit 4
fi
cd ..
rm -rf "$1"
git clone "$TMPDIR/repo.git" "$1"
cd "$TMPDIR/$1"
# grades branch
if ls | grep "grades"
then
echo -e "\e[1;34m>>>\e[1;37m Creating grades branch...\e[0m"
git checkout -b grades
find -mindepth 1 -maxdepth 1 ! -name grades ! -name .git -exec git rm -rf {} \;
find -name '*.trace' -name '*.html' -name '*.yml' -exec git rm -rf {} \;
git rm -f grades/DESC 2> /dev/null
git commit -am "Converting HG to Git" > /dev/null
fi
git checkout master
# moulette branch
if ls | grep "moulette"
then
echo -e "\e[1;34m>>>\e[1;37m Creating moulette branch...\e[0m"
git checkout -b moulette
find -mindepth 1 -maxdepth 1 ! -name moulette ! -name .git -exec git rm -rf {} \;
git rm -f moulette/DESC 2> /dev/null
git commit -am "Converting HG to Git" > /dev/null
fi
git checkout master
find -type f ! -name '*.sh' ! -name '*.rb' ! -name '*.pl' ! -name 'configure' -exec chmod -x {} \;
echo
echo -e "\e[1;31m##\e[1;37m Removing ELF outside files/ \e[1;31m##\e[0m"
for d in `find -mindepth 1 -maxdepth 1 -type d ! -name .git ! -name files`
do
for f in `find "$d" -type f`
do
if [ `file "$f" | cut -d " " -f 2` = "ELF" ]
then
git rm -f "$f"
fi
done
done
echo -e "\e[1;31m## ## ## ## ##\e[0m"
echo
echo -e "\e[1;31m##\e[1;37m Removing old and temporary files \e[1;31m##\e[0m"
git rm -f AUTHORS
git rm -f README
git rm -f Makefile
git rm -f files/list
git rm -f "files/*.pdf"
find -name 'Changelog' -exec git rm -fr {} \;
find -name 'ChangeLog' -exec git rm -fr {} \;
find -name 'DESC' -exec git rm -fr {} \;
find -name '*.old' -exec git rm -fr {} \;
find -name '*.bak' -exec git rm -fr {} \;
find -name '*~' -exec git rm -fr {} \;
find -name '#*#' -exec git rm -fr {} \;
echo -e "\e[1;31m## ## ## ## ##\e[0m"
echo
for DIR in *
do
if [ "$DIR" = "defenses" ]
then
echo -e "\e[1;35m##\e[1;37m Find directory $DIR with some defense files \e[1;35m##\e[0m"
cd defenses
git rm -f Makefile > /dev/null
for D in *
do
if [ -f "$D/template.xml" ]
then
~/new_intra/defenses/defense_converter.pl -o "$D.xml" "$D/template.xml"
git add "$D.xml"
echo -e "\e[1;35m>>>\e[1;37m Defense converted:\e[0m $D"
fi
git rm -rf "$D" > /dev/null
done
cd ..
echo -e "\e[1;35m## ## ## ## ##\e[0m"
echo
elif [ "$DIR" = "grades" ]
then
echo -e "\e[1;36m##\e[1;37m Find directory $DIR for grading \e[1;36m##\e[0m"
git rm -rf "$DIR"
echo -e "\e[1;36m## ## ## ## ##\e[0m"
echo
elif find "$DIR" -type f -name '*.yml' | grep yml > /dev/null
then
echo -e "\e[1;33m##\e[1;37m Find directory $DIR with some .yml files \e[1;33m##\e[0m"
git rm -rf "$DIR"
echo -e "\e[1;33m## ## ## ## ##\e[0m"
echo
elif find "$DIR" -type f -name '*.tex' | grep tex > /dev/null
then
echo -e "\e[1;32m##\e[1;37m Find directory $DIR with some .tex files \e[1;32m##\e[0m"
cd "$DIR"
clean_tex "$DIR"
cd ..
echo -e "\e[1;32m## ## ## ## ##\e[0m"
echo
elif [ -d "$DIR" ]
then
cd "$DIR"
FILELIST=""
if [ "$DIR" != "ref" ]
then
FILELIST="$FILELIST Makefile"
fi
if [ "$DIR" != "tests" ]
then
FILELIST="$FILELIST README"
fi
for f in $FILELIST
do
if [ -f "$f" ]
then
git rm -f "$f" > /dev/null
elif [ -d "$f" ]
then
git rm -rf "$f" > /dev/null
fi
done
cd ..
fi
done
echo -e "\e[1;34m>>>\e[1;37m Adding .gitignore...\e[0m"
cat <<EOF > .gitignore
*.toc
*.aux
*.bat
*.glo
*.log
*#
*.snm
*.vrb
*.nav
*~
*.bbl
*.blg
.*.sw?
*.o
*.class
*.ghc
*.so
*.a
EOF
for f in `find -name "README.txt"` `find -name "TODO.txt"` `find -name "AUTHORS.txt"`
do
git mv "$f" "${f%.txt}"
done
git add .gitignore
git commit -am "Converting HG to Git" > /dev/null
git remote remove origin
if [ -z "$2" ]
then
git remote add origin "ssh://git@forge/subjects/$1"
else
git remote add origin "ssh://git@forge/subjects/$2"
fi
#rm -rf $TMPDIR
echo
echo -e "\e[1;37mYou can view $TMPDIR/$1/ directory\e[0m"