fontist 1.5.1 → 1.6.0
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 +14 -9
- data/lib/fontist/font.rb +17 -3
- data/lib/fontist/font_formula.rb +5 -2
- data/lib/fontist/utils/cache.rb +22 -6
- data/lib/fontist/utils/downloader.rb +54 -10
- data/lib/fontist/utils/exe_extractor.rb +2 -0
- data/lib/fontist/utils/ui.rb +4 -0
- data/lib/fontist/utils/zip_extractor.rb +1 -0
- 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: 2dc209840287f224caec09be365402ca43e3605debfed69d01f3f89f12d27093
|
4
|
+
data.tar.gz: 2ba6e5c3359cfa30afe30ecf96b4f11311e33c12dcce5053b7e37ea9c1750ce9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3e2a83f4c56ca2092954e9602827dcc6fe74ba4ba40d52f5e8ce6b0ca532cec67558fcf5a2e24775b13d263843ff2fab045f66838468a9d5fe0f087c3c08e23
|
7
|
+
data.tar.gz: 5d8968907e2955e7657044ad60c6c8c66ffc0f90d4e06f219b4bde01ad43f949b8dfc24a3477a6eebd269535d14dd26b7222c841c1f2b216f9e5a9111c9c931d
|
data/lib/fontist/cli.rb
CHANGED
@@ -13,13 +13,10 @@ module Fontist
|
|
13
13
|
option :force, type: :boolean, aliases: :f,
|
14
14
|
desc: "Install even if it's already installed in system"
|
15
15
|
def install(font)
|
16
|
-
|
17
|
-
Fontist.ui.success("These fonts are found or installed:")
|
18
|
-
Fontist.ui.success(fonts_paths.join("\n"))
|
16
|
+
Fontist::Font.install(font, force: options[:force])
|
19
17
|
STATUS_SUCCESS
|
20
18
|
rescue Fontist::Errors::NonSupportedFontError
|
21
|
-
|
22
|
-
STATUS_ERROR
|
19
|
+
could_not_find_font(font)
|
23
20
|
end
|
24
21
|
|
25
22
|
desc "uninstall/remove FONT", "Uninstall font by font or formula"
|
@@ -32,8 +29,7 @@ module Fontist
|
|
32
29
|
Fontist.ui.error(e.message)
|
33
30
|
STATUS_ERROR
|
34
31
|
rescue Fontist::Errors::NonSupportedFontError
|
35
|
-
|
36
|
-
STATUS_ERROR
|
32
|
+
could_not_find_font(font)
|
37
33
|
end
|
38
34
|
map remove: :uninstall
|
39
35
|
|
@@ -47,7 +43,7 @@ module Fontist
|
|
47
43
|
rescue Fontist::Errors::MissingFontError => e
|
48
44
|
error(e.message)
|
49
45
|
rescue Fontist::Errors::NonSupportedFontError
|
50
|
-
|
46
|
+
could_not_find_font(font)
|
51
47
|
end
|
52
48
|
|
53
49
|
desc "list [FONT]", "List installation status of FONT or fonts in fontist"
|
@@ -56,7 +52,7 @@ module Fontist
|
|
56
52
|
print_list(formulas)
|
57
53
|
success
|
58
54
|
rescue Fontist::Errors::NonSupportedFontError
|
59
|
-
|
55
|
+
could_not_find_font(font)
|
60
56
|
end
|
61
57
|
|
62
58
|
desc "update", "Update formulas"
|
@@ -111,6 +107,15 @@ module Fontist
|
|
111
107
|
STATUS_SUCCESS
|
112
108
|
end
|
113
109
|
|
110
|
+
def could_not_find_font(font)
|
111
|
+
error("Font '#{font}' not found locally nor available in the Fontist " \
|
112
|
+
"formula repository.\n" \
|
113
|
+
"Perhaps it is available at the latest Fontist formula " \
|
114
|
+
"repository.\n" \
|
115
|
+
"You can update the formula repository using the command " \
|
116
|
+
"`fontist update` and try again.")
|
117
|
+
end
|
118
|
+
|
114
119
|
def error(message)
|
115
120
|
Fontist.ui.error(message)
|
116
121
|
STATUS_ERROR
|
data/lib/fontist/font.rb
CHANGED
@@ -81,7 +81,16 @@ module Fontist
|
|
81
81
|
attr_reader :name, :confirmation
|
82
82
|
|
83
83
|
def find_system_font
|
84
|
-
Fontist::SystemFont.find(name)
|
84
|
+
paths = Fontist::SystemFont.find(name)
|
85
|
+
unless paths
|
86
|
+
Fontist.ui.say(%(Font "#{name}" not found locally.))
|
87
|
+
return
|
88
|
+
end
|
89
|
+
|
90
|
+
Fontist.ui.say("Fonts found at:")
|
91
|
+
paths.each do |path|
|
92
|
+
Fontist.ui.say("- #{path}")
|
93
|
+
end
|
85
94
|
end
|
86
95
|
|
87
96
|
def check_or_create_fontist_path!
|
@@ -113,7 +122,13 @@ module Fontist
|
|
113
122
|
def download_font
|
114
123
|
if formula
|
115
124
|
check_and_confirm_required_license(formula)
|
116
|
-
font_installer(formula).fetch_font(name,
|
125
|
+
paths = font_installer(formula).fetch_font(name,
|
126
|
+
confirmation: confirmation)
|
127
|
+
|
128
|
+
Fontist.ui.say("Fonts installed at:")
|
129
|
+
paths.each do |path|
|
130
|
+
Fontist.ui.say("- #{path}")
|
131
|
+
end
|
117
132
|
end
|
118
133
|
end
|
119
134
|
|
@@ -232,6 +247,5 @@ module Fontist
|
|
232
247
|
def installed(style)
|
233
248
|
path(style) ? true : false
|
234
249
|
end
|
235
|
-
|
236
250
|
end
|
237
251
|
end
|
data/lib/fontist/font_formula.rb
CHANGED
@@ -109,8 +109,11 @@ module Fontist
|
|
109
109
|
end
|
110
110
|
|
111
111
|
def download_file(source)
|
112
|
+
url = source[:urls].first
|
113
|
+
Fontist.ui.say(%(Downloading font "#{key}" from #{url}))
|
114
|
+
|
112
115
|
downloaded_file = Fontist::Utils::Downloader.download(
|
113
|
-
|
116
|
+
url,
|
114
117
|
sha: source[:sha256],
|
115
118
|
file_size: source[:file_size],
|
116
119
|
progress_bar: is_progress_bar_enabled
|
@@ -121,7 +124,7 @@ module Fontist
|
|
121
124
|
end
|
122
125
|
|
123
126
|
def is_progress_bar_enabled
|
124
|
-
options.nil? ?
|
127
|
+
options.nil? ? true : options.fetch(:progress_bar, true)
|
125
128
|
end
|
126
129
|
end
|
127
130
|
end
|
data/lib/fontist/utils/cache.rb
CHANGED
@@ -1,14 +1,18 @@
|
|
1
1
|
module Fontist
|
2
2
|
module Utils
|
3
3
|
class Cache
|
4
|
-
def fetch(key)
|
4
|
+
def fetch(key, bar: nil)
|
5
5
|
map = load_cache
|
6
|
-
|
6
|
+
if cache_exist?(map[key])
|
7
|
+
print_bar(bar, map[key]) if bar
|
8
|
+
|
9
|
+
return downloaded_file(map[key])
|
10
|
+
end
|
7
11
|
|
8
12
|
generated_file = yield
|
9
13
|
path = save_cache(generated_file, key)
|
10
14
|
|
11
|
-
|
15
|
+
downloaded_file(path)
|
12
16
|
end
|
13
17
|
|
14
18
|
private
|
@@ -21,12 +25,24 @@ module Fontist
|
|
21
25
|
cache_map_path.exist? ? YAML.load_file(cache_map_path) : {}
|
22
26
|
end
|
23
27
|
|
24
|
-
def
|
25
|
-
File.new(
|
28
|
+
def downloaded_file(path)
|
29
|
+
File.new(downloaded_path(path))
|
26
30
|
end
|
27
31
|
|
28
32
|
def cache_exist?(path)
|
29
|
-
path && File.exist?(
|
33
|
+
path && File.exist?(downloaded_path(path))
|
34
|
+
end
|
35
|
+
|
36
|
+
def downloaded_path(path)
|
37
|
+
Fontist.downloads_path.join(path)
|
38
|
+
end
|
39
|
+
|
40
|
+
def print_bar(bar, path)
|
41
|
+
File.size(downloaded_path(path)).tap do |size|
|
42
|
+
bar.total = size
|
43
|
+
bar.increment(size)
|
44
|
+
bar.finish("cache")
|
45
|
+
end
|
30
46
|
end
|
31
47
|
|
32
48
|
def save_cache(generated_file, key)
|
@@ -7,13 +7,15 @@ module Fontist
|
|
7
7
|
# TODO: If the first mirror fails, try the second one
|
8
8
|
@file = file
|
9
9
|
@sha = [sha].flatten.compact
|
10
|
-
@progress_bar = set_progress_bar(progress_bar)
|
11
10
|
@file_size = (file_size || default_file_size).to_i
|
11
|
+
@progress_bar = set_progress_bar(progress_bar)
|
12
12
|
@cache = Cache.new
|
13
13
|
end
|
14
14
|
|
15
15
|
def download
|
16
|
-
file = @cache.fetch(@file
|
16
|
+
file = @cache.fetch(@file, bar: @progress_bar) do
|
17
|
+
download_file
|
18
|
+
end
|
17
19
|
|
18
20
|
if !sha.empty? && !sha.include?(Digest::SHA256.file(file).to_s)
|
19
21
|
raise(Fontist::Errors::TamperedFileError.new(
|
@@ -46,25 +48,27 @@ module Fontist
|
|
46
48
|
end
|
47
49
|
|
48
50
|
def set_progress_bar(progress_bar)
|
49
|
-
ENV.fetch("TEST_ENV", "") === "CI"
|
51
|
+
if ENV.fetch("TEST_ENV", "") === "CI" || progress_bar
|
52
|
+
ProgressBar.new(@file_size)
|
53
|
+
else
|
54
|
+
NullProgressBar.new
|
55
|
+
end
|
50
56
|
end
|
51
57
|
|
52
58
|
def download_file
|
53
|
-
bar = ProgressBar.new(file_size / byte_to_megabyte)
|
54
|
-
|
55
59
|
file = Down.download(
|
56
60
|
@file,
|
57
61
|
open_timeout: 10,
|
58
62
|
read_timeout: 10,
|
59
63
|
content_length_proc: ->(content_length) {
|
60
|
-
|
64
|
+
@progress_bar.total = content_length if content_length
|
61
65
|
},
|
62
66
|
progress_proc: -> (progress) {
|
63
|
-
|
67
|
+
@progress_bar.increment(progress)
|
64
68
|
}
|
65
69
|
)
|
66
70
|
|
67
|
-
|
71
|
+
@progress_bar.finish
|
68
72
|
|
69
73
|
file
|
70
74
|
rescue Down::NotFound
|
@@ -72,6 +76,20 @@ module Fontist
|
|
72
76
|
end
|
73
77
|
end
|
74
78
|
|
79
|
+
class NullProgressBar
|
80
|
+
def total=(_)
|
81
|
+
# do nothing
|
82
|
+
end
|
83
|
+
|
84
|
+
def increment(_)
|
85
|
+
# do nothing
|
86
|
+
end
|
87
|
+
|
88
|
+
def finish(_ = nil)
|
89
|
+
# do nothing
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
75
93
|
class ProgressBar
|
76
94
|
def initialize(total)
|
77
95
|
@counter = 1
|
@@ -83,9 +101,35 @@ module Fontist
|
|
83
101
|
end
|
84
102
|
|
85
103
|
def increment(progress)
|
86
|
-
complete = sprintf("%#.2f%%", ((@counter.to_f / @total.to_f) * 100))
|
87
|
-
print "\r\e[0KDownloads: #{@counter}MB/#{@total}MB (#{complete})"
|
88
104
|
@counter = progress
|
105
|
+
Fontist.ui.print "\r\e[0KDownloads: #{counter_mb}MB/#{total_mb}MB " \
|
106
|
+
"(#{completeness})"
|
107
|
+
end
|
108
|
+
|
109
|
+
def finish(message = nil)
|
110
|
+
if message
|
111
|
+
Fontist.ui.print " (#{message})\n"
|
112
|
+
else
|
113
|
+
Fontist.ui.print "\n"
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
private
|
118
|
+
|
119
|
+
def completeness
|
120
|
+
sprintf("%#.2f%%", (@counter.fdiv(@total) * 100)) # rubocop:disable Style/FormatStringToken, Metrics/LineLength
|
121
|
+
end
|
122
|
+
|
123
|
+
def counter_mb
|
124
|
+
@counter / byte_to_megabyte
|
125
|
+
end
|
126
|
+
|
127
|
+
def total_mb
|
128
|
+
@total / byte_to_megabyte
|
129
|
+
end
|
130
|
+
|
131
|
+
def byte_to_megabyte
|
132
|
+
@byte_to_megabyte ||= 1024 * 1024
|
89
133
|
end
|
90
134
|
end
|
91
135
|
end
|
@@ -5,6 +5,8 @@ module Fontist
|
|
5
5
|
download = @downloaded === true ? false : download
|
6
6
|
|
7
7
|
exe_file = download_file(exe_file).path if download
|
8
|
+
|
9
|
+
Fontist.ui.say(%(Installing font "#{key}".))
|
8
10
|
cab_file = decompressor.search(exe_file)
|
9
11
|
cabbed_fonts = grep_fonts(cab_file.files, font_ext) || []
|
10
12
|
fonts_paths = extract_cabbed_fonts_to_assets(cabbed_fonts)
|
data/lib/fontist/utils/ui.rb
CHANGED
data/lib/fontist/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fontist
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2020-11-
|
12
|
+
date: 2020-11-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: down
|