(no commit message)
[euphorik.git] / tools / tools.rb
1 #!/usr/bin/ruby
2 # coding: utf8
3 =begin
4 Copyright 2008 Grégory Burri
5
6 This file is part of Euphorik.
7
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.
12
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.
17
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/>.
20 =end
21
22 #TODO :
23 # - mettre à jour les numéros de versions (créer une classe)
24 # - création de unit tests (voir eunit) et validation avant la mise en prod
25 # - faire une classe qui vérifie tous les js avec jslint
26
27 # Classe permettant la vérification du code JS pas jslint.
28 # Passe en revu chaque fichier js de manière récursive à partir d'un dossier de départ.s
29 class VerifJS
30
31 def initialize(dossier)
32 @dossier = dossier
33 end
34
35 def verifier
36 verifierRecu(@dossier)
37 end
38
39 def verifierRecu(dossier)
40 Dir.foreach(dossier){|fichier|
41 if fichier != '.' and fichier != '..' and File.directory?(fichier) and fichier != 'dirs'
42 if not verifierRecu(dossier + '/' + fichier)
43 return false
44 end
45 elsif fichier[-3, 3] == '.js'
46 puts "== Vérification de #{dossier}/#{fichier} =="
47 system("java org.mozilla.javascript.tools.shell.Main jslint.js #{dossier}/#{fichier}")
48 if $?.exitstatus > 0
49 return false
50 end
51 end
52 }
53 return true
54 end
55 end
56
57
58
59 class MiseEnProd
60 @@rep_remote = '/var/www/euphorik'
61 @@host = 'euphorik.ch'
62 @@opt_rsync = ''
63
64 def initialize
65 end
66
67 def creer_remote_rep(rep)
68 begin
69 `ssh #{@@host} "mkdir #{@@rep_remote}/#{rep}"`
70 rescue
71 end
72 end
73
74 def compiler_partie_serveuse
75 Dir.chdir(@@rep_remote + '/modules')
76 puts `make`
77 if $?.exitstatus != 0
78 puts "Echec de compilation de la partie serveuse"
79 exit 1
80 end
81 Dir.chdir('..')
82 end
83
84 def creer_repertoire_bd
85 # création du repertoire BD
86 creer_remote_rep('BD')
87 creer_remote_rep('BD/backup')
88 `ssh #{@@host} "chmod g+w #{@@rep_remote}/BD"`
89 end
90
91 # css, images, html, etc..
92 def copier_partie_statique
93 print `rsync #{$opt_rsync} index.yaws #{$host}:#{$rep_remote}`
94 print `rsync #{$opt_rsync} favicon.ico #{$host}:#{$rep_remote}`
95 print `rsync #{$opt_rsync} -r css #{$host}:#{$rep_remote}`
96 print `rsync #{$opt_rsync} -r pages #{$host}:#{$rep_remote}`
97 print `rsync #{$opt_rsync} -r --exclude 'autres' img #{$host}:#{$rep_remote}`
98 end
99
100 # minification et package des fichiers js dans euphorik.js
101 def pack_js
102 # copie des js avec minification
103 rep_js = 'js'
104 creer_remote_rep(rep_js)
105 Dir.entries(rep_js).each{|fichier|
106 if fichier[0..0] != '.' and fichier != 'debug.js'
107 puts "Minimisation et copie de #{fichier}"
108 print `tools/jsmin.rb < #{rep_js}/#{fichier} | ssh #{@@host} "cat > #{@@rep_remote}/#{rep_js}/#{fichier}"`
109 end
110 }
111 end
112
113 def copie_modules_serveurs
114 # copie des modules erlang
115 creer_remote_rep('modules')
116 `rsync #{@@opt_rsync} -r --exclude 'euphorik_test.beam' modules/ebin #{@@host}:#{@@rep_remote}/modules`
117 `rsync #{@@opt_rsync} -r modules/include #{@@host}:#{@@rep_remote}/modules`
118 end
119
120 def set_droits_fichiers
121 # attribution des droits
122 `ssh #{$host} "chmod -R g+rx #{$rep_remote}"`
123 end
124
125 def maj
126 # execution du script de mise à jour
127 print `cat tools/mise_en_prod.erl | ssh #{$host} "cat > /tmp/mise_en_prod.erl"`
128 print `ssh #{$host} "chmod u+x /tmp/mise_en_prod.erl; /tmp/mise_en_prod.erl; rm /tmp/mise_en_prod.erl"`
129 end
130 end
131
132
133 v = VerifJS.new("../js")
134 v.verifier()