23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/flickrup.rb', line 23
def run(args = ARGV)
opts = Trollop::options do
opt :once, "Run single pass" opt :nowait, "Upload immediately on change, no delay"
opt :loglevel, "Logging level", :type => :string, :default => "INFO"
opt :logfile, "Log file (-- for STDOUT)", :type => :string, :default => "--"
opt :config, "Configuration file", :type => :string, :default => './flickrup.yml'
opt :timeout, "Timeout/Wait for file modification", :default => 5*60
opt :dryrun, "Dry run, don't move or upload (useful for debugging)"
end
Logging.pre_init(Logger::Severity.const_get(opts.loglevel), opts.logfile == "--" ? STDOUT : opts.logfile)
ENV['HOME'] ||= Etc.getpwuid.dir
config = YAML::load(File.open(opts.config, "r")).inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}.merge opts
if opts.once
Processor.new(config).run
elsif opts.nowait
QuickListener.new(config).run
else
SlowListener.new(config).run
end
@mutex = Mutex.new
@running = ConditionVariable.new
@mutex.synchronize do
@running.wait(@mutex)
end
end
|