X-Git-Url: http://git.euphorik.ch/?p=euphorik.git;a=blobdiff_plain;f=tools%2Ftools.rb;h=f2e2067cb77aa667ab55ec2bad2bcd1b59cc2ead;hp=fe7eb9db5539373365930b8c346b249c1f28861e;hb=e2355385811ba452308be5e66afc7f93cb6af75b;hpb=427ee8d1072dde4b06fbf019033c56e4929ee0d6
diff --git a/tools/tools.rb b/tools/tools.rb
index fe7eb9d..f2e2067 100644
--- a/tools/tools.rb
+++ b/tools/tools.rb
@@ -1,34 +1,114 @@
-#!/usr/bin/ruby
-=begin
-Copyright 2008 Grégory Burri
-
-This file is part of Euphorik.
-
-Euphorik is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-Euphorik is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with Euphorik. If not, see .
-=end
+#!/usr/bin/ruby
+# coding: utf-8
+=begin
+Copyright 2008 Grégory Burri
+
+This file is part of Euphorik.
+
+Euphorik is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+Euphorik is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Euphorik. If not, see .
+=end
-#TODO :
-# - mettre à jour les numéros de versions en appelant le script "cope_num_version.rb"
-# - création de unit tests (voir eunit) et validation avant la mise en prod
+# TODO :
+# - création de unit tests (voir eunit) et validation avant la mise en prod
+# Met à disposition plusieurs outils (classes), tel que :
+# - Vérification du code javascript
+# - Mise à jour du numéro de version à partir du fichier VERSION
+# - Mise en production et en preproduction
+# tools.rb peut s'utiliser à la ligne de commande, exemples :
+# * Mise en production :
+# ./tools.rb --doprod gburri@euphorik.ch:/var/www/euphorik
+# * Mise en préproduction, l'emplacement de production peut être indiqué pour copier la base
+# ./tools.rb --dopreprod gburri@euphorik.ch:/var/www/euphorik_preprod --prod gburri@euphorik.ch:/var/www/euphorik
+
+# Classe permettant la vérification du code JS pas jslint.
+# Passe en revu chaque fichier js de manière récursive à partir d'un dossier de départ.s
+class VerifJS
+
+ def initialize(dossier)
+ @dossier = dossier
+ end
+
+ def verifier
+ verifierRecu(@dossier)
+ end
+
+ def verifierRecu(dossier)
+ Dir.foreach(dossier){|fichier|
+ if fichier != '.' and fichier != '..' and File.directory?(fichier) and fichier != 'dirs'
+ if not verifierRecu(dossier + '/' + fichier)
+ return false
+ end
+ elsif fichier[-3, 3] == '.js'
+ puts "== Vérification de #{dossier}/#{fichier} =="
+ system("java org.mozilla.javascript.tools.shell.Main jslint.js #{dossier}/#{fichier}")
+ puts $?.exitstatus
+ if $?.exitstatus > 0
+ return false
+ end
+ end
+ }
+ return true
+ end
+end
+
+# Classe de gestion de la version
+class Version
+ # @param dossier la racine du site (par exemple "/var/www/euphorik"
+ def initialize(dossier)
+ @dossier = dossier
+ File.open(@dossier + '/VERSION') {|file|
+ @version = file.readline()
+ }
+ # les fichiers HTML dans lesquels mettre à jour la version
+ @fichiers = ['/pages/about.html']
+ @balise = /().*?(<\/span>)/
+ end
+
+ # met à jour la version dans les fichiers @fichiers
+ def maj
+ @fichiers.each{|fichier|
+ fichier = @dossier + fichier
+ lines = IO.readlines(fichier)
+ File.open(fichier, 'w') {|io|
+ lines.each{|l|
+ io.write(l.sub(@balise){|m| $1 + @version + $2})
+ }
+ }
+ }
+ end
+end
+
+# Permet la mise en production et preproduction
class MiseEnProd
+ # obsolète !
@@rep_remote = '/var/www/euphorik'
@@host = 'euphorik.ch'
@@opt_rsync = ''
- def initialize
+ def initialize(prod_uri, preprod_uri)
+ @prod = prod_uri
+ @preprod = preprod_uri
end
+
+ # Effectue la mise en production.
+ def miseEnProd
+ end
+
+ # Effectue la mise en préproduction.
+ def miseEnPreProd
+ end
def creer_remote_rep(rep)
begin
@@ -48,7 +128,7 @@ class MiseEnProd
end
def creer_repertoire_bd
- # création du repertoire BD
+ # création du repertoire BD
creer_remote_rep('BD')
creer_remote_rep('BD/backup')
`ssh #{@@host} "chmod g+w #{@@rep_remote}/BD"`
@@ -63,12 +143,6 @@ class MiseEnProd
print `rsync #{$opt_rsync} -r --exclude 'autres' img #{$host}:#{$rep_remote}`
end
- # contrôle des fichiers js à l'aide de jslint
- # @return false si une erreur est survenue durant la vérification
- def check_js
-
- end
-
# minification et package des fichiers js dans euphorik.js
def pack_js
# copie des js avec minification
@@ -95,8 +169,25 @@ class MiseEnProd
end
def maj
- # execution du script de mise à jour
+ # execution du script de mise à jour
print `cat tools/mise_en_prod.erl | ssh #{$host} "cat > /tmp/mise_en_prod.erl"`
print `ssh #{$host} "chmod u+x /tmp/mise_en_prod.erl; /tmp/mise_en_prod.erl; rm /tmp/mise_en_prod.erl"`
end
-end
+end
+
+# Traite la ligne de commande lorsque tools.rb est utilisé comme tel
+class Commande
+ def traiter
+ #miseEnProd = MiseEnProd.new("gburri@euphorik.ch:/var/www/euphorik", "gburri@euphorik.ch:/var/www/euphorik_preprod")
+ #miseEnProd.miseEnPreProd()
+
+ #verifJS = VerifJS.new("../js")
+ #verifJS.verifier()
+
+ #version = Version.new("..")
+ #version.maj()
+ end
+end
+
+cl = Commande.new
+cl.traiter()