Skip to content

Commit ed11855

Browse files
committedFeb 11, 2012
order parts before assigning prev/next. add force-regenerate option.
1 parent 631a9bd commit ed11855

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed
 

‎gall.rb

+22-14
Original file line numberDiff line numberDiff line change
@@ -220,19 +220,23 @@ def initialize(_parent,_path)
220220
Image.new(self,child)
221221
end
222222

223-
@images.each_with_index do |image,i|
224-
# Gah. arr[-1] gives the last, not nil. arr[BIG] gives nil.
225-
image.previous = @images[i-1] unless i==0
226-
image.next = @images[i+1]
227-
end
228-
229223
@movies = files.find_all do |child|
230224
Movie.known_type?(child)
231225
end.map do |child|
232226
Log.debug "Movie! #{child}"
233227
Movie.new(self,child)
234228
end
235229

230+
@galleries = @galleries.sort_by { |g| g.path.to_s.downcase }
231+
@images = @images.sort_by { |i| i.path.to_s.downcase }
232+
@movies = @movies.sort_by { |m| m.path.to_s.downcase }
233+
234+
@images.each_with_index do |image,i|
235+
# Gah. arr[-1] gives the last, not nil. arr[BIG] gives nil.
236+
image.previous = @images[i-1] unless i==0
237+
image.next = @images[i+1]
238+
end
239+
236240
@movies.each_with_index do |movie,i|
237241
# Gah. arr[-1] gives the last, not nil. arr[BIG] gives nil.
238242
movie.previous = @movies[i-1] unless i==0
@@ -246,10 +250,6 @@ def initialize(_parent,_path)
246250
end
247251
end
248252
end
249-
250-
@galleries = @galleries.sort_by { |g| g.path.to_s.downcase }
251-
@images = @images.sort_by { |i| i.path.to_s.downcase }
252-
@movies = @movies.sort_by { |m| m.path.to_s.downcase }
253253
end
254254

255255
def children?()
@@ -489,10 +489,11 @@ class GallRB
489489

490490
attr_accessor :gallery
491491

492-
def initialize(_base_path, _base_url)
492+
def initialize(_base_path, _base_url, _force)
493493
@base_path = _base_path
494494
@base_url = _base_url
495-
@rowsize = 5
495+
@force = _force
496+
@rowsize = 5
496497

497498
@templates = {}
498499
@urls = {}
@@ -566,7 +567,7 @@ def make_media_derivation(name,o)
566567
# BUG: Re-generate only when necessary (if settings change?)
567568
derivation = o.send(name)
568569
if derivation.image?
569-
unless derivation.path.exist?
570+
unless derivation.path.exist? or @force
570571
FileUtils.mkdir_p(derivation.path.dirname)
571572
derivation.resize
572573
end
@@ -819,6 +820,7 @@ def do_rubyprof()
819820
[ '--debug', '-d', GetoptLong::NO_ARGUMENT ],
820821
[ '--profile', '-p', GetoptLong::NO_ARGUMENT ],
821822
[ '--rubyprof', '-r', GetoptLong::NO_ARGUMENT ],
823+
[ '--force', '-f', GetoptLong::NO_ARGUMENT ],
822824
[ '--url', '-u', GetoptLong::REQUIRED_ARGUMENT ]
823825
)
824826

@@ -827,6 +829,8 @@ def do_rubyprof()
827829
base_url = "/photos"
828830
# How do we kickoff album generation?
829831
wrapper = :do_yield
832+
# Should we regenerate all thumb/medium images?
833+
force = false
830834

831835
opts.each do |opt, arg|
832836
case opt
@@ -840,6 +844,9 @@ def do_rubyprof()
840844
when '--rubyprof'
841845
Log.info("Using ruby-prof.")
842846
wrapper = :do_rubyprof
847+
when '--force'
848+
Log.info("Force image regeneration.")
849+
force = true
843850
when '--url'
844851
base_url = arg
845852
end
@@ -851,7 +858,7 @@ def do_rubyprof()
851858
url = cleanpath(File.join(base_url,scan_dir))
852859

853860
Log.info "Base URL: #{url.to_s}"
854-
send(wrapper) { GallRB.new(scan_dir,url).build }
861+
send(wrapper) { GallRB.new(scan_dir,url, force).build }
855862
Log.info("Done")
856863
end
857864

@@ -869,3 +876,4 @@ def do_rubyprof()
869876
# ** Latest is down to about 11M, 42s
870877
# Write my own pathname?
871878
# Tried using yaml for config file; required >5M!
879+
# better use of multiple cpus? parallel index generation? what about images?

0 commit comments

Comments
 (0)
Please sign in to comment.