+Euphorik is free software: you can redistribute it and/or modify\r
+it under the terms of the GNU General Public License as published by\r
+the Free Software Foundation, either version 3 of the License, or\r
+(at your option) any later version.\r
+\r
+Euphorik is distributed in the hope that it will be useful,\r
+but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+GNU General Public License for more details.\r
+\r
+You should have received a copy of the GNU General Public License\r
+along with Euphorik. If not, see <http://www.gnu.org/licenses/>.\r
+=end\r
+\r
+# TODO :\r
+# - création de unit tests (voir eunit) et validation avant la mise en prod\r
+\r
+# Met à disposition plusieurs outils (classes), tel que :\r
+# - Vérification du code javascript\r
+# - Mise à jour du numéro de version à partir du fichier VERSION\r
+# - Mise en production et en preproduction\r
+# tools.rb peut s'utiliser à la ligne de commande, exemples :\r
+# * Mise en production :\r
+# ./tools.rb --doprod gburri@euphorik.ch:/var/www/euphorik\r
+# * Mise en préproduction, l'emplacement de production peut être indiqué pour copier la base\r
+# ./tools.rb --dopreprod gburri@euphorik.ch:/var/www/euphorik_preprod --prod gburri@euphorik.ch:/var/www/euphorik\r
+\r
+# Classe permettant la vérification du code JS pas jslint.\r
+# Passe en revu chaque fichier js de manière récursive à partir d'un dossier de départ.s\r
+class VerifJS \r
+ \r
+ def initialize(dossier)\r
+ @dossier = dossier\r
+ end\r
+ \r
+ def verifier\r
+ verifierRecu(@dossier)\r
+ end\r
+ \r
+ def verifierRecu(dossier)\r
+ Dir.foreach(dossier){|fichier|\r
+ if fichier != '.' and fichier != '..' and File.directory?(fichier) and fichier != 'dirs'\r
+ if not verifierRecu(dossier + '/' + fichier)\r
+ return false\r
+ end\r
+ elsif fichier[-3, 3] == '.js'\r
+ puts "== Vérification de #{dossier}/#{fichier} =="\r
+ system("java org.mozilla.javascript.tools.shell.Main jslint.js #{dossier}/#{fichier}")\r
+ puts $?.exitstatus\r
+ if $?.exitstatus > 0\r
+ return false\r
+ end\r
+ end\r
+ }\r
+ return true\r
+ end\r
+end\r
+\r
+# Classe de gestion de la version\r
+class Version \r
+ # @param dossier la racine du site (par exemple "/var/www/euphorik"\r
+ def initialize(dossier)\r
+ @dossier = dossier\r
+ File.open(@dossier + '/VERSION') {|file|\r
+ @version = file.readline()\r
+ }\r
+ # les fichiers HTML dans lesquels mettre à jour la version\r
+ @fichiers = ['/pages/about.html']\r
+ @balise = /(<span.+?class.*?=.*?"version".*?>).*?(<\/span>)/\r
+ end\r
+ \r
+ # met à jour la version dans les fichiers @fichiers\r
+ def maj \r
+ @fichiers.each{|fichier|\r
+ fichier = @dossier + fichier\r
+ lines = IO.readlines(fichier)\r
+ File.open(fichier, 'w') {|io|\r
+ lines.each{|l|\r
+ io.write(l.sub(@balise){|m| $1 + @version + $2})\r
+ }\r
+ } \r
+ }\r
+ end\r
+end\r
+\r
+# Permet la mise en production et preproduction\r