-#!/usr/bin/ruby\r
-# coding: utf-8\r
-=begin\r
-Copyright 2008 Grégory Burri\r
-\r
-This file is part of Euphorik.\r
-\r
-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
-class MiseEnProd\r
- # obsolète !\r
- @@rep_remote = '/var/www/euphorik'\r
- @@host = 'euphorik.ch'\r
- @@opt_rsync = ''\r
- \r
- def initialize(prod_uri, preprod_uri) \r
- @prod = prod_uri\r
- @preprod = preprod_uri\r
- end \r
- \r
- # Effectue la mise en production.\r
- def miseEnProd\r
- end\r
- \r
- # Effectue la mise en préproduction.\r
- def miseEnPreProd\r
- end\r
-\r
- def creer_remote_rep(rep) \r
- begin\r
- `ssh #{@@host} "mkdir #{@@rep_remote}/#{rep}"`\r
- rescue\r
- end\r
- end\r
- \r
- def compiler_partie_serveuse\r
- Dir.chdir(@@rep_remote + '/modules')\r
- puts `make`\r
- if $?.exitstatus != 0\r
- puts "Echec de compilation de la partie serveuse"\r
- exit 1\r
- end\r
- Dir.chdir('..')\r
- end\r
- \r
- def creer_repertoire_bd \r
- # création du repertoire BD\r
- creer_remote_rep('BD')\r
- creer_remote_rep('BD/backup')\r
- `ssh #{@@host} "chmod g+w #{@@rep_remote}/BD"`\r
- end\r
- \r
- # css, images, html, etc..\r
- def copier_partie_statique \r
- print `rsync #{$opt_rsync} index.yaws #{$host}:#{$rep_remote}`\r
- print `rsync #{$opt_rsync} favicon.ico #{$host}:#{$rep_remote}`\r
- print `rsync #{$opt_rsync} -r css #{$host}:#{$rep_remote}`\r
- print `rsync #{$opt_rsync} -r pages #{$host}:#{$rep_remote}`\r
- print `rsync #{$opt_rsync} -r --exclude 'autres' img #{$host}:#{$rep_remote}` \r
- end\r
- \r
- # minification et package des fichiers js dans euphorik.js\r
- def pack_js\r
- # copie des js avec minification\r
- rep_js = 'js'\r
- creer_remote_rep(rep_js)\r
- Dir.entries(rep_js).each{|fichier|\r
- if fichier[0..0] != '.' and fichier != 'debug.js'\r
- puts "Minimisation et copie de #{fichier}"\r
- print `tools/jsmin.rb < #{rep_js}/#{fichier} | ssh #{@@host} "cat > #{@@rep_remote}/#{rep_js}/#{fichier}"`\r
- end\r
- } \r
- end\r
- \r
- def copie_modules_serveurs \r
- # copie des modules erlang\r
- creer_remote_rep('modules')\r
- `rsync #{@@opt_rsync} -r --exclude 'euphorik_test.beam' modules/ebin #{@@host}:#{@@rep_remote}/modules`\r
- `rsync #{@@opt_rsync} -r modules/include #{@@host}:#{@@rep_remote}/modules`\r
- end\r
- \r
- def set_droits_fichiers\r
- # attribution des droits\r
- `ssh #{$host} "chmod -R g+rx #{$rep_remote}"` \r
- end\r
- \r
- def maj\r
- # execution du script de mise à jour\r
- print `cat tools/mise_en_prod.erl | ssh #{$host} "cat > /tmp/mise_en_prod.erl"`\r
- print `ssh #{$host} "chmod u+x /tmp/mise_en_prod.erl; /tmp/mise_en_prod.erl; rm /tmp/mise_en_prod.erl"`\r
- end\r
-end\r
-\r
-\r
-# Traite la ligne de commande lorsque tools.rb est utilisé comme tel\r
-class Commande\r
- def traiter\r
- ARGV\r
- #miseEnProd = MiseEnProd.new("gburri@euphorik.ch:/var/www/euphorik", "gburri@euphorik.ch:/var/www/euphorik_preprod")\r
- #miseEnProd.miseEnPreProd()\r
-\r
- #verifJS = VerifJS.new("../js")\r
- #verifJS.verifier()\r
-\r
- #version = Version.new("..")\r
- #version.maj()\r
- end\r
-end\r
-\r
-cl = Commande.new\r
-cl.traiter()\r
+#!/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 <http://www.gnu.org/licenses/>.
+=end
+
+# 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
+
+# voir : http://net-ssh.rubyforge.org/ssh/v2/api/index.html
+require 'net/ssh'
+
+# 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.+?class.*?=.*?"version".*?>).*?(<\/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(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
+ `ssh #{@@host} "mkdir #{@@rep_remote}/#{rep}"`
+ rescue
+ end
+ end
+
+ def compiler_partie_serveuse
+ Dir.chdir(@@rep_remote + '/modules')
+ puts `make`
+ if $?.exitstatus != 0
+ puts "Echec de compilation de la partie serveuse"
+ exit 1
+ end
+ Dir.chdir('..')
+ end
+
+ def creer_repertoire_bd
+ # création du repertoire BD
+ creer_remote_rep('BD')
+ creer_remote_rep('BD/backup')
+ `ssh #{@@host} "chmod g+w #{@@rep_remote}/BD"`
+ end
+
+ # css, images, html, etc..
+ def copier_partie_statique
+ print `rsync #{$opt_rsync} index.yaws #{$host}:#{$rep_remote}`
+ print `rsync #{$opt_rsync} favicon.ico #{$host}:#{$rep_remote}`
+ print `rsync #{$opt_rsync} -r css #{$host}:#{$rep_remote}`
+ print `rsync #{$opt_rsync} -r pages #{$host}:#{$rep_remote}`
+ print `rsync #{$opt_rsync} -r --exclude 'autres' img #{$host}:#{$rep_remote}`
+ end
+
+ # minification et package des fichiers js dans euphorik.js
+ def pack_js
+ # copie des js avec minification
+ rep_js = 'js'
+ creer_remote_rep(rep_js)
+ Dir.entries(rep_js).each{|fichier|
+ if fichier[0..0] != '.' and fichier != 'debug.js'
+ puts "Minimisation et copie de #{fichier}"
+ print `tools/jsmin.rb < #{rep_js}/#{fichier} | ssh #{@@host} "cat > #{@@rep_remote}/#{rep_js}/#{fichier}"`
+ end
+ }
+ end
+
+ def copie_modules_serveurs
+ # copie des modules erlang
+ creer_remote_rep('modules')
+ `rsync #{@@opt_rsync} -r --exclude 'euphorik_test.beam' modules/ebin #{@@host}:#{@@rep_remote}/modules`
+ `rsync #{@@opt_rsync} -r modules/include #{@@host}:#{@@rep_remote}/modules`
+ end
+
+ def set_droits_fichiers
+ # attribution des droits
+ `ssh #{$host} "chmod -R g+rx #{$rep_remote}"`
+ end
+
+ def maj
+ # 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
+
+
+# Traite la ligne de commande lorsque tools.rb est utilisé comme tel
+class Commande
+ def traiter
+ #ARGV
+
+ Net::SSH.start('euphorik.ch', 'gburri') {|ssh|
+ output = ssh.exec!("hostname")
+ stdout = ""
+ ssh.exec!("ls -l /tmp"){|channel, stream, data|
+ stdout << data if stream == :stdout
+ }
+ puts stdout
+ }
+
+
+ #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()