This repository has been archived by the owner on Feb 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
68 lines (54 loc) · 1.7 KB
/
Rakefile
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
require 'date'
require 'logger'
require 'os'
desc "Clear Screenshot dir (try=true)"
task :clear_screenshots do
#OS check
unless OS.mac?
error_message = "This Rake task is only for OSX"
log "remove_screenshots.log", Logger::ERROR, error_message
raise error_message
end
screenshot_path = `defaults read com.apple.screencapture location`
screenshot_path.delete!("\n")
# screenshot_type = `defaults read com.apple.screencapture type`
# screenshot_type = ( screenshot_type.empty? )? ".png" : "." + screenshot_type.delete("\n")
screenshot_type = ".png"
if screenshot_path.empty? || !File.directory?(screenshot_path)
log "remove_screenshots.log", Logger::ERROR, "No custom Screenshot DIR. I will not remove files from the desctop."
exit -1
end
files_in_dir = Dir.entries(screenshot_path)
files_in_dir.each do |f|
f_path = screenshot_path + f
days_ago = (Date.today - 30).to_time
if File.ftype(f_path) == "file" && File.extname(f_path) == screenshot_type
if File.mtime(f_path) < days_ago
begin
if ENV['try']
puts "rm " + f_path
else
File.delete f_path
log "remove_screenshots.log", Logger::INFO, "rm " + f_path
end
rescue Exception => e
log "remove_screenshots.log", Logger::ERROR, "Can't remove #{f_path}: #{e.message}"
end
end
end
end
end
def log(file, level, message)
dir = "custom_rake"
if OS.mac?
logging_dir = ENV['HOME'] + "/Library/Logs/" + dir
else
#todo
exit -1
end
unless File.directory?(logging_dir)
Dir.mkdir(logging_dir)
end
log = Logger.new( logging_dir + "/" + file, 'monthly' )
log.add level, message
end