From 6301afec5256ab098253177846a04a814c167c5d Mon Sep 17 00:00:00 2001 From: Tristan Ancelet Date: Sun, 26 May 2024 12:21:07 -0500 Subject: [PATCH] Finished feature --- bucket-tool | 48 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/bucket-tool b/bucket-tool index bd26c65..4c5f8d7 100755 --- a/bucket-tool +++ b/bucket-tool @@ -11,7 +11,8 @@ require 'digest' # BEGIN: Helper Functions def usage - puts "#{__FILE__} [ACTION ] [] + puts <] [] Description: This utlity is meant to be used to interact with & manage the filebucket on P4 nodes due to the @@ -37,6 +38,19 @@ Global Flags: -d | --debug : Set debug flag -h | --help : This help message +Listing Filter Flags: + --from-date : Filter listings from starting after this point (FORMAT: YYYY-MM-DD HH:MM:SS) + : EX: + : 1. --from-date 2023-05-10 + : 2. --from-date "2023-05-10 13:23" + : + --to-date : Filter listings from ending at this point (FORMAT: YYYY-MM-DD HH:MM:SS) + : EX: + : 1. --to-date 2024-05-10 + : 2. --to-date "2024-05-10 05:27" + : + + Info Format Flags: -i | --inline : Set the info format to inline (MTIME : HASH : FILENAME) -l | --long : Set the info format to long @@ -51,7 +65,7 @@ Author: Email: tristan.ancelet@acumera.com Phone (Work) #: +1 (337) 965-1855 -" +EOT end def log (message, level = 0) @@ -194,10 +208,13 @@ $CONFIG[:search_term]="" $CONFIG[:log_file]="" $CONFIG[:alt_filepath]="" $CONFIG[:info_format]="inline" +$CONFIG[:from_time]=Time.at(0) # Beginning of epoch time +$CONFIG[:to_time]=Time.now # Today File.open('/etc/hostname') do |file| $HOSTNAME=file.read().strip() end FLAG_REGEX=/^\-+\S+/ +DATE_REGEX=/^(?[0-9]{4})-(?[0-9]{1,2})-(?[0-9]{1,2})[[:space:]]*((?[0-9]{1,2}):(?[0-9]{1,2}):(?[0-9]{1,2}))?$/ # END: Variables @@ -267,6 +284,23 @@ while i < ARGV.count usage exit end + when '--to-date', '--from-date' + if ARGV[i.next] != "" and ARGV[i.next] =~ DATE_REGEX + date_matches = DATE_REGEX.match(ARGV[i.next]).named_captures.each_value.select{|val| not val.nil?}.map(&:to_i) + case ARGV[i] + when '--to-date' + $CONFIG[:to_time]=Time.new(*date_matches) + log "$CONFIG[:to_time] was set to #{$CONFIG[:to_time]}}" + when '--from-date' + $CONFIG[:from_time]=Time.new(*date_matches) + log "$CONFIG[:from_time] was set to #{$CONFIG[:from_time]}}" + end + i+=2 + else + puts "Flag[#{ARGV[i]}] : Argument[#{ARGV[i.next]}] : Either the argument was not provided or it was a flag" + usage + exit + end else i+=1 @@ -377,8 +411,12 @@ class Bucket Dir["#{@bucketdir}/**/paths"].each.map{|path| File.dirname(path)}.each do |directory| log "\"#{directory}\" was grabbed from bucket directory. Making new BucketEntry" entry = BucketEntry.new(directory) - @entries[entry.hash]=entry - log "BucketEntry[#{entry.hash}] was added to @entries Size=#{@entries.count()}" + if entry.mtime <= $CONFIG[:to_time] and entry.mtime >= $CONFIG[:from_time] + @entries[entry.hash]=entry + log "BucketEntry[#{entry.hash}] was added to @entries Size=#{@entries.count()}" + else + log "Entry[#{entry.hash}] was filtered out by the user provided time constraints" + end end log "Bucket[#{@bucketdir}] was loaded" end @@ -538,7 +576,7 @@ def backup_file (bucket) log "Created preceeding directorys to hash directory" dir=$CONFIG[:bucket_dir] - hash.chars[0,8].map{|char| + hash.chars[0,8].each{|char| dir+="/#{char}" log "Checking to make sure that #{dir} doesn't exist" if not Dir.exist? dir