|
Revision 7, 0.8 kB
(checked in by astro, 4 years ago)
|
Gallery support
|
| Line | |
|---|
| 1 |
#!/usr/bin/env ruby |
|---|
| 2 |
|
|---|
| 3 |
require 'yaml' |
|---|
| 4 |
$:.unshift('lib') |
|---|
| 5 |
require 'rubygems' |
|---|
| 6 |
require 'blog' |
|---|
| 7 |
require 'objects' |
|---|
| 8 |
|
|---|
| 9 |
class SmallProgressBar |
|---|
| 10 |
def initialize(total) |
|---|
| 11 |
@val = 0 |
|---|
| 12 |
@total = total |
|---|
| 13 |
display |
|---|
| 14 |
end |
|---|
| 15 |
def inc |
|---|
| 16 |
@val += 1 |
|---|
| 17 |
display |
|---|
| 18 |
end |
|---|
| 19 |
def display |
|---|
| 20 |
print "\r[" + ('.' * @val) + (' ' * (@total - @val)) + "]" |
|---|
| 21 |
$stdout.flush |
|---|
| 22 |
end |
|---|
| 23 |
end |
|---|
| 24 |
|
|---|
| 25 |
blog = Blog.new('config.yaml') |
|---|
| 26 |
|
|---|
| 27 |
if ARGV.size != 1 |
|---|
| 28 |
puts "Usage: #{$0} <set directory>" |
|---|
| 29 |
exit |
|---|
| 30 |
end |
|---|
| 31 |
dir = ARGV.shift |
|---|
| 32 |
|
|---|
| 33 |
dir.gsub!(/\/$/, '') |
|---|
| 34 |
set = dir.split('/').last |
|---|
| 35 |
|
|---|
| 36 |
index = YAML::load(File.new("#{dir}/index")) |
|---|
| 37 |
progress = SmallProgressBar.new(index['images'].size) |
|---|
| 38 |
index['images'].each { |filename,meta| |
|---|
| 39 |
img = Image.by_set_and_filename(set, filename) || |
|---|
| 40 |
Image::new(:set=>set, :filename=>filename) |
|---|
| 41 |
|
|---|
| 42 |
img.date = File.ctime("#{dir}/#{filename}") |
|---|
| 43 |
img.tags = meta['tags'] |
|---|
| 44 |
img.write |
|---|
| 45 |
progress.inc |
|---|
| 46 |
} |
|---|
| 47 |
puts "" |
|---|