fontist 1.8.7 → 1.8.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rspec.yml +1 -10
  3. data/.rubocop.yml +3 -3
  4. data/README.md +3 -3
  5. data/fontist.gemspec +2 -6
  6. data/lib/fontist/cli.rb +3 -1
  7. data/lib/fontist/font.rb +2 -1
  8. data/lib/fontist/font_installer.rb +40 -39
  9. data/lib/fontist/formula_paths.rb +1 -0
  10. data/lib/fontist/import/helpers/system_helper.rb +1 -3
  11. data/lib/fontist/import/recursive_extraction.rb +25 -119
  12. data/lib/fontist/manifest/install.rb +11 -4
  13. data/lib/fontist/manifest/locations.rb +20 -6
  14. data/lib/fontist/system_font.rb +4 -12
  15. data/lib/fontist/utils.rb +0 -8
  16. data/lib/fontist/utils/cache.rb +27 -8
  17. data/lib/fontist/utils/downloader.rb +74 -32
  18. data/lib/fontist/version.rb +1 -1
  19. metadata +12 -87
  20. data/lib/fontist/import/extractors.rb +0 -9
  21. data/lib/fontist/import/extractors/cab_extractor.rb +0 -37
  22. data/lib/fontist/import/extractors/cpio_extractor.rb +0 -39
  23. data/lib/fontist/import/extractors/extractor.rb +0 -19
  24. data/lib/fontist/import/extractors/gzip_extractor.rb +0 -27
  25. data/lib/fontist/import/extractors/ole_extractor.rb +0 -41
  26. data/lib/fontist/import/extractors/rpm_extractor.rb +0 -45
  27. data/lib/fontist/import/extractors/seven_zip_extractor.rb +0 -44
  28. data/lib/fontist/import/extractors/tar_extractor.rb +0 -47
  29. data/lib/fontist/import/extractors/zip_extractor.rb +0 -31
  30. data/lib/fontist/utils/cpio/cpio.rb +0 -199
  31. data/lib/fontist/utils/cpio_extractor.rb +0 -47
  32. data/lib/fontist/utils/exe_extractor.rb +0 -75
  33. data/lib/fontist/utils/gzip_extractor.rb +0 -24
  34. data/lib/fontist/utils/msi_extractor.rb +0 -31
  35. data/lib/fontist/utils/rpm_extractor.rb +0 -44
  36. data/lib/fontist/utils/seven_zip_extractor.rb +0 -41
  37. data/lib/fontist/utils/tar_extractor.rb +0 -61
  38. data/lib/fontist/utils/zip_extractor.rb +0 -52
@@ -3,17 +3,18 @@ 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
13
14
 
14
15
  def file_paths(font, style)
15
16
  paths = find_font_with_name(font, style)
16
- return paths unless paths["paths"].empty?
17
+ return paths unless paths.nil?
17
18
 
18
19
  install_font(font)
19
20
 
@@ -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
@@ -42,26 +42,40 @@ module Fontist
42
42
  end
43
43
 
44
44
  def style_paths_map(font, names)
45
- paths = style_paths(font, names)
46
- names.zip(paths).to_h
45
+ styles = style_paths(font, names)
46
+ group_paths(styles)
47
47
  end
48
48
 
49
49
  def style_paths(font, names)
50
- names.map do |style|
51
- file_paths(font, style)
50
+ names.flat_map do |style|
51
+ file_paths(font, style) || empty_paths(style)
52
52
  end
53
53
  end
54
54
 
55
+ def group_paths(styles)
56
+ styles.group_by { |s| s[:type] }
57
+ .transform_values { |group| style(group) }
58
+ end
59
+
60
+ def style(styles)
61
+ { "full_name" => styles.first[:full_name],
62
+ "paths" => styles.map { |x| x[:path] } }.compact
63
+ end
64
+
55
65
  def file_paths(font, style)
56
66
  find_font_with_name(font, style).tap do |x|
57
- if x["paths"].empty?
67
+ if x.nil?
58
68
  raise Errors::MissingFontError.new(font, style)
59
69
  end
60
70
  end
61
71
  end
62
72
 
63
73
  def find_font_with_name(font, style)
64
- Fontist::SystemFont.find_with_name(font, style).map { |k, v| [k.to_s, v] }.to_h
74
+ Fontist::SystemFont.find_styles(font, style)
75
+ end
76
+
77
+ def empty_paths(style)
78
+ [{ "full_name" => nil, "type" => style, "path" => nil }]
65
79
  end
66
80
  end
67
81
  end
@@ -40,8 +40,8 @@ module Fontist
40
40
  new(font: font, sources: sources).find
41
41
  end
42
42
 
43
- def self.find_with_name(font, style)
44
- new(font: font, style: style).find_with_name
43
+ def self.find_styles(font, style)
44
+ new(font: font, style: style).find_styles
45
45
  end
46
46
 
47
47
  def find
@@ -51,22 +51,14 @@ module Fontist
51
51
  styles.map { |x| x[:path] }
52
52
  end
53
53
 
54
- def find_with_name
55
- styles = find_styles
56
- return { full_name: nil, paths: [] } unless styles
57
-
58
- { full_name: styles.first[:full_name],
59
- paths: styles.map { |x| x[:path] } }
54
+ def find_styles
55
+ find_by_index || find_by_formulas
60
56
  end
61
57
 
62
58
  private
63
59
 
64
60
  attr_reader :font, :style, :user_sources
65
61
 
66
- def find_styles
67
- find_by_index || find_by_formulas
68
- end
69
-
70
62
  def find_by_index
71
63
  SystemIndex.new(all_paths).find(font, style)
72
64
  end
data/lib/fontist/utils.rb CHANGED
@@ -5,14 +5,6 @@ require "fontist/utils/dsl"
5
5
  require "fontist/utils/dsl/font"
6
6
  require "fontist/utils/dsl/collection_font"
7
7
  require "fontist/utils/downloader"
8
- require "fontist/utils/zip_extractor"
9
- require "fontist/utils/exe_extractor"
10
- require "fontist/utils/msi_extractor"
11
- require "fontist/utils/seven_zip_extractor"
12
- require "fontist/utils/rpm_extractor"
13
- require "fontist/utils/gzip_extractor"
14
- require "fontist/utils/cpio_extractor"
15
- require "fontist/utils/tar_extractor"
16
8
 
17
9
  module Fontist
18
10
  module Utils
@@ -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.7".freeze
2
+ VERSION = "1.8.12".freeze
3
3
  end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fontist
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.7
4
+ version: 1.8.12
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-02-20 00:00:00.000000000 Z
11
+ date: 2021-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: arr-pm
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: 0.0.1
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: 0.0.1
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: down
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -39,49 +25,21 @@ dependencies:
39
25
  - !ruby/object:Gem::Version
40
26
  version: '5.0'
41
27
  - !ruby/object:Gem::Dependency
42
- name: libmspack
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: 0.1.0
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: 0.1.0
55
- - !ruby/object:Gem::Dependency
56
- name: rubyzip
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: 2.3.0
62
- type: :runtime
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: 2.3.0
69
- - !ruby/object:Gem::Dependency
70
- name: seven_zip_ruby
28
+ name: thor
71
29
  requirement: !ruby/object:Gem::Requirement
72
30
  requirements:
73
31
  - - "~>"
74
32
  - !ruby/object:Gem::Version
75
- version: '1.0'
33
+ version: 1.0.1
76
34
  type: :runtime
77
35
  prerelease: false
78
36
  version_requirements: !ruby/object:Gem::Requirement
79
37
  requirements:
80
38
  - - "~>"
81
39
  - !ruby/object:Gem::Version
82
- version: '1.0'
40
+ version: 1.0.1
83
41
  - !ruby/object:Gem::Dependency
84
- name: ruby-ole
42
+ name: git
85
43
  requirement: !ruby/object:Gem::Requirement
86
44
  requirements:
87
45
  - - "~>"
@@ -95,47 +53,33 @@ dependencies:
95
53
  - !ruby/object:Gem::Version
96
54
  version: '1.0'
97
55
  - !ruby/object:Gem::Dependency
98
- name: thor
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
102
- - !ruby/object:Gem::Version
103
- version: 1.0.1
104
- type: :runtime
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - "~>"
109
- - !ruby/object:Gem::Version
110
- version: 1.0.1
111
- - !ruby/object:Gem::Dependency
112
- name: git
56
+ name: ttfunk
113
57
  requirement: !ruby/object:Gem::Requirement
114
58
  requirements:
115
59
  - - "~>"
116
60
  - !ruby/object:Gem::Version
117
- version: '1.0'
61
+ version: '1.6'
118
62
  type: :runtime
119
63
  prerelease: false
120
64
  version_requirements: !ruby/object:Gem::Requirement
121
65
  requirements:
122
66
  - - "~>"
123
67
  - !ruby/object:Gem::Version
124
- version: '1.0'
68
+ version: '1.6'
125
69
  - !ruby/object:Gem::Dependency
126
- name: ttfunk
70
+ name: excavate
127
71
  requirement: !ruby/object:Gem::Requirement
128
72
  requirements:
129
73
  - - "~>"
130
74
  - !ruby/object:Gem::Version
131
- version: '1.0'
75
+ version: '0.1'
132
76
  type: :runtime
133
77
  prerelease: false
134
78
  version_requirements: !ruby/object:Gem::Requirement
135
79
  requirements:
136
80
  - - "~>"
137
81
  - !ruby/object:Gem::Version
138
- version: '1.0'
82
+ version: '0.1'
139
83
  - !ruby/object:Gem::Dependency
140
84
  name: extract_ttc
141
85
  requirement: !ruby/object:Gem::Requirement
@@ -324,16 +268,6 @@ files:
324
268
  - lib/fontist/import.rb
325
269
  - lib/fontist/import/convert_formulas.rb
326
270
  - lib/fontist/import/create_formula.rb
327
- - lib/fontist/import/extractors.rb
328
- - lib/fontist/import/extractors/cab_extractor.rb
329
- - lib/fontist/import/extractors/cpio_extractor.rb
330
- - lib/fontist/import/extractors/extractor.rb
331
- - lib/fontist/import/extractors/gzip_extractor.rb
332
- - lib/fontist/import/extractors/ole_extractor.rb
333
- - lib/fontist/import/extractors/rpm_extractor.rb
334
- - lib/fontist/import/extractors/seven_zip_extractor.rb
335
- - lib/fontist/import/extractors/tar_extractor.rb
336
- - lib/fontist/import/extractors/zip_extractor.rb
337
271
  - lib/fontist/import/files/collection_file.rb
338
272
  - lib/fontist/import/files/file_requirement.rb
339
273
  - lib/fontist/import/files/font_detector.rb
@@ -372,22 +306,13 @@ files:
372
306
  - lib/fontist/system_index.rb
373
307
  - lib/fontist/utils.rb
374
308
  - lib/fontist/utils/cache.rb
375
- - lib/fontist/utils/cpio/cpio.rb
376
- - lib/fontist/utils/cpio_extractor.rb
377
309
  - lib/fontist/utils/downloader.rb
378
310
  - lib/fontist/utils/dsl.rb
379
311
  - lib/fontist/utils/dsl/collection_font.rb
380
312
  - lib/fontist/utils/dsl/font.rb
381
- - lib/fontist/utils/exe_extractor.rb
382
- - lib/fontist/utils/gzip_extractor.rb
383
313
  - lib/fontist/utils/locking.rb
384
- - lib/fontist/utils/msi_extractor.rb
385
- - lib/fontist/utils/rpm_extractor.rb
386
- - lib/fontist/utils/seven_zip_extractor.rb
387
314
  - lib/fontist/utils/system.rb
388
- - lib/fontist/utils/tar_extractor.rb
389
315
  - lib/fontist/utils/ui.rb
390
- - lib/fontist/utils/zip_extractor.rb
391
316
  - lib/fontist/version.rb
392
317
  homepage: https://github.com/fontist/fontist
393
318
  licenses: