| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
require 'optparse' |
|---|
| 13 |
|
|---|
| 14 |
development_mode = false |
|---|
| 15 |
test_mode = false |
|---|
| 16 |
only_initial_update = false |
|---|
| 17 |
clear = false |
|---|
| 18 |
force_update_time = nil |
|---|
| 19 |
|
|---|
| 20 |
opts = OptionParser.new |
|---|
| 21 |
opts.banner = <<END_OF_STRING |
|---|
| 22 |
Monitor directories recursively for changes and keep up-to-date |
|---|
| 23 |
information in a database |
|---|
| 24 |
Usage: #{$0} [-d][-i] <directory path> [<directory path>..] || -c |
|---|
| 25 |
END_OF_STRING |
|---|
| 26 |
opts.on("-d", "--development", "Run the daemon in development mode.") { development_mode = true } |
|---|
| 27 |
opts.on("-t", "--test", "Run the daemon in test mode.") { test_mode = true } |
|---|
| 28 |
opts.on("-i", "--initial-only", "Only scan a new directory, do not update continuously.") { only_initial_update = true } |
|---|
| 29 |
opts.on("-c", "--clear", "Clears *all* data for this server out of the database (Use with caution!)") { clear = true } |
|---|
| 30 |
opts.on("-u", "--update-interval SECONDS", "Ignore update_interval stored in database and use given update interval instead") do |_force_update_time| |
|---|
| 31 |
force_update_time = _force_update_time.to_i |
|---|
| 32 |
end |
|---|
| 33 |
opts.on_tail("-h", "--help", "Show this message") do |
|---|
| 34 |
puts opts |
|---|
| 35 |
exit |
|---|
| 36 |
end |
|---|
| 37 |
|
|---|
| 38 |
begin |
|---|
| 39 |
opts.parse!(ARGV) |
|---|
| 40 |
rescue |
|---|
| 41 |
puts opts |
|---|
| 42 |
exit 1 |
|---|
| 43 |
end |
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
if clear |
|---|
| 47 |
if ARGV.length != 0 |
|---|
| 48 |
puts opts |
|---|
| 49 |
exit 1 |
|---|
| 50 |
end |
|---|
| 51 |
else |
|---|
| 52 |
if ARGV.length < 1 |
|---|
| 53 |
puts opts |
|---|
| 54 |
exit 1 |
|---|
| 55 |
end |
|---|
| 56 |
end |
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
if development_mode and test_mode |
|---|
| 60 |
puts "ERROR: you can not specify --development and --test (or -d and -t) at the same time." |
|---|
| 61 |
exit 1 |
|---|
| 62 |
end |
|---|
| 63 |
|
|---|
| 64 |
if development_mode |
|---|
| 65 |
ENV["RAILS_ENV"] = "development" |
|---|
| 66 |
elsif test_mode |
|---|
| 67 |
ENV["RAILS_ENV"] = "test" |
|---|
| 68 |
else |
|---|
| 69 |
ENV["RAILS_ENV"] = "production" |
|---|
| 70 |
end |
|---|
| 71 |
require File.dirname(__FILE__) + '/../config/environment' |
|---|
| 72 |
|
|---|
| 73 |
if clear |
|---|
| 74 |
FileMonitor.database_cleanup |
|---|
| 75 |
exit |
|---|
| 76 |
end |
|---|
| 77 |
|
|---|
| 78 |
FileMonitor.start(ARGV, only_initial_update, force_update_time) |
|---|