Class: Flickrup::Runner

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/flickrup.rb

Instance Method Summary collapse

Methods included from Logging

logger, #logger, pre_init

Instance Method Details

#run(args = ARGV) ⇒ Object



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" # flag --once, default false
    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)

  #set home if unset
  ENV['HOME'] ||= Etc.getpwuid.dir

  #load config, symbolise, merge with command line config
  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

  # suspend thread so we don't exit immediately
  @mutex = Mutex.new
  @running = ConditionVariable.new

  @mutex.synchronize do
    @running.wait(@mutex)
  end

end