Sha256: 0006b419b16f6791138b5439bc46fa36ab3f6450960c36cb97262e85d625fa2b
Contents?: true
Size: 1.33 KB
Versions: 2
Compression:
Stored size: 1.33 KB
Contents
$:<< File.expand_path(File.dirname(__FILE__)) require "checksummer_file" class Checksummer attr_accessor :checksum_to, :paths def initialize(checksum_to) self.checksum_to = File.expand_path(checksum_to) end def checksum_directory(directory) files = find(directory) total = files.length files.each_with_index do |file, i| status = file.checksum_to!(checksum_to) yield(status, file, i, total) if block_given? end end def find(directory) Kernel.send(:`, %(find #{directory} -type f -printf "%T+\t%s\t%Y\t%p\t%l\n")).split("\n").map do |line| ChecksummerFile.from_line(line) end end def self.run_for_args(args) directory, checksum_to = args sleep = args.index("--sleep") ? args[args.index("--sleep") + 1].to_i / 1000.0 : 0.1 if !directory || !File.directory?(directory) || !checksum_to || !File.directory?(checksum_to) puts usage else self.new(checksum_to).checksum_directory(directory) do |status, file, index, total| puts "%s\t%0#{total.to_s.length}d/%d\t%s\t%s" % [Time.now.strftime("%Y-%m-%d %H:%M:%S"), index, total, status, file.path] $stdout.flush sleep sleep if !Range.new(0,7).include?(Time.now.hour) end end end def self.usage "checksummer <directory_to_checksum> <directory_to_store_checksummed_files>" end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
checksummer-0.1.4 | lib/checksummer.rb |
checksummer-0.1.2 | lib/checksummer.rb |