Class: Wraith::FolderManager
- Inherits:
-
Object
- Object
- Wraith::FolderManager
- Includes:
- Logging
- Defined in:
- lib/wraith/folder.rb
Instance Attribute Summary collapse
-
#wraith ⇒ Object
readonly
Returns the value of attribute wraith.
Instance Method Summary collapse
- #clear_shots_folder ⇒ Object
- #copy_base_images ⇒ Object
- #copy_old_shots ⇒ Object
- #create_folders ⇒ Object
- #dir ⇒ Object
- #history_dir ⇒ Object
-
#initialize(config) ⇒ FolderManager
constructor
A new instance of FolderManager.
- #paths ⇒ Object
- #spider_paths ⇒ Object
- #threshold_rate(dirs) ⇒ Object
- #tidy_shots_folder(dirs) ⇒ Object
Methods included from Logging
Constructor Details
#initialize(config) ⇒ FolderManager
Returns a new instance of FolderManager.
8 9 10 |
# File 'lib/wraith/folder.rb', line 8 def initialize(config) @wraith = Wraith::Wraith.new(config) end |
Instance Attribute Details
#wraith ⇒ Object (readonly)
Returns the value of attribute wraith.
6 7 8 |
# File 'lib/wraith/folder.rb', line 6 def wraith @wraith end |
Instance Method Details
#clear_shots_folder ⇒ Object
33 34 35 36 |
# File 'lib/wraith/folder.rb', line 33 def clear_shots_folder FileUtils.rm_rf("./#{dir}") FileUtils.mkdir_p("#{dir}") end |
#copy_base_images ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/wraith/folder.rb', line 53 def copy_base_images logger.info "COPYING BASE IMAGES" wraith.paths.each do |path| path = path[0] logger.info "Copying #{history_dir}/#{path} to #{dir}" FileUtils.cp_r(Dir.glob("#{history_dir}/#{path}"), dir) end end |
#copy_old_shots ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/wraith/folder.rb', line 38 def copy_old_shots if history_dir.nil? logger.error "no `history_dir` attribute found in config. Cannot copy files." else FileUtils.mkdir_p("#{history_dir}") FileUtils.cp_r("#{dir}/.", "#{history_dir}/") FileUtils.rm_rf("#{history_dir}/thumbnails") # thumbnails aren't generated until the gallery stage anyway FileUtils.rm_rf("#{dir}") # get rid of the live folder Dir["#{history_dir}/**/*.png"].each do |filepath| new_name = filepath.gsub("latest.png", "base.png") File.rename(filepath, new_name) end end end |
#create_folders ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/wraith/folder.rb', line 62 def create_folders spider_paths.each do |folder_label, path| unless path path = folder_label folder_label = path.gsub("/", "__") end FileUtils.mkdir_p("#{dir}/thumbnails/#{folder_label}") FileUtils.mkdir_p("#{dir}/#{folder_label}") end logger.info "Creating Folders" end |
#dir ⇒ Object
12 13 14 |
# File 'lib/wraith/folder.rb', line 12 def dir wraith.directory end |
#history_dir ⇒ Object
16 17 18 |
# File 'lib/wraith/folder.rb', line 16 def history_dir wraith.history_dir end |
#paths ⇒ Object
20 21 22 |
# File 'lib/wraith/folder.rb', line 20 def paths wraith.paths end |
#spider_paths ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/wraith/folder.rb', line 24 def spider_paths if !paths paths = File.read(wraith.spider_file) eval(paths) else wraith.paths end end |
#threshold_rate(dirs) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/wraith/folder.rb', line 86 def threshold_rate(dirs) dirs.each do |_folder_name, shot_info| shot_info.each do |_k, v| begin return false unless v.include?(:diff) return false if v[:data] > wraith.threshold rescue return true end end end end |
#tidy_shots_folder(dirs) ⇒ Object
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/wraith/folder.rb', line 75 def tidy_shots_folder(dirs) if wraith.mode == "diffs_only" dirs.each do |folder_name, shot_info| if shot_info.none? { |_k, v| v[:data] > 0 } FileUtils.rm_rf("#{wraith.directory}/#{folder_name}") dirs.delete(folder_name) end end end end |