Finished feature
This commit is contained in:
parent
5232f2bebb
commit
6301afec52
48
bucket-tool
48
bucket-tool
@ -11,7 +11,8 @@ require 'digest'
|
|||||||
# BEGIN: Helper Functions
|
# BEGIN: Helper Functions
|
||||||
|
|
||||||
def usage
|
def usage
|
||||||
puts "#{__FILE__} [ACTION <arg>] [<flags>]
|
puts <<EOT
|
||||||
|
#{__FILE__} [ACTION <arg>] [<flags>]
|
||||||
|
|
||||||
Description:
|
Description:
|
||||||
This utlity is meant to be used to interact with & manage the filebucket on P4 nodes due to the
|
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
|
-d | --debug : Set debug flag
|
||||||
-h | --help : This help message
|
-h | --help : This help message
|
||||||
|
|
||||||
|
Listing Filter Flags:
|
||||||
|
--from-date <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 <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:
|
Info Format Flags:
|
||||||
-i | --inline : Set the info format to inline (MTIME : HASH : FILENAME)
|
-i | --inline : Set the info format to inline (MTIME : HASH : FILENAME)
|
||||||
-l | --long : Set the info format to long
|
-l | --long : Set the info format to long
|
||||||
@ -51,7 +65,7 @@ Author:
|
|||||||
Email: tristan.ancelet@acumera.com
|
Email: tristan.ancelet@acumera.com
|
||||||
Phone (Work) #: +1 (337) 965-1855
|
Phone (Work) #: +1 (337) 965-1855
|
||||||
|
|
||||||
"
|
EOT
|
||||||
end
|
end
|
||||||
|
|
||||||
def log (message, level = 0)
|
def log (message, level = 0)
|
||||||
@ -194,10 +208,13 @@ $CONFIG[:search_term]=""
|
|||||||
$CONFIG[:log_file]=""
|
$CONFIG[:log_file]=""
|
||||||
$CONFIG[:alt_filepath]=""
|
$CONFIG[:alt_filepath]=""
|
||||||
$CONFIG[:info_format]="inline"
|
$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|
|
File.open('/etc/hostname') do |file|
|
||||||
$HOSTNAME=file.read().strip()
|
$HOSTNAME=file.read().strip()
|
||||||
end
|
end
|
||||||
FLAG_REGEX=/^\-+\S+/
|
FLAG_REGEX=/^\-+\S+/
|
||||||
|
DATE_REGEX=/^(?<year>[0-9]{4})-(?<month>[0-9]{1,2})-(?<day>[0-9]{1,2})[[:space:]]*((?<hour>[0-9]{1,2}):(?<minute>[0-9]{1,2}):(?<second>[0-9]{1,2}))?$/
|
||||||
|
|
||||||
# END: Variables
|
# END: Variables
|
||||||
|
|
||||||
@ -267,6 +284,23 @@ while i < ARGV.count
|
|||||||
usage
|
usage
|
||||||
exit
|
exit
|
||||||
end
|
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
|
else
|
||||||
i+=1
|
i+=1
|
||||||
@ -377,8 +411,12 @@ class Bucket
|
|||||||
Dir["#{@bucketdir}/**/paths"].each.map{|path| File.dirname(path)}.each do |directory|
|
Dir["#{@bucketdir}/**/paths"].each.map{|path| File.dirname(path)}.each do |directory|
|
||||||
log "\"#{directory}\" was grabbed from bucket directory. Making new BucketEntry"
|
log "\"#{directory}\" was grabbed from bucket directory. Making new BucketEntry"
|
||||||
entry = BucketEntry.new(directory)
|
entry = BucketEntry.new(directory)
|
||||||
@entries[entry.hash]=entry
|
if entry.mtime <= $CONFIG[:to_time] and entry.mtime >= $CONFIG[:from_time]
|
||||||
log "BucketEntry[#{entry.hash}] was added to @entries Size=#{@entries.count()}"
|
@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
|
end
|
||||||
log "Bucket[#{@bucketdir}] was loaded"
|
log "Bucket[#{@bucketdir}] was loaded"
|
||||||
end
|
end
|
||||||
@ -538,7 +576,7 @@ def backup_file (bucket)
|
|||||||
|
|
||||||
log "Created preceeding directorys to hash directory"
|
log "Created preceeding directorys to hash directory"
|
||||||
dir=$CONFIG[:bucket_dir]
|
dir=$CONFIG[:bucket_dir]
|
||||||
hash.chars[0,8].map{|char|
|
hash.chars[0,8].each{|char|
|
||||||
dir+="/#{char}"
|
dir+="/#{char}"
|
||||||
log "Checking to make sure that #{dir} doesn't exist"
|
log "Checking to make sure that #{dir} doesn't exist"
|
||||||
if not Dir.exist? dir
|
if not Dir.exist? dir
|
||||||
|
Loading…
Reference in New Issue
Block a user