Class: DerivedData
- Inherits:
-
Object
- Object
- DerivedData
- Defined in:
- lib/main2.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.clean ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/main2.rb', line 50 def self.clean # cmd = 'sh delete_all_derived_data.sh' # system(cmd) # cmd = "echo 'hi'" # value = %x( echo 'hi' ) # value = %x[ #{cmd} ] # wasGood = system( "echo 'hi'" ) # wasGood = system( cmd ) spinner = TTY::Spinner.new("[:spinner] Search ...", format: :dots_2) spinner.auto_spin # puts File.expand_path('../', __dir__) # system('find ../ -type d -name "DerivedData" 2>/dev/null -exec trash -v {} +') # system('trash -e') somedir = "/Users/nicolaerogojan/gitRepository/Personal/delete_all_derived_data/DerivedData" # FileUtils.remove_dir(somedir) system("echo #{somedir}") # system("trash #{somedir}") # OK system("trash", "-v", "#{somedir}") # system("trash -e") spinner.stop("Done!") end |
.hi(language = "english") ⇒ Object
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 |
# File 'lib/main2.rb', line 13 def self.hi(language = "english") cmd = 'ls' system(cmd) puts "Hello world!" puts language spinner = TTY::Spinner.new("[:spinner] Loading ...", format: :pulse_2) spinner.auto_spin # Automatic animation with default interval # sleep(2) # Perform task derived_paths = [] # Find.find('../..') do |path| # derived_paths << path if path =~ /.*\DerivedData$/ # end Find.find('../') do |path| # derived_paths << File.expand_path(path, __dir__) if path =~ /.*\DerivedData$/ derived_paths << path if path =~ /.*\DerivedData$/ end spinner.stop("Done!") # Stop animation puts derived_paths # trash = Trash.new # trash.throw_out(*derived_paths) # Trash.new.throw_out(*derived_paths) somedir = derived_paths?.first # FileUtils.mv(derived_paths.first, File.expand_path('~/.Trash/')) if File.directory?(somedir) puts somedir FileUtils.remove_dir(somedir) end end |
Instance Method Details
#find ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/main2.rb', line 75 def find logger = Logger.new(STDOUT) logger.level = Logger::DEBUG logger.debug(Dir.home) puts "Started At #{Time.now}" spinner = TTY::Spinner.new("[:spinner] Search ...", format: :dots_2) spinner.auto_spin # base_dir_path = Dir.home # base_dir_path = "/Users/nicolaerogojan/gitRepository" # base_dir_path = "/Users/nicolaerogojan/gitRepository/Personal/delete_all_derived_data" base_dir_path = "/Users/nicolaerogojan/.Trash" # directory_paths = Dir.glob(File.join(base_dir_path, '*', '')) directory_paths = Pathname.new(base_dir_path).children.select { |c| c.directory? && c.basename(path)[0] != ?. } logger.debug base_dir_path logger.debug directory_paths derived_paths = [] arr = [] # directory_paths.each do |f| # arr << Thread.new { # Find.find(f) {|path| derived_paths << path if path =~ /.*\DerivedData$/} # } # end # directory_paths.each do |folder| # Find.find(folder) do |path| # if FileTest.directory?(path) # if File.basename(path)[0] == ?. # Find.prune # Don't look any further into this directory. # else # next # end # else # if path =~ /.*\DerivedData$/ # puts path # derived_paths << path # end # end # end # end directory_paths.each do |folder| arr << Thread.new { Find.find(folder){ |path| next if !File.directory?(path) next if File.basename(path)[0] == ?. # puts File.stat(path).blockdev? next if File.stat(path).blockdev? == true if path =~ /.*\DerivedData$/ puts path derived_paths << path end } } end arr.each {|t| t.join} logger.debug arr.count logger.debug derived_paths # derived_paths.each {|f| logger.debug f; trash(f)} spinner.stop("Done!") puts "End at #{Time.now}" end |
#find2 ⇒ Object
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
# File 'lib/main2.rb', line 160 def find2 spinner = TTY::Spinner.new("[:spinner] Search ...", format: :dots_2) spinner.auto_spin base_dir_path = ENV["HOME"] # base_dir_path = "/Users/nicolaerogojan/.Trash" # directory_paths = Dir.glob(File.join(base_dir_path, '*', '')) directory_paths = [] derived_paths = [] threads = [] Pathname.new(base_dir_path).children.select do |c| # c.directory? && c.zero? # puts "dirname -> #{c.dirname}" # puts "basename -> #{c.basename}" # puts "directory -> #{c.directory?}" # puts "blockdev -> #{c.blockdev?}" # puts "zero -> #{c.zero?}" # puts " -> #{c.to_s[0]}" # puts " -> #{c.to_s[0] != '.'}" # puts " -> #{c.basename != '.'}" # puts " -> #{c.basename.to_s[0] != '.'}" # puts "owned -> #{c.owned?}" # puts "==============================" # if c.directory? && c.zero? == false && c.blockdev? == false && c.basename.to_s[0] != '.' && c.basename.to_s != 'Library' if c.directory? && c.zero? == false && c.blockdev? == false && c.basename.to_s[0] != '.' directory_paths << c end end # puts # puts base_dir_path # puts "==============================" # puts directory_paths # puts "==============================" directory_paths.each do |folder| threads << Thread.new { begin Find.find(folder, ignore_error: true) {|path| derived_paths << path if path =~ /.*\DerivedData$/} rescue Exception => e puts e. end } end # Thread.abort_on_exception = false # Thread.report_on_exception = false # threads.each {|t| t.abort_on_exception = false; t.report_on_exception = false; t.join} threads.each {|t| t.join} # table = TTY::Table.new(["header1","header2"], [["a1", "a2"], ["b1", "b2"]]) # roys = [["a1"], ["a2"]] # roys = [] # directory_paths.each do |folder| # roys << [folder] # end roys = directory_paths.map { |f| [f] } table = TTY::Table.new(["directory_paths"], roys) puts puts table.render(:ascii) puts derived_paths puts "==============================" xcode_archives_size = Filesize.size(Dir["#{ENV["HOME"]}/Library/Developer/Xcode/Archives/**/*"].select { |f| File.file?(f) }.sum { |f| File.size(f) }) puts "Xcode Archives size: #{xcode_archives_size}" spinner.stop("Done!") prompt = TTY::Prompt.new # answer = prompt.yes?("Do you like Ruby?") answer = prompt.yes?("Are you a human?") do |q| q.default false q.positive "Yup" q.negative "Nope" end puts "Answer: #{answer}" end |
#find_in_path(folder) ⇒ Object
146 147 148 149 150 151 152 |
# File 'lib/main2.rb', line 146 def find_in_path(folder) derived_paths = [] Find.find(folder) do |path| derived_paths << path if path =~ /.*\DerivedData$/ end puts derived_paths end |
#trash(file) ⇒ Object
154 155 156 157 158 |
# File 'lib/main2.rb', line 154 def trash(file) IO.popen("osascript", "w") do |stdin| stdin.puts %Q{tell app "Finder" to move the POSIX file "#{file}" to trash} end end |