4 Copyright 2008 Grégory Burri
6 This file is part of Euphorik.
8 Euphorik is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 Euphorik is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with Euphorik. If not, see <http://www.gnu.org/licenses/>.
23 # - création de unit tests (voir eunit) et validation avant la mise en prod
25 # Met à disposition plusieurs outils (classes), tel que :
26 # - Vérification du code javascript
27 # - Mise à jour du numéro de version à partir du fichier VERSION
28 # - Mise en production et en preproduction
29 # tools.rb peut s'utiliser à la ligne de commande, exemples :
30 # * Mise en production :
31 # ./tools.rb --doprod gburri@euphorik.ch:/var/www/euphorik
32 # * Mise en préproduction, l'emplacement de production peut être indiqué pour copier la base
33 # ./tools.rb --dopreprod gburri@euphorik.ch:/var/www/euphorik_preprod --prod gburri@euphorik.ch:/var/www/euphorik
35 # Classe permettant la vérification du code JS pas jslint.
36 # Passe en revu chaque fichier js de manière récursive à partir d'un dossier de départ.s
39 def initialize(dossier
)
44 verifierRecu(@dossier)
47 def verifierRecu(dossier
)
48 Dir
.foreach(dossier
){|fichier
|
49 if fichier !
= '.' and fichier !
= '..' and File
.directory
?(fichier
) and fichier !
= 'dirs'
50 if not verifierRecu(dossier +
'/' + fichier
)
53 elsif fichier
[-3, 3] == '.js'
54 puts
"== Vérification de #{dossier}/#{fichier} =="
55 system("java org.mozilla.javascript.tools.shell.Main jslint.js #{dossier}/#{fichier}")
66 # Classe de gestion de la version
68 # @param dossier la racine du site (par exemple "/var/www/euphorik"
69 def initialize(dossier
)
71 File
.open(@dossier +
'/VERSION') {|file
|
72 @version = file
.readline()
74 # les fichiers HTML dans lesquels mettre à jour la version
75 @fichiers = ['/pages/about.html']
76 @balise = /(<span.+?class.*?=.*?"version".*?>).*?(<\/span
>)/
79 # met à jour la version dans les fichiers @fichiers
81 @fichiers.each
{|fichier
|
82 fichier
= @dossier + fichier
83 lines
= IO
.readlines(fichier
)
84 File
.open(fichier
, 'w') {|io
|
86 io
.write(l
.sub(@balise){|m
| $1 +
@version +
$2})
93 # Permet la mise en production et preproduction
96 @
@rep_remote = '/var/www/euphorik'
97 @
@host = 'euphorik.ch'
100 def initialize(prod_uri
, preprod_uri
)
102 @preprod = preprod_uri
105 # Effectue la mise en production.
109 # Effectue la mise en préproduction.
113 def creer_remote_rep(rep
)
115 `ssh #{@@host} "mkdir #{@@rep_remote}/#{rep}"`
120 def compiler_partie_serveuse
121 Dir
.chdir(@
@rep_remote +
'/modules')
123 if $
?.exitstatus !
= 0
124 puts
"Echec de compilation de la partie serveuse"
130 def creer_repertoire_bd
131 # création du repertoire BD
132 creer_remote_rep('BD')
133 creer_remote_rep('BD/backup')
134 `ssh #{@@host} "chmod g+w
#{@@rep_remote}/BD
"`
137 # css, images, html, etc..
138 def copier_partie_statique
139 print `rsync #{$opt_rsync} index.yaws #{$host}:#{$rep_remote}`
140 print `rsync #{$opt_rsync} favicon.ico #{$host}:#{$rep_remote}`
141 print `rsync #{$opt_rsync} -r css #{$host}:#{$rep_remote}`
142 print `rsync #{$opt_rsync} -r pages #{$host}:#{$rep_remote}`
143 print `rsync #{$opt_rsync} -r --exclude 'autres' img #{$host}:#{$rep_remote}`
146 # minification et package des fichiers js dans euphorik.js
148 # copie des js avec minification
150 creer_remote_rep(rep_js)
151 Dir.entries(rep_js).each{|fichier|
152 if fichier[0..0] != '.' and fichier !
= 'debug.js'
153 puts
"Minimisation et copie de #{fichier}"
154 print
`tools/jsmin.rb < #{rep_js}/#{fichier} | ssh #{@@host} "cat > #{@@rep_remote}/#{rep_js}/#{fichier}"`
159 def copie_modules_serveurs
160 # copie des modules erlang
161 creer_remote_rep('modules')
162 `rsync #{@@opt_rsync} -r --exclude 'euphorik_test.beam' modules/ebin #{@@host}:#{@@rep_remote}/modules`
163 `rsync #{@@opt_rsync} -r modules/include #{@@host}:#{@@rep_remote}/modules`
166 def set_droits_fichiers
167 # attribution des droits
168 `ssh #{$host} "chmod -R g+rx
#{$rep_remote}"`
172 # execution du script de mise à jour
173 print `cat tools/mise_en_prod.erl | ssh #{$host} "cat
> /tmp
/mise_en_prod
.erl
"`
174 print `ssh #{$host} "chmod u+x
/tmp/mise_en_prod
.erl
; /tmp/mise_en_prod
.erl
; rm
/tmp/mise_en_prod
.erl
"`
178 # Traite la ligne de commande lorsque tools.rb est utilisé comme tel
181 #miseEnProd = MiseEnProd.new("gburri
@euphorik.ch
:/var/www
/euphorik", "gburri@euphorik.ch:/var
/www/euphorik_preprod
")
182 #miseEnProd.miseEnPreProd()
184 #verifJS = VerifJS.new("../js
")
187 #version = Version.new("..")