fontist 1.8.9 → 1.8.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0c34f4a52f1c0842347ebd17811c7550b4eb9e31048bab00077cea20dcd94985
4
- data.tar.gz: 9a5bad3ff72333d3b73673189510f0b739ef1160233235212e6b0c21f5152d2c
3
+ metadata.gz: 5a61fbcb4c7c4242df9816a14e4b38ef2a0653f2979d60351ff46e2afd534287
4
+ data.tar.gz: 117b390025eb49b700213b9964aa7134c39d9945b1aed822e7b92e36295b750f
5
5
  SHA512:
6
- metadata.gz: d8d58465500cd8417d3c164cb791215d6adcfeee358ac60b14d93492d5c6ef1b465cb26236e44ced38566995d61e741ffe1566ad482c491d474ccea9c10fa447
7
- data.tar.gz: f41298a94ffe8d6c2d6f33ff990f9e3c03b6271d580db2a86f48d94bc7dd4776a7c767f7d0d946097782ec00335c716053c90bd88aec4ba3dc274a6e863555bb
6
+ metadata.gz: c77e83a9a67f3782bbf4eb8c3d3de30ebb0db904c6429e6d83bc457e9651125acee7528b5503ab51fac3dfc6a4441e966cc8596aa70455dc1181f2c866f0cdae
7
+ data.tar.gz: 1b542a3e06a395198277e5ac34d7615fa25f95bd7da1a3fcbd6e819a572871b3d0ca4ad51678859eeae180c0b76b586d6c815b1807ac82b3f79e703eef5bffde
data/lib/fontist/cli.rb CHANGED
@@ -31,12 +31,14 @@ module Fontist
31
31
  desc: "Install even if it's already installed in system"
32
32
  option :accept_all_licenses, type: :boolean, aliases: "--confirm-license", desc: "Accept all license agreements"
33
33
  option :hide_licenses, type: :boolean, desc: "Hide license texts"
34
+ option :no_progress, type: :boolean, desc: "Hide download progress"
34
35
  def install(font)
35
36
  Fontist::Font.install(
36
37
  font,
37
38
  force: options[:force],
38
39
  confirmation: options[:accept_all_licenses] ? "yes" : "no",
39
- hide_licenses: options[:hide_licenses]
40
+ hide_licenses: options[:hide_licenses],
41
+ no_progress: options[:no_progress]
40
42
  )
41
43
  success
42
44
  rescue Fontist::Errors::GeneralError => e
data/lib/fontist/font.rb CHANGED
@@ -7,6 +7,7 @@ module Fontist
7
7
  @name = options[:name]
8
8
  @confirmation = options[:confirmation] || "no"
9
9
  @hide_licenses = options[:hide_licenses]
10
+ @no_progress = options[:no_progress] || false
10
11
  @force = options[:force] || false
11
12
 
12
13
  check_or_create_fontist_path!
@@ -94,7 +95,7 @@ module Fontist
94
95
  end
95
96
 
96
97
  def font_installer(formula)
97
- FontInstaller.new(formula)
98
+ FontInstaller.new(formula, no_progress: @no_progress)
98
99
  end
99
100
 
100
101
  def formula
@@ -3,8 +3,9 @@ require "excavate"
3
3
 
4
4
  module Fontist
5
5
  class FontInstaller
6
- def initialize(formula)
6
+ def initialize(formula, no_progress: false)
7
7
  @formula = formula
8
+ @no_progress = no_progress
8
9
  end
9
10
 
10
11
  def install(confirmation:)
@@ -60,7 +61,7 @@ module Fontist
60
61
  url,
61
62
  sha: source.sha256,
62
63
  file_size: source.file_size,
63
- progress_bar: true
64
+ progress_bar: !@no_progress
64
65
  )
65
66
  end
66
67
 
@@ -4,9 +4,7 @@ module Fontist
4
4
  module SystemHelper
5
5
  class << self
6
6
  def run(command)
7
- unless ENV.fetch("TEST_ENV", "") === "CI"
8
- Fontist.ui.say("Run `#{command}`")
9
- end
7
+ Fontist.ui.say("Run `#{command}`")
10
8
 
11
9
  result = `#{command}`
12
10
  unless $CHILD_STATUS.to_i.zero?
@@ -3,10 +3,11 @@ require_relative "locations"
3
3
  module Fontist
4
4
  module Manifest
5
5
  class Install < Locations
6
- def initialize(manifest, confirmation: "no", hide_licenses: false)
7
- @manifest = manifest
6
+ def initialize(manifest, confirmation: "no", hide_licenses: false, no_progress: false)
7
+ super(manifest)
8
8
  @confirmation = confirmation
9
9
  @hide_licenses = hide_licenses
10
+ @no_progress = no_progress
10
11
  end
11
12
 
12
13
  private
@@ -21,7 +22,13 @@ module Fontist
21
22
  end
22
23
 
23
24
  def install_font(font)
24
- Fontist::Font.install(font, force: true, confirmation: @confirmation, hide_licenses: @hide_licenses)
25
+ Fontist::Font.install(
26
+ font,
27
+ force: true,
28
+ confirmation: @confirmation,
29
+ hide_licenses: @hide_licenses,
30
+ no_progress: @no_progress
31
+ )
25
32
  end
26
33
  end
27
34
  end
@@ -3,10 +3,10 @@ module Fontist
3
3
  class Cache
4
4
  include Locking
5
5
 
6
- def fetch(key, bar: nil)
6
+ def fetch(key)
7
7
  map = load_cache
8
8
  if cache_exist?(map[key])
9
- print_bar(bar, map[key]) if bar
9
+ print(map[key])
10
10
 
11
11
  return downloaded_file(map[key])
12
12
  end
@@ -17,6 +17,25 @@ module Fontist
17
17
  downloaded_file(path)
18
18
  end
19
19
 
20
+ def delete(key)
21
+ lock(lock_path) do
22
+ map = load_cache
23
+ return unless map[key]
24
+
25
+ value = map.delete(key)
26
+ File.write(cache_map_path, YAML.dump(map))
27
+ value
28
+ end
29
+ end
30
+
31
+ def set(key, value)
32
+ lock(lock_path) do
33
+ map = load_cache
34
+ map[key] = value
35
+ File.write(cache_map_path, YAML.dump(map))
36
+ end
37
+ end
38
+
20
39
  private
21
40
 
22
41
  def cache_map_path
@@ -39,12 +58,12 @@ module Fontist
39
58
  Fontist.downloads_path.join(path)
40
59
  end
41
60
 
42
- def print_bar(bar, path)
43
- File.size(downloaded_path(path)).tap do |size|
44
- bar.total = size
45
- bar.increment(size)
46
- bar.finish("cache")
47
- end
61
+ def print(path)
62
+ Fontist.ui.say("Fetched from cache: #{size(path)} MiB.")
63
+ end
64
+
65
+ def size(path)
66
+ File.size(downloaded_path(path)) / (1024 * 1024)
48
67
  end
49
68
 
50
69
  def save_cache(generated_file, key)
@@ -14,13 +14,13 @@ module Fontist
14
14
  # TODO: If the first mirror fails, try the second one
15
15
  @file = file
16
16
  @sha = [sha].flatten.compact
17
- @file_size = (file_size || default_file_size).to_i
17
+ @file_size = file_size.to_i if file_size
18
18
  @progress_bar = set_progress_bar(progress_bar)
19
19
  @cache = Cache.new
20
20
  end
21
21
 
22
22
  def download
23
- file = @cache.fetch(@file, bar: @progress_bar) do
23
+ file = @cache.fetch(@file) do
24
24
  download_file
25
25
  end
26
26
 
@@ -38,10 +38,6 @@ module Fontist
38
38
 
39
39
  attr_reader :file, :sha, :file_size
40
40
 
41
- def default_file_size
42
- 5 * byte_to_megabyte
43
- end
44
-
45
41
  def byte_to_megabyte
46
42
  @byte_to_megabyte ||= 1024 * 1024
47
43
  end
@@ -51,10 +47,10 @@ module Fontist
51
47
  end
52
48
 
53
49
  def set_progress_bar(progress_bar)
54
- if ENV.fetch("TEST_ENV", "") === "CI" || progress_bar
50
+ if progress_bar
55
51
  ProgressBar.new(@file_size)
56
52
  else
57
- NullProgressBar.new
53
+ NullProgressBar.new(@file_size)
58
54
  end
59
55
  end
60
56
 
@@ -79,24 +75,13 @@ module Fontist
79
75
  end
80
76
  end
81
77
 
82
- class NullProgressBar
83
- def total=(_)
84
- # do nothing
85
- end
86
-
87
- def increment(_)
88
- # do nothing
89
- end
90
-
91
- def finish(_ = nil)
92
- # do nothing
93
- end
94
- end
95
-
96
78
  class ProgressBar
97
79
  def initialize(total)
98
- @counter = 1
80
+ @counter = 0
99
81
  @total = total
82
+ @printed_percent = -1
83
+ @printed_size = -1
84
+ @start = Time.now
100
85
  end
101
86
 
102
87
  def total=(total)
@@ -105,22 +90,57 @@ module Fontist
105
90
 
106
91
  def increment(progress)
107
92
  @counter = progress
108
- Fontist.ui.print "\r\e[0KDownloads: #{counter_mb}MB/#{total_mb}MB " \
109
- "(#{completeness})"
93
+
94
+ print_incrementally
95
+ end
96
+
97
+ def finish
98
+ print
99
+
100
+ Fontist.ui.print(format(", %<mb_per_second>.2f MiB/s, done.\n", mb_per_second: mb_per_second))
110
101
  end
111
102
 
112
- def finish(message = nil)
113
- if message
114
- Fontist.ui.print " (#{message})\n"
103
+ private
104
+
105
+ def print_incrementally
106
+ if total?
107
+ print_percent_incrementally
115
108
  else
116
- Fontist.ui.print "\n"
109
+ print_size_incrementally
117
110
  end
118
111
  end
119
112
 
120
- private
113
+ def print
114
+ if total?
115
+ print_percent
116
+ else
117
+ print_size
118
+ end
119
+ end
120
+
121
+ def total?
122
+ !!@total
123
+ end
121
124
 
122
- def completeness
123
- sprintf("%#.2f%%", (@counter.fdiv(@total) * 100)) # rubocop:disable Style/FormatStringToken, Metrics/LineLength
125
+ def print_percent_incrementally
126
+ return unless percent > @printed_percent
127
+
128
+ print_percent
129
+
130
+ @printed_percent = percent
131
+ end
132
+
133
+ def print_percent
134
+ # rubocop:disable Style/FormatStringToken
135
+ Fontist.ui.print(format("\r\e[0KDownloading: %<completeness>3d%% (%<counter_mb>d/%<total_mb>d MiB)",
136
+ completeness: percent,
137
+ counter_mb: counter_mb,
138
+ total_mb: total_mb))
139
+ # rubocop:enable Style/FormatStringToken
140
+ end
141
+
142
+ def percent
143
+ (@counter.fdiv(@total) * 100).to_i
124
144
  end
125
145
 
126
146
  def counter_mb
@@ -134,6 +154,28 @@ module Fontist
134
154
  def byte_to_megabyte
135
155
  @byte_to_megabyte ||= 1024 * 1024
136
156
  end
157
+
158
+ def print_size_incrementally
159
+ return unless counter_mb > @printed_size
160
+
161
+ print_size
162
+
163
+ @printed_size = counter_mb
164
+ end
165
+
166
+ def print_size
167
+ Fontist.ui.print(format("\r\e[0KDownloading: %<downloaded>4d MiB", downloaded: counter_mb))
168
+ end
169
+
170
+ def mb_per_second
171
+ @counter / (Time.now - @start) / byte_to_megabyte
172
+ end
173
+ end
174
+
175
+ class NullProgressBar < ProgressBar
176
+ def print_incrementally
177
+ # do nothing
178
+ end
137
179
  end
138
180
  end
139
181
  end
@@ -1,3 +1,3 @@
1
1
  module Fontist
2
- VERSION = "1.8.9".freeze
2
+ VERSION = "1.8.10".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fontist
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.9
4
+ version: 1.8.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-10 00:00:00.000000000 Z
11
+ date: 2021-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: down