Module: Hadupils::Helpers::Dfs
- Included in:
- Commands::Cleanup
- Defined in:
- lib/hadupils/helpers.rb
Instance Method Summary collapse
- #all_expired?(parsed_ls, ttl) ⇒ Boolean
- #dir_candidates(parsed_ls, ttl) ⇒ Object
- #dir_empty?(count) ⇒ Boolean
- #hadupils_tmpfile?(parsed_line) ⇒ Boolean
- #hadupils_tmpfiles(parsed_ls) ⇒ Object
- #parse_count(stdout) ⇒ Object
- #parse_ls(stdout) ⇒ Object
Instance Method Details
#all_expired?(parsed_ls, ttl) ⇒ Boolean
67 68 69 |
# File 'lib/hadupils/helpers.rb', line 67 def all_expired?(parsed_ls, ttl) parsed_ls.all? {|file_time, file_path| file_time < (Time.now.utc - ttl)} end |
#dir_candidates(parsed_ls, ttl) ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/hadupils/helpers.rb', line 54 def dir_candidates(parsed_ls, ttl) parsed_ls.inject([]) do |dir_candidates, (file_time, file_path)| if file_time < (Time.now.utc - ttl) dir_candidates << file_path end dir_candidates end end |
#dir_empty?(count) ⇒ Boolean
63 64 65 |
# File 'lib/hadupils/helpers.rb', line 63 def dir_empty?(count) count.to_i == 0 end |
#hadupils_tmpfile?(parsed_line) ⇒ Boolean
50 51 52 |
# File 'lib/hadupils/helpers.rb', line 50 def hadupils_tmpfile?(parsed_line) parsed_line.match(/hadupils-tmp/) end |
#hadupils_tmpfiles(parsed_ls) ⇒ Object
71 72 73 74 75 76 77 78 79 |
# File 'lib/hadupils/helpers.rb', line 71 def hadupils_tmpfiles(parsed_ls) parsed_ls.map do |time, file_path| if hadupils_tmpfile? file_path [time, file_path] else nil end end.compact end |
#parse_count(stdout) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/hadupils/helpers.rb', line 17 def parse_count(stdout) parsed_count = {} if stdout result = stdout.squeeze(' ').split parsed_count = begin { :dir_count => result[0], :file_count => result[1], :content_size => result[2], :file_name => result[3] } end if result.length == 4 # Check for proper # of dfs -count columns end parsed_count end |
#parse_ls(stdout) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/hadupils/helpers.rb', line 32 def parse_ls(stdout) parsed_ls = [] if stdout result = stdout.split(/\n/) parsed_ls = result[1..-1].map do |line| l = line.squeeze(' ').split begin l = l[-3..-1] [Time.parse("#{l[0]} #{l[1]}Z"), l[2]] rescue ArgumentError nil end if l.length == 8 # Check for proper # of dfs -ls columns end.compact unless result.empty? end parsed_ls end |