Papy-tools 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2011 Fabien Turmel
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
data/NEWS.md ADDED
File without changes
@@ -0,0 +1,115 @@
1
+
2
+
3
+ Papy-tools
4
+ ----------
5
+
6
+ papy-tools est un outil qui permet de génèrer des grilles americaines adaptés au web.
7
+ vous pouvez voir un exemple sur notre site [http://www.caenalekhine.fr/grilles/opentoussaint/toussaint2011.html](http://www.caenalekhine.fr/grilles/opentoussaint/toussaint2011.html).
8
+
9
+ Pré-requis
10
+ ----------
11
+
12
+ Papy-tools nécessite le langage ruby installé sur votre machine.
13
+ Ci-dessous,pour ceux qui ne dispose de ruby sur leur machine,voir la procédure ci-desssous.
14
+
15
+ Installation sous window
16
+ ------------------------
17
+
18
+ Télécharger ruby à l'adresse suivante [http://rubyinstaller.org/downloads/](http://rubyinstaller.org/downloads/)
19
+
20
+ Une fois installé,ouvrir la console windows.
21
+
22
+ Tapez *gem install papy-tools --platform 386-mswin32*
23
+
24
+
25
+ Installation sous Linux
26
+ -------------------------------------------
27
+
28
+ Ruby est disponible dans toutes les distributions Linux.
29
+ Utiliser le gestionnaire de logiciel ou de paquets de votre distributions.
30
+
31
+ Exemple sous ubuntu et debian,
32
+
33
+ *sudo aptitude install ruby1.9.1-full*
34
+
35
+ Une fois installé,tapez gem install papy-tools
36
+
37
+
38
+ Utilisation
39
+ --------------------------------------------
40
+
41
+ En mode console cree un nouveau repertoire de travail et installez vous dedans.
42
+
43
+ Tapez *papy-tools init*
44
+
45
+ Ceci cree les repertoires source,output,template et helper.
46
+ source désigne l'emplacement des fichiers html crée par papy.
47
+ output désigne l'emplacement des fichiers généres par papy-tools.
48
+ template désigne les gabarits utilisés pour la transformations des fichiers.
49
+ helper désigne des utilitaires utilisés par les templates.
50
+
51
+ Si vous êtes programmeur,vous pouvez modifier ou creer vos propres templates et helpers.
52
+
53
+ Taper *papy-tools list-template*
54
+
55
+ il devrait afficher la liste des templates existants.
56
+
57
+ *defaut.html.erb* utilisé par defaut.
58
+ *etendu.html.erb* permet d'ajouter des filtres aux grilles
59
+ *format.json.erb* pour les programmeurs transforme la grille en format JSON
60
+ *format.yaml.erb* pour les programmeurs transforme la grille en format YAML
61
+
62
+ Ajouter une grille americaine dans le repertoire source et taper *papy-tools create _nom_grilleamericaine*
63
+
64
+ Dans le repertoire output est créé notre grille americaine magique.
65
+
66
+ On peut aussi créer directement une grille americaine a partir d'une grille du site de la FFE .
67
+
68
+ exemple:
69
+
70
+ *papy-tools create 'http://www.echecs.asso.fr/Resultat.aspx?URL=Tournois/Id/20009/20009&Action=Ga'*
71
+
72
+ Pour les differentes options disponible,allez voir la section usage
73
+
74
+ Usage
75
+ ------
76
+ Usage:
77
+
78
+ *papytools commandes [arguments..] [options..]*
79
+
80
+ commandes:
81
+
82
+ init: cree les differents repertoires source,output,templates et helpers et importent les differents templates et helpers.
83
+
84
+ list-template: liste les templates disponibles
85
+
86
+ create argument [options]: cree la grille americaine avec comme template default.html.erb.argument peut etre l'url de la grille sur le site de la FFE ou un fichier grille americaine généré par papy contenu dans le repertoire source.le fichier cree est dans le repertoire output
87
+
88
+ exemples:
89
+
90
+ *papy-tools create 'http://www.echecs.asso.fr/Resultat.aspx?URL=Tournois/Id/20009/20009&Action=Ga'*
91
+
92
+ *papy-tools create regentblitznovembre.html*
93
+
94
+ options pour create:
95
+
96
+ --ligue argument :cree en filtrant la grille à une ligue
97
+
98
+ --premiers argument :cree en filtrant la grille au n [argument] premiers joueurs
99
+
100
+ --template argument :cree en utilisant un template contenu dans le repertoire template
101
+
102
+ --liste argument :cree en ajoutant la liste des joueurs gêrés par papy.permet d'obtenir les clubs pour la grille americaine. argument est le fichier liste des joueurs généré par papy contenu dans le repertoire source.
103
+
104
+ --output argument :change le nom du fichier.le nom du fichier ne doit pas contenir d'extension.
105
+
106
+ --invisible argument :rend invisibles certaines colonnes de la grille.argument prend comme valeur une chaine de caractêre.cette chaine de caractêre peut contenir les lettre c,l,p,d representant respectivement les colonnes club,ligue,pays et les colonnes departages.
107
+
108
+
109
+
110
+
111
+
112
+
113
+
114
+
115
+
@@ -0,0 +1,13 @@
1
+ # encoding: utf-8
2
+ require File.join(File.dirname(__FILE__),"lib","papy-tools.rb")
3
+
4
+ desc "integration continue des tests"
5
+
6
+ task :autotest do
7
+ system("watchr")
8
+ end
9
+
10
+ task :specs do
11
+ specs=Dir['spec/**/*_spec.rb']
12
+ system(" rspec -cfs #{specs.join(' ')}")
13
+ end
@@ -0,0 +1,7 @@
1
+ #! /usr/bin/env ruby
2
+ # encoding: utf-8
3
+ require File.join(File.dirname(__FILE__),"..","lib","papy-tools")
4
+
5
+ PapyTools::Commande.instance.run
6
+
7
+
@@ -0,0 +1,104 @@
1
+ module DefaultHelper
2
+
3
+ def couleur_style_noir(style)
4
+ case style
5
+ when :image
6
+ "<img src='images/clr_bl.gif'>&nbsp;"
7
+ when :div
8
+ "<div class='noir'></div>"
9
+ end
10
+ end
11
+
12
+ def couleur_style_blanc(style)
13
+ case style
14
+ when :image
15
+ "<img src='images/clr_wh.gif'>&nbsp;"
16
+ when :div
17
+ "<div class='blanc'></div>"
18
+ end
19
+ end
20
+
21
+ def couleur_joueur(ronde,style=:image)
22
+ if ronde.exempt || ronde.forfait_prevenu
23
+ ""
24
+ else
25
+ if ronde.couleur=="B"
26
+ couleur_style_blanc(style)
27
+ else
28
+ couleur_style_noir(style)
29
+ end
30
+ end
31
+ end
32
+
33
+ def couleur_joueur_adversaire(ronde,style=:image)
34
+ if ronde.exempt || ronde.forfait_prevenu
35
+ ""
36
+ else
37
+ if ronde.couleur=="N"
38
+ couleur_style_blanc(style)
39
+ else
40
+ couleur_style_noir(style)
41
+ end
42
+ end
43
+ end
44
+
45
+ def nom_adversaire(ronde,joueurs)
46
+ if ronde.exempt || ronde.forfait_prevenu
47
+ ""
48
+ else
49
+ joueurs[ronde.proxyadversaire.to_i-1].nom
50
+ end
51
+ end
52
+
53
+ def elo_adversaire(ronde,joueurs)
54
+ if ronde.exempt || ronde.forfait_prevenu
55
+ ""
56
+ else
57
+ joueurs[ronde.proxyadversaire.to_i-1].elo
58
+ end
59
+ end
60
+
61
+ def couleurligne(cle)
62
+ if cle.to_i.divmod(2)[1]==0
63
+ cle
64
+ "ligneclaire"
65
+ else
66
+ "lignefonce"
67
+ end
68
+ end
69
+
70
+ def couleur_ligne(hash)
71
+ hash[:default]= if hash[:default]=="lignefonce"
72
+ "ligneclaire"
73
+ else
74
+ "lignefonce"
75
+ end
76
+ end
77
+
78
+ def class_ligne(hash)
79
+ hash[:default]= if hash[:default]=="papi_small_f"
80
+ "papi_small_c"
81
+ else
82
+ "papi_small_f"
83
+ end
84
+
85
+ end
86
+
87
+ def format_titre(titre)
88
+ if titre==""
89
+ "&nbsp;"
90
+ else
91
+ titre
92
+ end
93
+
94
+ end
95
+
96
+ def visibilite(colonne)
97
+ if @invisibles[colonne]
98
+ "class='invisible'"
99
+ else
100
+ ""
101
+ end
102
+ end
103
+
104
+ end
@@ -0,0 +1,26 @@
1
+ # encoding: utf-8
2
+
3
+ LIB=File.expand_path( File.dirname __FILE__ )
4
+
5
+ $: << LIB
6
+
7
+ HELPER=File.join File.expand_path(File.dirname __FILE__ ),"../helper"
8
+
9
+ $: << HELPER
10
+
11
+ TEMPLATE=File.join File.expand_path(File.dirname __FILE__ ),"../template"
12
+
13
+ require 'rubygems'
14
+ require 'hpricot'
15
+ require 'erb'
16
+ require 'yaml'
17
+ require 'open-uri'
18
+ require 'fileutils'
19
+ require 'getoptlong'
20
+ require 'json'
21
+
22
+ require 'papy-tools/fabriquetournoi'
23
+ require 'papy-tools/fabriquejoueur'
24
+ require 'papy-tools/presentation'
25
+ require 'papy-tools/commande'
26
+ require 'papy-tools/tournoi'
@@ -0,0 +1,316 @@
1
+ # encoding: utf-8
2
+
3
+ module PapyTools
4
+
5
+
6
+ class Commande
7
+
8
+ def initialize
9
+
10
+ end
11
+
12
+ def self.instance()
13
+ @instance||=new()
14
+ end
15
+
16
+ def run(options={})
17
+
18
+ Dir.glob(File.join(Dir.pwd,"helper","*.rb")).each do |f|
19
+ require f
20
+ end
21
+
22
+ if ARGV.length<1
23
+ CommandeHelp.instance.run()
24
+ exit(0)
25
+ end
26
+ commande=ARGV.first
27
+ case commande
28
+ when "create"
29
+ CommandeCreate.instance.run()
30
+ when "list-template"
31
+ CommandeListTemplate.instance.run()
32
+ when "init"
33
+ CommandeInit.instance.run()
34
+ else
35
+ CommandeHelp.instance.run()
36
+ end
37
+ end
38
+ end
39
+
40
+ class CommandeHelp<Commande
41
+
42
+ def initialize()
43
+ @help = <<-END
44
+
45
+ Usage:
46
+
47
+ papytools commandes [arguments..] [options..]
48
+
49
+ commandes:
50
+
51
+ init: cree les differents repertoires source,output,templates et helpers
52
+ et importent les differents templates et helpers.
53
+
54
+ list-template: liste les templates disponibles
55
+
56
+ create argument [options]: cree la grille americaine avec comme template default.html.erb.
57
+
58
+ argument peut etre l'url de la grille sur le site de la FFE ou
59
+
60
+ un fichier grille americaine généré par papy contenu dans le
61
+
62
+ repertoire source.le fichier cree est dans le repertoire output
63
+
64
+ exemples:
65
+
66
+ papy-tools create 'http://www.echecs.asso.fr/Resultat.aspx?URL=Tournois/Id/20009/20009&Action=Ga'
67
+
68
+ papy-tools create regentblitznovembre.html
69
+
70
+ options pour create:
71
+
72
+ --ligue argument :cree en filtrant la grille à une ligue
73
+
74
+ --premiers argument :cree en filtrant la grille au n [argument] premiers joueurs
75
+
76
+ --template argument :cree en utilisant un template contenu dans le repertoire template
77
+
78
+ --liste argument :cree en ajoutant la liste des joueurs gêrés par papy.
79
+
80
+ permet d'obtenir les clubs pour la grille americaine.
81
+
82
+ argument est le fichier liste des joueurs généré par papy
83
+
84
+ contenu dans le repertoire source.
85
+
86
+ --output argument :change le nom du fichier.
87
+
88
+ le nom du fichier ne doit pas contenir d'extension.
89
+
90
+ --invisible argument :rend invisibles certaines colonnes de la grille.
91
+
92
+ argument prend comme valeur une chaine de caractêre.
93
+
94
+ cette chaine de caractêre peut contenir les lettre c,l,p,d
95
+
96
+ representant respectivement les colonnes club,ligue,pays et les colonnes departages.
97
+
98
+
99
+
100
+
101
+ END
102
+ end
103
+
104
+ def run(options={})
105
+
106
+ print @help
107
+
108
+ end
109
+
110
+ end
111
+
112
+ class CommandeListTemplate<Commande
113
+
114
+ def initialize
115
+ end
116
+
117
+ def run(options={})
118
+ liste=Dir.entries("template")-[".",".."]
119
+ puts "liste des templates"
120
+ puts "-------------------"
121
+ liste.each {|t| puts t}
122
+ end
123
+ end
124
+
125
+ class CommandeInit<Commande
126
+
127
+ def initialize
128
+ end
129
+
130
+ def run(options={})
131
+ Dir.mkdir("source") unless File.exist?("source")
132
+ Dir.mkdir("output") unless File.exist?("output")
133
+ Dir.mkdir("template") unless File.exist?("template")
134
+ Dir.mkdir("helper") unless File.exist?("helper")
135
+ FileUtils.cp_r TEMPLATE+"/.","template"
136
+ FileUtils.cp_r HELPER+"/.","helper"
137
+ end
138
+
139
+ end
140
+
141
+ class CommandeCreate<Commande
142
+
143
+ def initialize
144
+ @template="default.html.erb"
145
+ @opts = GetoptLong.new([ '--club', '-c', GetoptLong::NO_ARGUMENT ],
146
+ [ '--pays', '-a', GetoptLong::NO_ARGUMENT ],
147
+ ['--ligue','-l',GetoptLong::REQUIRED_ARGUMENT ],
148
+ ['--premiers','-p',GetoptLong::REQUIRED_ARGUMENT ],
149
+ ['--departage','-d',GetoptLong::NO_ARGUMENT],
150
+ ['--template','-t',GetoptLong::REQUIRED_ARGUMENT ],
151
+ ['--liste','-L',GetoptLong::REQUIRED_ARGUMENT],
152
+ ['--output','-o',GetoptLong::REQUIRED_ARGUMENT],
153
+ ['--invisibles','-i',GetoptLong::REQUIRED_ARGUMENT]
154
+
155
+ )
156
+ @filtres={}
157
+ @invisibles={:ligue=>false,:categorie=>false,:club=>false,:pays=>false,:departages=>false}
158
+ end
159
+
160
+ def run(options={})
161
+ ressource=ARGV[1]
162
+ if URI.extract(ressource).empty?
163
+ CommandeCreateWithHTM.instance.run()
164
+ else
165
+ CommandeCreateWithSite.instance.run()
166
+ end
167
+
168
+ end
169
+
170
+
171
+ def filter_erb()
172
+ begin
173
+ io=open(File.join("template",@template))
174
+ rescue Exception
175
+ puts "template non trouvé:#{@template}"
176
+ exit 0
177
+ end
178
+ view= ERB.new(io.readlines.join("\n") , 0, "%<>")
179
+ @content=view.result(@presentation.get_binding)
180
+ end
181
+
182
+ def output()
183
+ File.open(@output_file,"w") do |f|
184
+ f.puts @content
185
+ end
186
+ end
187
+
188
+ def input(input)
189
+ begin
190
+ io=open(input)
191
+ rescue
192
+ puts "fichier non trouvé:#{input}"
193
+ exit 0
194
+ end
195
+ content=io.readlines.join("\n")
196
+ Hpricot(content, :xhtml_strict => true)
197
+
198
+ end
199
+
200
+ def set_invisible(arg)
201
+ arg.split("").each do |c|
202
+ case c
203
+ when 'l'
204
+ @invisibles[:ligue]=true
205
+ when 'p'
206
+ @invisibles[:pays]=true
207
+ when 'd'
208
+ @invisibles[:departages]=true
209
+ when 'c'
210
+ @invisibles[:club]=true
211
+ when 'a'
212
+ @invisibles[:categorie]=true
213
+ end
214
+ end
215
+ end
216
+
217
+ def name_output_file
218
+ @output_file=File.join("output",@output_file)
219
+ output_part=@template.split(".")
220
+ output_type_file=output_part[1] if output_part.length == 3
221
+ @output_file=@output_file+"."+output_type_file if output_type_file
222
+ end
223
+
224
+ def parametres
225
+
226
+ @opts.each do |opt, arg|
227
+ case opt
228
+ when '--pays'
229
+ @filtres[:pays]=arg
230
+ when '--ligue'
231
+ @filtres[:ligue]=arg
232
+ when '--premiers'
233
+ @filtres[:premiers]=arg
234
+ p "filtre premiers"
235
+ when '--departage'
236
+ options[:departage]=false
237
+ when '--template'
238
+ @template=arg
239
+ when "--liste"
240
+ @liste=arg
241
+ when "--output"
242
+ @output=arg
243
+ when "--invisibles"
244
+ set_invisible(arg)
245
+ end
246
+ end
247
+ end
248
+ end
249
+
250
+ class CommandeCreateWithSite<CommandeCreate
251
+
252
+
253
+ def initialize()
254
+ super()
255
+ parametres()
256
+ end
257
+
258
+ def run(options={})
259
+ @url=ARGV[1]
260
+ url_base=@url.split("&").first
261
+ @url_grille=url_base+"&Action=Ga"
262
+ @url_liste=url_base+"&Action=Ls"
263
+ @doc=input(@url_grille)
264
+ @liste=input(@url_liste)
265
+ options[:liste]=@liste
266
+ @invisibles[:FFE]=true
267
+ @tournoi=FabriqueTournoiFFE.instance.construction(@doc,options)
268
+ if @output
269
+ @output_file=@output
270
+ else
271
+ @output_file=@tournoi.titre.split(":").first()
272
+ end
273
+ @presentation=Presentation.new(@tournoi,@invisibles,@filtres)
274
+ filter_erb
275
+ name_output_file
276
+ output
277
+ end
278
+ end
279
+
280
+ class CommandeCreateWithHTM<CommandeCreate
281
+
282
+ def initialize()
283
+ super()
284
+ parametres()
285
+ end
286
+
287
+
288
+ def run()
289
+
290
+
291
+ @input_file=ARGV[1]
292
+ if @output
293
+ @output_file=@output
294
+ else
295
+ @output_file=@input_file.split(".").first
296
+ end
297
+ @input_file=File.join("source",@input_file)
298
+
299
+ @doc=input(@input_file)
300
+ options={}
301
+ if @liste
302
+ @liste=File.join("source",@liste)
303
+ @doc_liste=input(@liste)
304
+ options[:liste]=@doc_liste
305
+ end
306
+ @tournoi=FabriqueTournoi.instance.construction(@doc,options)
307
+ @presentation=Presentation.new(@tournoi,@invisibles,@filtres)
308
+ filter_erb
309
+ name_output_file
310
+ output
311
+ end
312
+
313
+
314
+ end
315
+
316
+ end