-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.rb
90 lines (71 loc) · 2.55 KB
/
helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# frozen_string_literal: true
require 'config'
require 'digest'
require 'fileutils'
require 'logger'
require 'mini_magick'
require 'optparse'
require 'parallel'
require 'sinatra/activerecord'
require 'streamio-ffmpeg'
require 'timeout'
require 'yaml'
require_relative 'lib/helpers'
require_relative 'lib/folders'
require_relative 'lib/thumbs'
require_relative 'lib/images'
require_relative 'lib/models'
Config.load_and_set_settings("#{File.dirname(__FILE__)}/config/settings.yml")
def logger
@logger ||= Logger.new($stdout)
end
ActiveRecord::Base.establish_connection(
adapter: Settings.db_adapter,
database: Settings.db_name,
password: Settings.db_password,
username: Settings.db_username,
host: Settings.db_host,
encoding: Settings.db_ecnoding,
collation: Settings.db_collation,
pool: Settings.db_pool
)
image_root = Settings.originals_path
thumb_target = Settings.thumb_target
extensions = Settings.image_extentions + Settings.movie_extentions
@options = {}
OptionParser.new do |opts|
opts.banner = 'Usage: helper.rb [options]'
opts.on('--clean-thumbs', TrueClass, 'Clean obsolete Thumbs') do |e|
@options[:clean_thumbs] = e.nil? ? true : e
end
opts.on('--clean-files', TrueClass, 'Clean obsolete Files') do |e|
@options[:clean_files] = e.nil? ? true : e
end
opts.on('--clean-folders', TrueClass, 'Clean obsolete Folders') do |e|
@options[:clean_folders] = e.nil? ? true : e
end
opts.on('--index', TrueClass, 'Start Indexing') do |e|
@options[:index] = e.nil? ? true : e
end
opts.on('--find-duplicates', TrueClass, 'Find Duplicates') do |e|
@options[:find_duplicates] = e.nil? ? true : e
end
opts.on('--ar-logger', TrueClass, 'Activate AcitveRecord Logger') do |e|
@options[:ar_logger] = e.nil? ? true : e
end
opts.on('--add_new_fields', TrueClass, 'add new fields') do |e|
@options[:add_new_fields] = e.nil? ? true : e
end
opts.on('--add_mtime_and_ctime', TrueClass, 'add mtime and ctime') do |e|
@options[:add_mtime_and_ctime] = e.nil? ? true : e
end
end.parse!
ActiveRecord::Base.logger = nil unless @options[:ar_logger]
build_index(image_root, thumb_target, extensions) if @options[:index]
remove_thumb(Settings.thumb_target) if @options[:clean_thumbs]
remove_folders if @options[:clean_folders]
remove_files(Settings.thumb_target) if @options[:clean_files]
find_duplicates if @options[:find_duplicates]
# temporary actions
add_new_fields if @options[:add_new_fields]
add_mtime_and_ctime if @options[:add_mtime_and_ctime]