fontist 1.8.6 → 1.8.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rspec.yml +5 -14
  3. data/README.md +3 -3
  4. data/fontist.gemspec +3 -7
  5. data/lib/fontist/cli.rb +3 -1
  6. data/lib/fontist/font.rb +20 -15
  7. data/lib/fontist/font_installer.rb +40 -39
  8. data/lib/fontist/formula.rb +4 -0
  9. data/lib/fontist/import/helpers/system_helper.rb +1 -3
  10. data/lib/fontist/import/recursive_extraction.rb +25 -119
  11. data/lib/fontist/manifest/install.rb +10 -3
  12. data/lib/fontist/utils.rb +0 -8
  13. data/lib/fontist/utils/cache.rb +27 -8
  14. data/lib/fontist/utils/downloader.rb +81 -36
  15. data/lib/fontist/version.rb +1 -1
  16. metadata +14 -89
  17. data/lib/fontist/import/extractors.rb +0 -9
  18. data/lib/fontist/import/extractors/cab_extractor.rb +0 -37
  19. data/lib/fontist/import/extractors/cpio_extractor.rb +0 -39
  20. data/lib/fontist/import/extractors/extractor.rb +0 -19
  21. data/lib/fontist/import/extractors/gzip_extractor.rb +0 -27
  22. data/lib/fontist/import/extractors/ole_extractor.rb +0 -41
  23. data/lib/fontist/import/extractors/rpm_extractor.rb +0 -45
  24. data/lib/fontist/import/extractors/seven_zip_extractor.rb +0 -44
  25. data/lib/fontist/import/extractors/tar_extractor.rb +0 -47
  26. data/lib/fontist/import/extractors/zip_extractor.rb +0 -31
  27. data/lib/fontist/utils/cpio/cpio.rb +0 -199
  28. data/lib/fontist/utils/cpio_extractor.rb +0 -47
  29. data/lib/fontist/utils/exe_extractor.rb +0 -75
  30. data/lib/fontist/utils/gzip_extractor.rb +0 -24
  31. data/lib/fontist/utils/msi_extractor.rb +0 -31
  32. data/lib/fontist/utils/rpm_extractor.rb +0 -37
  33. data/lib/fontist/utils/seven_zip_extractor.rb +0 -41
  34. data/lib/fontist/utils/tar_extractor.rb +0 -61
  35. data/lib/fontist/utils/zip_extractor.rb +0 -52
@@ -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
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)
@@ -3,17 +3,24 @@ require_relative "cache"
3
3
  module Fontist
4
4
  module Utils
5
5
  class Downloader
6
+ class << self
7
+ def download(*args)
8
+ new(*args).download
9
+ end
10
+ ruby2_keywords :download if respond_to?(:ruby2_keywords, true)
11
+ end
12
+
6
13
  def initialize(file, file_size: nil, sha: nil, progress_bar: nil)
7
14
  # TODO: If the first mirror fails, try the second one
8
15
  @file = file
9
16
  @sha = [sha].flatten.compact
10
- @file_size = (file_size || default_file_size).to_i
17
+ @file_size = file_size.to_i if file_size
11
18
  @progress_bar = set_progress_bar(progress_bar)
12
19
  @cache = Cache.new
13
20
  end
14
21
 
15
22
  def download
16
- file = @cache.fetch(@file, bar: @progress_bar) do
23
+ file = @cache.fetch(@file) do
17
24
  download_file
18
25
  end
19
26
 
@@ -27,18 +34,10 @@ module Fontist
27
34
  file
28
35
  end
29
36
 
30
- def self.download(file, options = {})
31
- new(file, options).download
32
- end
33
-
34
37
  private
35
38
 
36
39
  attr_reader :file, :sha, :file_size
37
40
 
38
- def default_file_size
39
- 5 * byte_to_megabyte
40
- end
41
-
42
41
  def byte_to_megabyte
43
42
  @byte_to_megabyte ||= 1024 * 1024
44
43
  end
@@ -48,10 +47,10 @@ module Fontist
48
47
  end
49
48
 
50
49
  def set_progress_bar(progress_bar)
51
- if ENV.fetch("TEST_ENV", "") === "CI" || progress_bar
50
+ if progress_bar
52
51
  ProgressBar.new(@file_size)
53
52
  else
54
- NullProgressBar.new
53
+ NullProgressBar.new(@file_size)
55
54
  end
56
55
  end
57
56
 
@@ -76,24 +75,13 @@ module Fontist
76
75
  end
77
76
  end
78
77
 
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
-
93
78
  class ProgressBar
94
79
  def initialize(total)
95
- @counter = 1
80
+ @counter = 0
96
81
  @total = total
82
+ @printed_percent = -1
83
+ @printed_size = -1
84
+ @start = Time.now
97
85
  end
98
86
 
99
87
  def total=(total)
@@ -102,22 +90,57 @@ module Fontist
102
90
 
103
91
  def increment(progress)
104
92
  @counter = progress
105
- Fontist.ui.print "\r\e[0KDownloads: #{counter_mb}MB/#{total_mb}MB " \
106
- "(#{completeness})"
93
+
94
+ print_incrementally
107
95
  end
108
96
 
109
- def finish(message = nil)
110
- if message
111
- Fontist.ui.print " (#{message})\n"
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))
101
+ end
102
+
103
+ private
104
+
105
+ def print_incrementally
106
+ if total?
107
+ print_percent_incrementally
112
108
  else
113
- Fontist.ui.print "\n"
109
+ print_size_incrementally
114
110
  end
115
111
  end
116
112
 
117
- 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
124
+
125
+ def print_percent_incrementally
126
+ return unless percent > @printed_percent
118
127
 
119
- def completeness
120
- sprintf("%#.2f%%", (@counter.fdiv(@total) * 100)) # rubocop:disable Style/FormatStringToken, Metrics/LineLength
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
121
144
  end
122
145
 
123
146
  def counter_mb
@@ -131,6 +154,28 @@ module Fontist
131
154
  def byte_to_megabyte
132
155
  @byte_to_megabyte ||= 1024 * 1024
133
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
134
179
  end
135
180
  end
136
181
  end
@@ -1,3 +1,3 @@
1
1
  module Fontist
2
- VERSION = "1.8.6".freeze
2
+ VERSION = "1.8.11".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.6
4
+ version: 1.8.11
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-05 00:00:00.000000000 Z
11
+ date: 2021-03-21 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
@@ -212,14 +156,14 @@ dependencies:
212
156
  requirements:
213
157
  - - "~>"
214
158
  - !ruby/object:Gem::Version
215
- version: 12.3.3
159
+ version: '13'
216
160
  type: :development
217
161
  prerelease: false
218
162
  version_requirements: !ruby/object:Gem::Requirement
219
163
  requirements:
220
164
  - - "~>"
221
165
  - !ruby/object:Gem::Version
222
- version: 12.3.3
166
+ version: '13'
223
167
  - !ruby/object:Gem::Dependency
224
168
  name: rspec
225
169
  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: