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 Guillaume Cottenceau <gc3 at bluewin.ch>
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., 675 Mass Ave, Cambridge, MA 02139, 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('ç', 'ç').
91 gsub('é', 'é').
93 gsub('è', 'è').
97 gsub('ù', 'ù').
101 def parse_webalbum_indextxt(filepath)
103 contents = File.open(filepath).readlines
110 elsif line =~ /^\s*TITLE\s*=\s*(.*)/
112 elsif line =~ /^\s*ABSTRACT\s*=\s*(.*)/
114 elsif line =~ /^\s*IMAGE_LEGEND\s*=\s*(.*)/
116 elsif line =~ /^\s*IMAGE_FILE\s*=\s*(.*)/
117 out[:legends][$1] = legend
128 `find #{$source} -type d`.sort.each { |dir|
130 msg 2, _("Handling %s from config list...") % dir
132 if !infos = parse_webalbum_indextxt("#{dir}/index.txt")
136 #- place xml document on proper node
137 xmldir = $xmldoc.elements["//dir[@path='#{utf8(dir)}']"]
139 if infos.has_key?(:title)
140 type = find_subalbum_info_type(xmldir)
141 xmldir.add_attribute("#{type}-caption", utf8_and_entities(infos[:title]))
144 xmldir.elements.each { |element|
145 if %w(image video).include?(element.name)
146 if infos[:legends].has_key?(element.attributes['filename'])
147 element.add_attribute('caption', utf8_and_entities(infos[:legends][element.attributes['filename']]))
159 ios = File.open("#{$conffile}.merged", "w")
160 $xmldoc.write(ios, 0)