5 # A.k.a 'Best web-album Of the world, Or your money back, Humerus'.
7 # The acronyn sucks, however this is a tribute to Dragon Ball by
8 # Akira Toriyama, where the last enemy beaten by heroes of Dragon
9 # Ball is named "Boo". But there was already a free software project
10 # called Boo, so this one will be it "Booh". Or whatever.
13 # Copyright (c) 2004-2006 Guillaume Cottenceau <http://zarb.org/~gc/resource/gc_mail.png>
15 # This software may be freely redistributed under the terms of the GNU
16 # public license version 2.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 require 'rexml/document'
28 require 'booh/booh-lib'
33 [ '--help', '-h', GetoptLong::NO_ARGUMENT, _("Get help message") ],
35 [ '--config', '-C', GetoptLong::REQUIRED_ARGUMENT, _("File containing config listing images and videos within directories with captions") ],
37 [ '--verbose-level', '-v', GetoptLong::REQUIRED_ARGUMENT, _("Set max verbosity level (0: errors, 1: warnings, 2: important messages, 3: other messages)") ],
40 #- default values for some globals
45 puts _("Usage: %s [OPTION]...") % File.basename($0)
47 printf " %3s, %-15s %s\n", ary[1], ary[0], ary[3]
52 parser = GetoptLong.new
53 parser.set_options(*$options.collect { |ary| ary[0..2] })
55 parser.each_option do |name, arg|
62 if File.readable?(arg)
63 $xmldoc = REXML::Document.new File.new(arg)
66 die_ _('Config file does not exist or is unreadable.')
69 when '--verbose-level'
70 $verbose_level = arg.to_i
81 die_ _("Missing --config parameter.")
84 $source = $xmldoc.root.attributes['source']
85 $dest = $xmldoc.root.attributes['destination']
88 def utf8_and_entities(string)
89 return utf8(string).gsub('à', 'à').
90 gsub('ç', 'ç').
92 gsub('é', 'é').
94 gsub('è', 'è').
95 gsub('È', 'È').
99 gsub('ù', 'ù').
103 def parse_webalbum_indextxt(filepath)
105 contents = File.open(filepath).readlines
112 elsif line =~ /^\s*TITLE\s*=\s*(.*)/
114 elsif line =~ /^\s*ABSTRACT\s*=\s*(.*)/
116 elsif line =~ /^\s*IMAGE_LEGEND\s*=\s*(.*)/
118 elsif line =~ /^\s*IMAGE_FILE\s*=\s*(.*)/
119 out[:legends][$1] = legend
130 `find #{$source} -type d`.sort.each { |dir|
132 msg 2, _("Handling %s from config list...") % dir
134 if !infos = parse_webalbum_indextxt("#{dir}/index.txt")
138 #- place xml document on proper node
139 xmldir = $xmldoc.elements["//dir[@path='#{utf8(dir)}']"]
141 if infos.has_key?(:title)
142 type = find_subalbum_info_type(xmldir)
143 xmldir.add_attribute("#{type}-caption", utf8_and_entities(infos[:title]))
146 xmldir.elements.each { |element|
147 if %w(image video).include?(element.name)
148 if infos[:legends].has_key?(element.attributes['filename'])
149 element.add_attribute('caption', utf8_and_entities(infos[:legends][element.attributes['filename']]))
161 ios = File.open("#{$conffile}.merged", "w")
162 $xmldoc.write(ios, 0)