Class: Zold::Clean
- Inherits:
-
Object
- Object
- Zold::Clean
- Defined in:
- lib/zold/commands/clean.rb
Overview
CLEAN command
Instance Method Summary collapse
- #clean(cps, opts) ⇒ Object
-
#initialize(wallets:, copies:, log: Loog::NULL) ⇒ Clean
constructor
A new instance of Clean.
- #run(args = []) ⇒ Object
Constructor Details
#initialize(wallets:, copies:, log: Loog::NULL) ⇒ Clean
Returns a new instance of Clean.
29 30 31 32 33 |
# File 'lib/zold/commands/clean.rb', line 29 def initialize(wallets:, copies:, log: Loog::NULL) @wallets = wallets @copies = copies @log = log end |
Instance Method Details
#clean(cps, opts) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/zold/commands/clean.rb', line 54 def clean(cps, opts) start = Time.now deleted = cps.clean(max: opts['max-age'] * 60 * 60) list = cps.all.map do |c| wallet = Wallet.new(c[:path]) "#{c[:name]}: #{c[:score]} #{c[:total]}n #{wallet.mnemo} \ #{Size.new(File.size(c[:path]))}/#{Age.new(File.mtime(c[:path]))}#{' master' if c[:master]}" end @log.debug( "#{deleted} expired local copies removed for #{cps} \ in #{Age.new(start, limit: 0.01)}, \ #{list.empty? ? 'nothing left' : "#{list.count} left:\n#{list.join("\n")}"}" ) end |
#run(args = []) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/zold/commands/clean.rb', line 35 def run(args = []) opts = Slop.parse(args, help: true, suppress_errors: true) do |o| o. = "Usage: zold clean [ID...] [options] Available options:" o.integer '--threads', 'How many threads to use for cleaning copies (default: 1)', default: 1 o.integer '--max-age', 'Maximum age for a copy to stay, in hours (default: 24)', default: 24 o.bool '--help', 'Print instructions' end mine = Args.new(opts, @log).take || return list = mine.empty? ? @wallets.all : mine.map { |i| Id.new(i) } Hands.exec(opts['threads'], list.uniq) do |id| clean(Copies.new(File.join(@copies, id), log: @log), opts) end end |