WebsiteTools 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5fe8a92c0f604827041d332d40b854d4008e3ce9
4
+ data.tar.gz: 74b0b3c6841fa9ac7825daa5892698992380b2bc
5
+ SHA512:
6
+ metadata.gz: 410e3c78ac964540f8afb791c2d63a98cfb85c40b1dc89750f103c8251d906003bacfb4f389ae576b6892c0d9ff82578168df34ae9841176d5a3985c91eb5b9a
7
+ data.tar.gz: 02c4b7bfaf889a163a1a27cbfb2bd82859eff0792ce9c36464fb9d5e4bcebe7d6c031c2cd6b86e1aa58f7fcc1613afaf50353e8cf6939aa76acb888f69d88d26
data/bin/dyn-site ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ cmd=::File.expand_path('../dyn-site.sh', __FILE__)+" "+ARGV.join(" ")
4
+
5
+ out=`/bin/bash -c "#{cmd}"`
6
+
7
+ puts out unless out.empty?
data/bin/dyn-site.sh ADDED
@@ -0,0 +1,78 @@
1
+ #!/bin/bash
2
+
3
+ Cmd=$1
4
+
5
+ #echo "Command: $Cmd"
6
+
7
+ if [ "$Cmd" != "" ]; then
8
+ Cmd="help"
9
+ fi
10
+
11
+ case $Cmd in
12
+ help)
13
+ echo "Aide:"
14
+ echo "----"
15
+ echo " dyn-site rebase <Conf>"
16
+ echo " dyn-site rebase-subdir <Subdir> <Prj> (Subdir=<User>/<PrjPath>)"
17
+ ;;
18
+ rebase)
19
+ Conf=$2
20
+ if [ "${Conf}" = "" ]; then
21
+ exit
22
+ fi
23
+ PUBLIC_ROOT="$HOME/RodaSrv/public/users/${Conf}"
24
+ SITE_ROOT="$HOME/RodaSrv/.site/$Conf"
25
+ PAGES_ROOT="$SITE_ROOT/pages"
26
+ mkdir -p ${SITE_ROOT}
27
+ cp -R ${PUBLIC_ROOT}/* ${SITE_ROOT}/
28
+ cd ${PAGES_ROOT}
29
+ pages=$(ls *.html)
30
+ echo "pages to process: $pages"
31
+ for html in $pages
32
+ do
33
+ rebase_url --from /users/$Conf/ --to / $html
34
+ rebase_url --from /$Conf/ --to / $html
35
+ mv $html ..
36
+ done
37
+ cd $SITE_ROOT
38
+ rm -fr pages
39
+ ;;
40
+ rebase-subdir)
41
+ Subdir=$2
42
+ if [ "${Subdir}" = "" ]; then
43
+ echo "Subdir doit être non vide!"
44
+ exit
45
+ fi
46
+ Prj=$3
47
+ if [ "${Prj}" = "" ]; then
48
+ echo "Prj doit être non vide!"
49
+ exit
50
+ fi
51
+ PUBLIC_ASSETS="$HOME/RodaSrv/public/users/${Subdir}/${Prj}"
52
+ PUBLIC_PAGES="$HOME/RodaSrv/public/pages/${Subdir}/${Prj}"
53
+ SITE_ROOT="$HOME/RodaSrv/.site/$Prj"
54
+ PAGES_ROOT="$SITE_ROOT/pages"
55
+ mkdir -p ${PAGES_ROOT}
56
+ cp ${PUBLIC_PAGES}/* ${PAGES_ROOT}/
57
+ cp -R ${PUBLIC_ASSETS}/* ${SITE_ROOT}/
58
+ cd ${PAGES_ROOT}
59
+ pages=$(ls *.html)
60
+ echo "pages to process: $pages"
61
+ for html in $pages
62
+ do
63
+ rebase_url --from /users/${Subdir}/${Prj}/ --to / $html
64
+ rebase_url --from /${Subdir}/${Prj}/ --to / $html
65
+ mv $html ..
66
+ done
67
+ cd $SITE_ROOT
68
+ rm -fr pages
69
+ ;;
70
+ deploy)
71
+ Conf=$2
72
+ url="sfdsmqrk@ftp.sfds.asso.fr:$Conf/"
73
+ if [ "$3" != "" ]; then
74
+ url="$3"
75
+ fi
76
+ rsync -az $SITE_ROOT/* $url
77
+ ;;
78
+ esac
data/bin/rebase_url ADDED
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ cur=0
4
+ opts={mode: :default, to: ""}
5
+
6
+ ##p ARGV
7
+
8
+ while ["--dir","--mode","--from","--to","--help","--ext"].include? ARGV[cur]
9
+ ##p [:cur,ARGV[cur]]
10
+ case ARGV[cur]
11
+ when "--dir","--help"
12
+ opts[ARGV[cur].to_sym]=true
13
+ cur += 1
14
+ when "--mode"
15
+ opts[:mode]==ARGV[cur+1].to_sym if ["default","href"].include? ARGV[cur+1]
16
+ cur += 2
17
+ when "--from","--to"
18
+ opts[ARGV[cur][2..-1].to_sym]=ARGV[cur+1]
19
+ cur += 2
20
+ when "--ext"
21
+ opts[ARGV[cur].to_sym]=ARGV[cur+1]
22
+ cur += 2
23
+ end
24
+ end
25
+
26
+ file=ARGV[cur]
27
+ opts[:help]=true unless file
28
+ if opts[:help]
29
+ puts "rebase_url [--dir] [--from <from_path>] [--to <to_path>] [--ext <extension>] file"
30
+ else
31
+ ext=opts[:ext] ? "."+opts[:ext] : ""
32
+ files=opts[:dir] ? Dir[File.join(file,"*"+ext)] : [file]
33
+ ##p files
34
+ ##p opts
35
+ files.each do |filename|
36
+ content=File.read(filename)
37
+ File.open(filename,"w") do |f|
38
+ case opts[:mode]
39
+ when :href
40
+ f << content.gsub(/\ href="#{opts[:from]}/," href=\""+opts[:to])
41
+ else
42
+ f << content.gsub(/#{opts[:from]}/,opts[:to])
43
+ end
44
+ end
45
+ end
46
+ end
data/lib/workshop.rb ADDED
@@ -0,0 +1,275 @@
1
+ module Workshop
2
+ def Workshop.format_first_name(first)
3
+ first.split(" ").map{|e| (e.split(/\-/).map{|e2| e2.capitalize}.join("-"))}.join(" ")
4
+ end
5
+
6
+ def Workshop.format_last_name(last)
7
+ last.gsub(/[éèëê]/,"e").gsub(/[ïî]/,"i").gsub(/[ôö]/,"o").upcase
8
+ end
9
+
10
+ def Workshop.format_full_name(name)
11
+ tmp=name.split(" ")
12
+ return ([Workshop.format_first_name(tmp[0])]+tmp[1..-1].map{|e| Workshop.format_last_name(e)}).join(" ")
13
+ end
14
+
15
+ def Workshop.format_full_name_index(name)
16
+ tmp=name.split(" ")
17
+ first=[Workshop.format_first_name(tmp[0])]
18
+ tmp.shift
19
+ while tmp[0][-1,1]=="."
20
+ first << Workshop.format_first_name(tmp[0])
21
+ tmp.shift
22
+ end
23
+ return (tmp.map{|e| Workshop.format_last_name(e)}+first).join(" ")
24
+ end
25
+
26
+ ## For title with all upcase letters, apply the change
27
+ ## dict allows badly transformed word to be corrected! (ex: type-i => Type-I)
28
+ def Workshop.prepare_title(title,dict={})
29
+ mots=title.split(" ")
30
+ if mots.map{|e| e == e.upcase}.all?
31
+ title2=(mots[0]==mots[0].upcase ? mots[0].capitalize : mots[0])
32
+ title2 = dict[title2] || title2
33
+ title2 += " " + (mots[1..-1].map{|e|
34
+ mot2=(e==e.upcase ? e.downcase : e)
35
+ dict[mot2] || mot2
36
+ }.join(" "))
37
+ Dyndoc.warn :title, [title,title2]
38
+ return title2
39
+ else
40
+ return title
41
+ end
42
+ end
43
+
44
+ class Program
45
+
46
+ attr_reader :cfg, :prog, :event, :colors, :rooms, :subms, :guests, :root
47
+
48
+ def initialize(root,program_yml="program.yml",subms_csv="submission_browse.csv",guests_yml="guests.yml",contacts_csv="user_browse.csv")
49
+ @root=root
50
+ require 'yaml'
51
+ @cfg=YAML::load_file(File.join(@root,program_yml))
52
+ @event,@prog,@colors,@rooms=@cfg["event"],@cfg["program"],@cfg["colors"],@cfg["rooms"]
53
+ require 'csv'
54
+ @subms = CSV.read(File.join(@root,subms_csv))
55
+ @subms_extra = (@cfg["subms"] || {})
56
+ @guests=YAML::load_file(File.join(@root,guests_yml))
57
+ @contacts=CSV.read(File.join(@root,contacts_csv))
58
+ end
59
+
60
+ def cell_session(id) #guest or simple info
61
+ ev=@event[id]
62
+ is_talk=(ev.is_a? Hash and ev["speaker"])
63
+ sess={is_talk: is_talk}
64
+ if is_talk
65
+ sess[:room],sess[:chair],sess[:thema],sess[:aut_aff]="","","",""
66
+ sess[:type]=ev["type"]
67
+ sess[:room]=@rooms[ev["place"]]["name"] if ev["place"]
68
+ sess[:thema]=ev["thema"]+" : " if ev["thema"]
69
+ if ev["chairman"]
70
+ sess[:chair]=Workshop.format_full_name(ev["chairman"])
71
+ end
72
+
73
+ if ev["nb"] and ev["nb"]>1
74
+ sess[:nb]=ev["nb"]
75
+ sess[:authors]=[]
76
+ sess[:thema]=ev["thema"]
77
+ (1..ev["nb"]).each do |i| #
78
+ id2=id+"."+i.to_s
79
+ ev2={}
80
+ ev2[:id]=id2
81
+ ev2[:aut_aff]=Workshop.format_full_name(@guests[id2]["author"])+" ("+@guests[id2]["affiliation"]+")"
82
+ ev2[:title]=@guests[id2]["title"]
83
+ ev2[:index]=@guests[id2]["index"]
84
+ ev2[:abstract]=@guests[id2]["abstract"].strip.gsub("\u200B", "") #.gsub("%","\\%")
85
+ sess[:authors] << ev2
86
+ end
87
+ else
88
+ sess[:aut_aff]=Workshop.format_full_name(@guests[id]["author"])+" ("+@guests[id]["affiliation"]+")"
89
+ sess[:author]=Workshop.format_full_name(@guests[id]["author"])
90
+ sess[:author_index]=Workshop.format_full_name_index(@guests[id]["author"])
91
+ sess[:index]=@guests[id]["index"]
92
+ sess[:title]=@guests[id]["title"] || ev["title"]
93
+ sess[:abstract]=@guests[id]["abstract"].strip.gsub("\u200B", "") #.gsub("%","\\%")
94
+ end
95
+ else
96
+ sess[:title]=(ev.is_a? Hash and ev["title"]) ? ev["title"] : ev
97
+ end
98
+ sess
99
+ end
100
+
101
+ def last_subm(s_id) #s_id: id of submission
102
+ subm_res=@subms.select {|subm| subm[0]==s_id}[0]
103
+ if subm_res[5].include? ","
104
+ s_id2=subm_res[5].split(",")[-1]
105
+ #Dyndoc.warn :history, [s,s2]
106
+ subm_res=@subms.select {|subm| subm[0]==s_id2}[0]
107
+ end
108
+ subm_res
109
+ end
110
+
111
+ def subms_session(id)
112
+ chair=Workshop.format_full_name(@event[id]["chairman"] || "Maude Herateur")
113
+ chair="TBA" if @event[id]["chairman"]=="TBA"
114
+ sess={
115
+ topic: @event[id]["topic"],
116
+ chairman: chair,
117
+ place: @rooms[@event[id]["place"]]["name"] || "Room",
118
+ label: @event[id]["label"] || "Label",
119
+ subms: (@event[id]["subms"] || "").split(",").map{|e| e.strip}.map{|s| #
120
+ if s.to_i==0
121
+ @subms_extra[s] ? @subms_extra[s] : @event[s]
122
+ else
123
+ last_subm(s)
124
+ end
125
+ }
126
+ }
127
+ sess
128
+ end
129
+
130
+ def subm_info(subm)
131
+ begin
132
+ if subm.is_a? Array
133
+ authors=subm[4].split("|||").map do |author| #
134
+ tmp=author.split("&&&")
135
+ {
136
+ first_name: Workshop.format_first_name(tmp[0]).strip,
137
+ last_name: Workshop.format_last_name(tmp[1]).strip,
138
+ email: tmp[2],
139
+ institution: (tmp[3] || "").gsub("&","\\\\&")
140
+ }
141
+ end
142
+ title=subm[2].gsub(/[^[:print:]]/,' ')
143
+ else
144
+ title,authors=subm.gsub(/[^[:print:]]/,' '),[]
145
+ end
146
+
147
+ rescue
148
+ authors,title=[],""
149
+ Dyndoc.warn :subm, subm
150
+ end
151
+ info={id: subm[0], authors: authors, title: title, abstract: subm[3].gsub(/[^[:print:]]/,' ').gsub("\u200B", "")} #.gsub("%","\\%")}
152
+ end
153
+
154
+ def textab_cell_session(id,mode=:fr)
155
+ ev=@event[id]
156
+ begin
157
+ if ev.is_a? Hash
158
+ if ev["speaker"]
159
+ if ev["speaker"].include? " et "
160
+ speaker=ev["speaker"].split(" et ").map{|sp| Workshop.format_full_name(sp.strip)}.join(" et ")
161
+ else
162
+ speaker=Workshop.format_full_name(ev["speaker"])
163
+ end
164
+ end
165
+ room=@rooms[ev["place"]]["name"] if ev["place"]
166
+ if ev["chairman"]
167
+ chair=ev["chairman"]=="TBA" ? "TBA" : Workshop.format_full_name(ev["chairman"])
168
+ end
169
+ res=""
170
+ res << "\\textbf{"+ev["thema"]+"}" if ev["thema"]
171
+ res << ": " unless res.empty?
172
+ res << "\\textbf{"+speaker+ "}"
173
+ res << "\\\\"+ev["title"] if ev["title"]
174
+ if mode==:fr
175
+ res << "\\\\\\textit{Mod.} : "+chair+", \\textit{Amphi} : "+room
176
+ else
177
+ res << "\\\\\\textit{Chair}: "+chair+", "+room
178
+ end
179
+ else
180
+ res="\\textbf{"+ev+"}"
181
+ end
182
+ rescue
183
+ res="Problem id=#{id}"
184
+ end
185
+
186
+ res
187
+ end
188
+
189
+ def html_cell_session(id)
190
+ ev=event[id]
191
+ room,chair,speaker="","",""
192
+ if ev.is_a? Hash
193
+ if ev["speaker"]
194
+ if ev["speaker"].include? " et "
195
+ speaker=ev["speaker"].split(" et ").map{|sp| Workshop.format_full_name(sp.strip)}.join(" et ")
196
+ else
197
+ speaker=Workshop.format_full_name(ev["speaker"])
198
+ end
199
+ end
200
+ room=@rooms[ev["place"]]["name"] if ev["place"]
201
+ if ev["chairman"]
202
+ chair=Workshop.format_full_name(ev["chairman"])
203
+ end
204
+ res=""
205
+ res << "<strong>"+ev["thema"]+"</strong>" if ev["thema"]
206
+ res << ": " unless res.empty?
207
+ res << "<strong>"+speaker+ "</strong>"
208
+ res << "<br/>"+ev["title"] if ev["title"]
209
+ res << "<br/><em>Modérateur</em>: "+chair+", <em>Amphi</em>: "+room
210
+ res
211
+ else
212
+ res="<strong>"+ev+"</strong>"
213
+ end
214
+ res
215
+ end
216
+
217
+ def prepare_pdfs(from,to=nil)
218
+ return unless to
219
+ require 'fileutils'
220
+ @prog.each do |k,v|
221
+ v["table"].each do |l|
222
+ h,txt=l.split("->").map{|e| e.strip}
223
+ elts=txt.split(",").map{|e| e.strip}
224
+ elts.each {|elt| #
225
+ unless elt=="empty"
226
+ (@event[elt]["subms"] || "").split(",").map{|e| e.strip}.each{|s|
227
+ unless s.to_i==0
228
+ subm=last_subm(s)
229
+ if subm
230
+ upload_dir=subm[9]
231
+ subm_pdf=Dir[File.join(from,upload_dir,"*")]
232
+ if subm_pdf.length == 1
233
+ FileUtils.mkdir_p to
234
+ FileUtils.cp subm_pdf[0],File.join(to,"subm"+subm[0]+".pdf")
235
+ else
236
+ puts "Warnings: "+s+","+subm_pdf.inspect
237
+ end
238
+ end
239
+ end
240
+ }
241
+ end
242
+ }
243
+ end
244
+ end
245
+ end
246
+
247
+ def prepare_email_list
248
+ emails=[]
249
+ @prog.each do |k,v|
250
+ v["table"].each do |l|
251
+ h,txt=l.split("->").map{|e| e.strip}
252
+ elts=txt.split(",").map{|e| e.strip}
253
+ elts.each {|elt| #
254
+ unless elt=="empty"
255
+ (@event[elt]["subms"] || "").split(",").map{|e| e.strip}.each{|s|
256
+ unless s.to_i==0
257
+ subm=last_subm(s)
258
+ if subm
259
+ emails << @contacts.select{|u|
260
+ u[0]==subm[1]
261
+ }[0][1]
262
+ else
263
+ puts "Warnings: "+s+" missing!"
264
+ end
265
+ end
266
+ }
267
+ end
268
+ }
269
+ end
270
+ end
271
+ return emails
272
+ end
273
+
274
+ end # class Session
275
+ end
metadata ADDED
@@ -0,0 +1,51 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: WebsiteTools
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - CQLS
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-10-12 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: " Tools for Website.\n"
14
+ email: rdrouilh@gmail.com
15
+ executables:
16
+ - rebase_url
17
+ - dyn-site
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - bin/dyn-site
22
+ - bin/dyn-site.sh
23
+ - bin/rebase_url
24
+ - lib/workshop.rb
25
+ homepage: http://cqls.upmf-grenoble.fr
26
+ licenses:
27
+ - MIT
28
+ - GPL-2
29
+ metadata: {}
30
+ post_install_message:
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ requirements:
45
+ - none
46
+ rubyforge_project:
47
+ rubygems_version: 2.6.13
48
+ signing_key:
49
+ specification_version: 4
50
+ summary: Tools for Website
51
+ test_files: []