Class: Kotoshu::Cli::StatusReport
- Inherits:
-
Object
- Object
- Kotoshu::Cli::StatusReport
- Defined in:
- lib/kotoshu/cli/status_report.rb
Overview
Pure data model describing what the ‘kotoshu status` command reports.
Knows nothing about presentation — the CLI command formats it as text or JSON. Construction is split from presentation so both outputs share one source of truth (MECE).
Defined Under Namespace
Classes: ResourceStatus
Instance Attribute Summary collapse
-
#audit_log_path ⇒ Object
readonly
Returns the value of attribute audit_log_path.
-
#audit_log_size_bytes ⇒ Object
readonly
Returns the value of attribute audit_log_size_bytes.
-
#cache_path ⇒ Object
readonly
Returns the value of attribute cache_path.
-
#cache_size_bytes ⇒ Object
readonly
Returns the value of attribute cache_size_bytes.
-
#default_language ⇒ Object
readonly
Returns the value of attribute default_language.
-
#languages_setup ⇒ Object
readonly
Returns the value of attribute languages_setup.
-
#offline ⇒ Object
readonly
Returns the value of attribute offline.
-
#onnx_loaded ⇒ Object
readonly
Returns the value of attribute onnx_loaded.
-
#resources ⇒ Object
readonly
Returns the value of attribute resources.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
-
.build(version:, resource_manager: Kotoshu::ResourceManager, paths: Kotoshu::Paths, configuration: Kotoshu.configuration, onnx_loaded: Kotoshu::Models::OnnxModel::ONNX_LOADED) ⇒ Object
Probe the live system and produce a report.
-
.directory_size(dir) ⇒ Object
Sum every regular file’s size under ‘dir`.
-
.format_bytes(bytes) ⇒ String
Human-readable byte format (KB / MB / GB).
Instance Method Summary collapse
-
#initialize(version:, languages_setup:, resources:, cache_path:, cache_size_bytes:, audit_log_path:, audit_log_size_bytes:, onnx_loaded:, default_language:, offline:) ⇒ StatusReport
constructor
A new instance of StatusReport.
- #languages_with_model ⇒ Object
Constructor Details
#initialize(version:, languages_setup:, resources:, cache_path:, cache_size_bytes:, audit_log_path:, audit_log_size_bytes:, onnx_loaded:, default_language:, offline:) ⇒ StatusReport
Returns a new instance of StatusReport.
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/kotoshu/cli/status_report.rb', line 17 def initialize(version:, languages_setup:, resources:, cache_path:, cache_size_bytes:, audit_log_path:, audit_log_size_bytes:, onnx_loaded:, default_language:, offline:) @version = version @languages_setup = languages_setup @resources = resources @cache_path = cache_path @cache_size_bytes = cache_size_bytes @audit_log_path = audit_log_path @audit_log_size_bytes = audit_log_size_bytes @onnx_loaded = onnx_loaded @default_language = default_language @offline = offline end |
Instance Attribute Details
#audit_log_path ⇒ Object (readonly)
Returns the value of attribute audit_log_path.
13 14 15 |
# File 'lib/kotoshu/cli/status_report.rb', line 13 def audit_log_path @audit_log_path end |
#audit_log_size_bytes ⇒ Object (readonly)
Returns the value of attribute audit_log_size_bytes.
13 14 15 |
# File 'lib/kotoshu/cli/status_report.rb', line 13 def audit_log_size_bytes @audit_log_size_bytes end |
#cache_path ⇒ Object (readonly)
Returns the value of attribute cache_path.
13 14 15 |
# File 'lib/kotoshu/cli/status_report.rb', line 13 def cache_path @cache_path end |
#cache_size_bytes ⇒ Object (readonly)
Returns the value of attribute cache_size_bytes.
13 14 15 |
# File 'lib/kotoshu/cli/status_report.rb', line 13 def cache_size_bytes @cache_size_bytes end |
#default_language ⇒ Object (readonly)
Returns the value of attribute default_language.
13 14 15 |
# File 'lib/kotoshu/cli/status_report.rb', line 13 def default_language @default_language end |
#languages_setup ⇒ Object (readonly)
Returns the value of attribute languages_setup.
13 14 15 |
# File 'lib/kotoshu/cli/status_report.rb', line 13 def languages_setup @languages_setup end |
#offline ⇒ Object (readonly)
Returns the value of attribute offline.
13 14 15 |
# File 'lib/kotoshu/cli/status_report.rb', line 13 def offline @offline end |
#onnx_loaded ⇒ Object (readonly)
Returns the value of attribute onnx_loaded.
13 14 15 |
# File 'lib/kotoshu/cli/status_report.rb', line 13 def onnx_loaded @onnx_loaded end |
#resources ⇒ Object (readonly)
Returns the value of attribute resources.
13 14 15 |
# File 'lib/kotoshu/cli/status_report.rb', line 13 def resources @resources end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
13 14 15 |
# File 'lib/kotoshu/cli/status_report.rb', line 13 def version @version end |
Class Method Details
.build(version:, resource_manager: Kotoshu::ResourceManager, paths: Kotoshu::Paths, configuration: Kotoshu.configuration, onnx_loaded: Kotoshu::Models::OnnxModel::ONNX_LOADED) ⇒ Object
Probe the live system and produce a report. Each collaborator is injectable for tests; defaults pull from the live configuration.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/kotoshu/cli/status_report.rb', line 37 def self.build(version:, resource_manager: Kotoshu::ResourceManager, paths: Kotoshu::Paths, configuration: Kotoshu.configuration, onnx_loaded: Kotoshu::Models::OnnxModel::ONNX_LOADED) langs = resource_manager.languages_setup cache_path = paths.cache_path cache_size = directory_size(cache_path) audit = audit_info(paths.audit_log_path) new( version: version, languages_setup: langs, resources: langs.flat_map { |lang| statuses_for(lang, resource_manager, cache_path) }, cache_path: cache_path, cache_size_bytes: cache_size, audit_log_path: audit[:path], audit_log_size_bytes: audit[:size], onnx_loaded: onnx_loaded, default_language: configuration.default_language, offline: configuration.offline ) end |
.directory_size(dir) ⇒ Object
Sum every regular file’s size under ‘dir`. Returns 0 if missing.
60 61 62 63 64 65 66 |
# File 'lib/kotoshu/cli/status_report.rb', line 60 def self.directory_size(dir) return 0 unless File.directory?(dir) Dir.glob(File.join(dir, "**", "*")) .select { |path| File.file?(path) } .sum { |path| File.size(path) } end |
.format_bytes(bytes) ⇒ String
Human-readable byte format (KB / MB / GB).
71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/kotoshu/cli/status_report.rb', line 71 def self.format_bytes(bytes) return "0 B" if bytes.nil? || bytes.zero? units = %w[B KB MB GB TB] size = bytes.to_f i = 0 while size >= 1024 && i < units.length - 1 size /= 1024 i += 1 end template = i.zero? ? "%.0f" : "%.1f" "#{template % size} #{units[i]}" end |
Instance Method Details
#languages_with_model ⇒ Object
31 32 33 |
# File 'lib/kotoshu/cli/status_report.rb', line 31 def languages_with_model resources.select { |r| r.resource == :model && r.available }.map(&:language).uniq.sort end |