fontist 1.8.9 → 1.8.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/fontist/cli.rb +3 -1
- data/lib/fontist/font.rb +2 -1
- data/lib/fontist/font_installer.rb +3 -2
- data/lib/fontist/import/helpers/system_helper.rb +1 -3
- data/lib/fontist/manifest/install.rb +10 -3
- data/lib/fontist/utils/cache.rb +27 -8
- data/lib/fontist/utils/downloader.rb +74 -32
- data/lib/fontist/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a61fbcb4c7c4242df9816a14e4b38ef2a0653f2979d60351ff46e2afd534287
|
4
|
+
data.tar.gz: 117b390025eb49b700213b9964aa7134c39d9945b1aed822e7b92e36295b750f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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:
|
64
|
+
progress_bar: !@no_progress
|
64
65
|
)
|
65
66
|
end
|
66
67
|
|
@@ -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
|
-
|
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(
|
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
|
data/lib/fontist/utils/cache.rb
CHANGED
@@ -3,10 +3,10 @@ module Fontist
|
|
3
3
|
class Cache
|
4
4
|
include Locking
|
5
5
|
|
6
|
-
def fetch(key
|
6
|
+
def fetch(key)
|
7
7
|
map = load_cache
|
8
8
|
if cache_exist?(map[key])
|
9
|
-
|
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
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
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 =
|
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
|
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
|
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 =
|
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
|
-
|
109
|
-
|
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
|
-
|
113
|
-
|
114
|
-
|
103
|
+
private
|
104
|
+
|
105
|
+
def print_incrementally
|
106
|
+
if total?
|
107
|
+
print_percent_incrementally
|
115
108
|
else
|
116
|
-
|
109
|
+
print_size_incrementally
|
117
110
|
end
|
118
111
|
end
|
119
112
|
|
120
|
-
|
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
|
123
|
-
|
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
|
data/lib/fontist/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2021-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: down
|