fontist 1.8.7 → 1.8.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 69bc4225a7dac5b44f92364344568e4990ec3917631febbab1739a4980890308
4
- data.tar.gz: b1bd65c7db74152b911375a6990cda7dd23f849291feeb00edd3fddda5b93f4d
3
+ metadata.gz: 7cd7962408633c39bb2cfff2ef8c3c0500842033f80ed7211474eefe98845327
4
+ data.tar.gz: 4630d28fbe5afad9865aeaebfa46e50215eb99cc8e2580466ae1fcb616117cfa
5
5
  SHA512:
6
- metadata.gz: 298d8927f07494407568e35fea9a3ed6fc26a725df7dcd9f4a6f3e134be628bc38bc315b0d61bac63c15c92501396b04c8e59dcad59429420785fdeaf9d4ac22
7
- data.tar.gz: 27f7bf0e155c8c3210030de3e5d1f140b4b0cee26214ca48c5cf34136eb09f8850f80178aa331b608c61583af003c8d7ca4ac071601e3fe8dbbebd25e6e15e9d
6
+ metadata.gz: 57ac2451e5911694725ddd4f7f29bb8693e0be8e4397101f1f90c6a83ba353ea51fc7e2c9c0875e1bc0f4f17a466b9191d2c4017a47e971c9bb620bef0ea4a4c
7
+ data.tar.gz: 6aee6a31dd412af421191cb8cb5ca7793d5071bfcb0101666ef7d591abffcb98a7e9a3990978e7268d4e55fb1f0fa339711bffe801f272e08c133cd3c6783a9b
data/fontist.gemspec CHANGED
@@ -27,15 +27,11 @@ Gem::Specification.new do |spec|
27
27
  spec.executables = ["fontist"]
28
28
  spec.test_files = `git ls-files -- {spec}/*`.split("\n")
29
29
 
30
- spec.add_runtime_dependency "arr-pm", "~> 0.0.1"
31
30
  spec.add_runtime_dependency "down", "~> 5.0"
32
- spec.add_runtime_dependency "libmspack", "~> 0.1.0"
33
- spec.add_runtime_dependency "rubyzip", "~> 2.3.0"
34
- spec.add_runtime_dependency "seven_zip_ruby", "~> 1.0"
35
- spec.add_runtime_dependency "ruby-ole", "~> 1.0"
36
31
  spec.add_runtime_dependency "thor", "~> 1.0.1"
37
32
  spec.add_runtime_dependency "git", "~> 1.0"
38
33
  spec.add_runtime_dependency "ttfunk", "~> 1.0"
34
+ spec.add_runtime_dependency "excavate", "~> 0.1"
39
35
 
40
36
  spec.add_development_dependency "extract_ttc", "~> 0.1"
41
37
  spec.add_development_dependency "pry"
@@ -1,16 +1,8 @@
1
1
  require "fontist/utils"
2
+ require "excavate"
2
3
 
3
4
  module Fontist
4
5
  class FontInstaller
5
- include Utils::ZipExtractor
6
- include Utils::ExeExtractor
7
- include Utils::MsiExtractor
8
- include Utils::SevenZipExtractor
9
- include Utils::RpmExtractor
10
- include Utils::GzipExtractor
11
- include Utils::CpioExtractor
12
- include Utils::TarExtractor
13
-
14
6
  def initialize(formula)
15
7
  @formula = formula
16
8
  end
@@ -20,7 +12,6 @@ module Fontist
20
12
  raise(Fontist::Errors::LicensingError)
21
13
  end
22
14
 
23
- reinitialize
24
15
  install_font
25
16
  end
26
17
 
@@ -28,10 +19,6 @@ module Fontist
28
19
 
29
20
  attr_reader :formula
30
21
 
31
- def reinitialize
32
- @downloaded = false
33
- end
34
-
35
22
  def install_font
36
23
  fonts_paths = run_in_temp_dir { extract }
37
24
  fonts_paths.empty? ? nil : fonts_paths
@@ -50,47 +37,39 @@ module Fontist
50
37
  end
51
38
 
52
39
  def extract
53
- resource = @formula.resources.first
54
-
55
- [@formula.extract].flatten.each do |operation|
56
- resource = extract_by_operation(operation, resource)
57
- end
58
-
59
- fonts_paths = resource
40
+ archive = download_file(@formula.resources.first)
60
41
 
61
- fonts_paths
42
+ install_fonts_from_archive(archive)
62
43
  end
63
44
 
64
- def extract_by_operation(operation, resource)
65
- method = "#{operation.format}_extract"
66
- if operation.options
67
- send(method, resource, **operation.options.to_h)
68
- else
69
- send(method, resource)
70
- end
71
- end
45
+ def install_fonts_from_archive(archive)
46
+ Fontist.ui.say(%(Installing font "#{@formula.key}".))
72
47
 
73
- def fonts_path
74
- Fontist.fonts_path
48
+ Array.new.tap do |fonts_paths|
49
+ Excavate::Archive.new(archive.path).files(recursive_packages: true) do |path|
50
+ fonts_paths << install_font_file(path) if font_file?(path)
51
+ end
52
+ end
75
53
  end
76
54
 
77
55
  def download_file(source)
78
56
  url = source.urls.first
79
57
  Fontist.ui.say(%(Downloading font "#{@formula.key}" from #{url}))
80
58
 
81
- downloaded_file = Fontist::Utils::Downloader.download(
59
+ Fontist::Utils::Downloader.download(
82
60
  url,
83
61
  sha: source.sha256,
84
62
  file_size: source.file_size,
85
63
  progress_bar: true
86
64
  )
65
+ end
87
66
 
88
- @downloaded = true
89
- downloaded_file
67
+ def font_file?(path)
68
+ source_file?(path) && font_directory?(path)
90
69
  end
91
70
 
92
- def font_file?(filename)
93
- source_files.include?(filename)
71
+ def source_file?(path)
72
+ source_files.include?(File.basename(path))
94
73
  end
95
74
 
96
75
  def source_files
@@ -101,6 +80,27 @@ module Fontist
101
80
  end
102
81
  end
103
82
 
83
+ def font_directory?(path)
84
+ return true unless subdirectory_pattern
85
+
86
+ File.fnmatch?(subdirectory_pattern, File.dirname(path))
87
+ end
88
+
89
+ def subdirectory_pattern
90
+ @subdirectory_pattern ||= "*" + subdirectories.first.chomp("/") unless subdirectories.empty?
91
+ end
92
+
93
+ def subdirectories
94
+ @subdirectories ||= [@formula.extract].flatten.map(&:options).compact.map(&:fonts_sub_dir).compact
95
+ end
96
+
97
+ def install_font_file(source)
98
+ target = Fontist.fonts_path.join(target_filename(File.basename(source))).to_s
99
+ FileUtils.mv(source, target)
100
+
101
+ target
102
+ end
103
+
104
104
  def target_filename(source_filename)
105
105
  target_filenames[source_filename]
106
106
  end
@@ -1,21 +1,18 @@
1
- require "find"
2
- require_relative "extractors"
3
1
  require_relative "files/font_detector"
4
2
 
5
3
  module Fontist
6
4
  module Import
7
5
  class RecursiveExtraction
8
- FONTS_PATTERN = "**/*.{ttf,otf,ttc}".freeze
9
- ARCHIVE_EXTENSIONS = %w[zip msi exe cab].freeze
10
6
  LICENSE_PATTERN = /(ofl\.txt|ufl\.txt|licenses?\.txt|copying)$/i.freeze
11
7
 
12
8
  def initialize(archive, subarchive: nil, subdir: nil)
13
9
  @archive = archive
14
- @subarchive = subarchive
15
10
  @subdir = subdir
16
- @operations = []
11
+ @operations = {}
17
12
  @font_files = []
18
13
  @collection_files = []
14
+
15
+ save_operation_subdir
19
16
  end
20
17
 
21
18
  def extension
@@ -39,11 +36,18 @@ module Fontist
39
36
 
40
37
  def operations
41
38
  ensure_extracted
42
- @operations.size == 1 ? @operations.first : @operations
39
+ @operations
43
40
  end
44
41
 
45
42
  private
46
43
 
44
+ def save_operation_subdir
45
+ return unless @subdir
46
+
47
+ @operations[:options] ||= {}
48
+ @operations[:options][:fonts_sub_dir] = @subdir
49
+ end
50
+
47
51
  def fetch_extension(file)
48
52
  File.extname(filename(file)).sub(/^\./, "")
49
53
  end
@@ -57,68 +61,21 @@ module Fontist
57
61
  end
58
62
 
59
63
  def ensure_extracted
60
- extracted_path
61
- end
64
+ return if @extracted
62
65
 
63
- def extracted_path
64
- @extracted_path ||= extract_recursively(@archive)
66
+ extract_data(@archive)
67
+ @extracted = true
65
68
  end
66
69
 
67
- def extract_recursively(archive)
68
- path = operate_on_archive(archive)
69
- match_files(path)
70
- if matched?
71
- save_operation_subdir
72
- return path
73
- end
74
-
75
- next_archive = find_archive(path)
76
- extract_recursively(next_archive)
77
- end
78
-
79
- def operate_on_archive(archive)
80
- extractor = choose_extractor(archive)
81
- Fontist.ui.say("Extracting #{archive} with #{extractor.class.name}")
82
-
83
- save_operation(extractor)
84
- extractor.extract
85
- end
86
-
87
- # rubocop:disable Metrics/MethodLength
88
- def choose_extractor(archive)
89
- case fetch_extension(archive).downcase
90
- when "msi"
91
- Extractors::OleExtractor.new(archive)
92
- when "cab"
93
- Extractors::CabExtractor.new(archive)
94
- when "exe"
95
- extractor = Extractors::SevenZipExtractor.new(archive)
96
- extractor.try ? extractor : Extractors::CabExtractor.new(archive)
97
- when "zip"
98
- Extractors::ZipExtractor.new(archive)
99
- when "rpm"
100
- Extractors::RpmExtractor.new(archive)
101
- when "gz"
102
- Extractors::GzipExtractor.new(archive)
103
- when "cpio"
104
- Extractors::CpioExtractor.new(archive)
105
- when "tar"
106
- Extractors::TarExtractor.new(archive)
107
- else
108
- raise Errors::UnknownArchiveError, "Could not unarchive `#{filename(archive)}`."
70
+ def extract_data(archive)
71
+ Excavate::Archive.new(path(archive)).files(recursive_packages: true) do |path|
72
+ match_license(path)
73
+ match_font(path) if font_directory?(path)
109
74
  end
110
75
  end
111
- # rubocop:enable Metrics/MethodLength
112
76
 
113
- def save_operation(extractor)
114
- @operations << { format: extractor.format }
115
- end
116
-
117
- def match_files(dir_path)
118
- Find.find(dir_path) do |entry_path| # rubocop:disable Style/CollectionMethods
119
- match_license(entry_path)
120
- match_font(entry_path) if font_directory?(entry_path, dir_path)
121
- end
77
+ def path(file)
78
+ file.respond_to?(:path) ? file.path : file
122
79
  end
123
80
 
124
81
  def match_license(path)
@@ -129,18 +86,6 @@ module Fontist
129
86
  file.match?(LICENSE_PATTERN)
130
87
  end
131
88
 
132
- def font_directory?(path, base_path)
133
- return true unless @subdir
134
-
135
- # https://bugs.ruby-lang.org/issues/10011
136
- base_path = Pathname.new(base_path)
137
-
138
- relative_path = Pathname.new(path).relative_path_from(base_path).to_s
139
- dirname = File.dirname(relative_path)
140
- normalized_pattern = @subdir.chomp("/")
141
- File.fnmatch?(normalized_pattern, dirname)
142
- end
143
-
144
89
  def match_font(path)
145
90
  case Files::FontDetector.detect(path)
146
91
  when :font
@@ -150,53 +95,14 @@ module Fontist
150
95
  end
151
96
  end
152
97
 
153
- def matched?
154
- [@font_files, @collection_files].any? do |files|
155
- files.size.positive?
156
- end
157
- end
158
-
159
- def save_operation_subdir
160
- return unless @subdir
161
-
162
- @operations.last[:options] ||= {}
163
- @operations.last[:options][:fonts_sub_dir] = @subdir
164
- end
165
-
166
- def find_archive(path)
167
- children = Dir.entries(path) - [".", ".."] # ruby 2.4 compat
168
- paths = children.map { |file| File.join(path, file) }
169
- by_subarchive(paths) || by_size(paths)
170
- end
171
-
172
- def by_subarchive(paths)
173
- return unless @subarchive
174
-
175
- path_found = paths.detect do |path|
176
- @subarchive == File.basename(path)
177
- end
178
-
179
- return unless path_found
180
-
181
- save_operation_subarchive(path_found)
182
-
183
- path_found
184
- end
185
-
186
- def save_operation_subarchive(path)
187
- @operations.last[:options] ||= {}
188
- @operations.last[:options][:subarchive] = File.basename(path)
189
- end
98
+ def font_directory?(path)
99
+ return true unless subdirectory_pattern
190
100
 
191
- def by_size(paths)
192
- paths.max_by do |path|
193
- [file_type(path), File.size(path)]
194
- end
101
+ File.fnmatch?(subdirectory_pattern, File.dirname(path))
195
102
  end
196
103
 
197
- def file_type(file_path)
198
- extension = File.extname(file_path).delete(".")
199
- ARCHIVE_EXTENSIONS.include?(extension) ? 1 : 0
104
+ def subdirectory_pattern
105
+ @subdirectory_pattern ||= "*" + @subdir.chomp("/") if @subdir
200
106
  end
201
107
  end
202
108
  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
@@ -1,3 +1,3 @@
1
1
  module Fontist
2
- VERSION = "1.8.7".freeze
2
+ VERSION = "1.8.8".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.8
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-02-26 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,21 +53,7 @@ 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
  - - "~>"
@@ -123,19 +67,19 @@ dependencies:
123
67
  - !ruby/object:Gem::Version
124
68
  version: '1.0'
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: