fontist 1.8.4 → 1.8.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rspec.yml +13 -13
  3. data/fontist.gemspec +3 -7
  4. data/lib/fontist.rb +4 -0
  5. data/lib/fontist/cli.rb +11 -22
  6. data/lib/fontist/font.rb +37 -42
  7. data/lib/fontist/font_installer.rb +37 -37
  8. data/lib/fontist/font_path.rb +29 -0
  9. data/lib/fontist/formula.rb +8 -4
  10. data/lib/fontist/import/recursive_extraction.rb +25 -119
  11. data/lib/fontist/index.rb +4 -65
  12. data/lib/fontist/indexes/base_index.rb +82 -0
  13. data/lib/fontist/indexes/filename_index.rb +19 -0
  14. data/lib/fontist/indexes/font_index.rb +21 -0
  15. data/lib/fontist/indexes/index_formula.rb +36 -0
  16. data/lib/fontist/manifest/install.rb +3 -2
  17. data/lib/fontist/utils.rb +0 -8
  18. data/lib/fontist/utils/downloader.rb +7 -4
  19. data/lib/fontist/version.rb +1 -1
  20. metadata +21 -92
  21. data/lib/fontist/import/extractors.rb +0 -9
  22. data/lib/fontist/import/extractors/cab_extractor.rb +0 -37
  23. data/lib/fontist/import/extractors/cpio_extractor.rb +0 -39
  24. data/lib/fontist/import/extractors/extractor.rb +0 -19
  25. data/lib/fontist/import/extractors/gzip_extractor.rb +0 -27
  26. data/lib/fontist/import/extractors/ole_extractor.rb +0 -41
  27. data/lib/fontist/import/extractors/rpm_extractor.rb +0 -45
  28. data/lib/fontist/import/extractors/seven_zip_extractor.rb +0 -44
  29. data/lib/fontist/import/extractors/tar_extractor.rb +0 -47
  30. data/lib/fontist/import/extractors/zip_extractor.rb +0 -31
  31. data/lib/fontist/index_formula.rb +0 -30
  32. data/lib/fontist/utils/cpio/cpio.rb +0 -199
  33. data/lib/fontist/utils/cpio_extractor.rb +0 -47
  34. data/lib/fontist/utils/exe_extractor.rb +0 -75
  35. data/lib/fontist/utils/gzip_extractor.rb +0 -24
  36. data/lib/fontist/utils/msi_extractor.rb +0 -31
  37. data/lib/fontist/utils/rpm_extractor.rb +0 -37
  38. data/lib/fontist/utils/seven_zip_extractor.rb +0 -41
  39. data/lib/fontist/utils/tar_extractor.rb +0 -61
  40. data/lib/fontist/utils/zip_extractor.rb +0 -52
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e12ad24d94f6220992c66f06c21872135932b1b64f7ae17c7aa414c2f80f12ad
4
- data.tar.gz: 29665a7556a8fbeda7449616c688a90e694b8060c7f2b8158abcc41e049579c4
3
+ metadata.gz: 0c34f4a52f1c0842347ebd17811c7550b4eb9e31048bab00077cea20dcd94985
4
+ data.tar.gz: 9a5bad3ff72333d3b73673189510f0b739ef1160233235212e6b0c21f5152d2c
5
5
  SHA512:
6
- metadata.gz: 92b8942a88a3f02c57fd9840060c8ba333f0378611477bf1ff9435296792a4b79f97616da3520ea8d6fbe1088498c6d15d9c885c02e740fdc4bc26811988b176
7
- data.tar.gz: 41aab015006c2109db2a52ea6ace23aeaaa571e5153559c53e327c448be4684189c7d72d5785811ecf505b124a48fa5016f5cfe62cd0946f92d0d6aab6d9b870
6
+ metadata.gz: d8d58465500cd8417d3c164cb791215d6adcfeee358ac60b14d93492d5c6ef1b465cb26236e44ced38566995d61e741ffe1566ad482c491d474ccea9c10fa447
7
+ data.tar.gz: f41298a94ffe8d6c2d6f33ff990f9e3c03b6271d580db2a86f48d94bc7dd4776a7c767f7d0d946097782ec00335c716053c90bd88aec4ba3dc274a6e863555bb
@@ -13,19 +13,19 @@ jobs:
13
13
  strategy:
14
14
  fail-fast: false
15
15
  matrix:
16
- ruby: [ '2.6', '2.5', '2.4' ]
16
+ ruby: [ '2.4', '2.5', '2.6', '2.7' ]
17
17
  os: [ ubuntu-latest, windows-latest, macos-latest ]
18
18
  experimental: [ false ]
19
- include:
20
- - ruby: '2.7'
21
- os: 'ubuntu-latest'
22
- experimental: true
23
- - ruby: '2.7'
24
- os: 'windows-latest'
25
- experimental: true
26
- - ruby: '2.7'
27
- os: 'macos-latest'
28
- experimental: true
19
+ # include:
20
+ # - ruby: '3.0'
21
+ # os: 'ubuntu-latest'
22
+ # experimental: true
23
+ # - ruby: '3.0'
24
+ # os: 'windows-latest'
25
+ # experimental: true
26
+ # - ruby: '3.0'
27
+ # os: 'macos-latest'
28
+ # experimental: true
29
29
 
30
30
  steps:
31
31
  - uses: actions/checkout@master
@@ -37,8 +37,8 @@ jobs:
37
37
  - uses: actions/cache@v1
38
38
  with:
39
39
  path: vendor/bundle
40
- key: bundle-${{ matrix.os }}-${{ matrix.ruby }}-${{ hashFiles('**/*.gemspec') }}
41
- restore-keys: bundle-${{ matrix.os }}-${{ matrix.ruby }}
40
+ key: bundle-v2-${{ matrix.os }}-${{ matrix.ruby }}-${{ hashFiles('**/*.gemspec') }}
41
+ restore-keys: bundle-v2-${{ matrix.os }}-${{ matrix.ruby }}
42
42
 
43
43
  - if: matrix.os == 'macos-latest'
44
44
  run: brew install lcdf-typetools
data/fontist.gemspec CHANGED
@@ -27,22 +27,18 @@ 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
- spec.add_runtime_dependency "ttfunk", "~> 1.0"
33
+ spec.add_runtime_dependency "ttfunk", "~> 1.6.2"
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"
42
38
  spec.add_development_dependency "bundler", "~> 2.0"
43
39
  spec.add_development_dependency "gem-release"
44
40
  spec.add_development_dependency "nokogiri", "~> 1.0"
45
- spec.add_development_dependency "rake", "~> 12.3.3"
41
+ spec.add_development_dependency "rake", "~> 13"
46
42
  spec.add_development_dependency "rspec", "~> 3.0"
47
43
  spec.add_development_dependency "rubocop", "0.75.0"
48
44
  spec.add_development_dependency "rubocop-rails"
data/lib/fontist.rb CHANGED
@@ -62,4 +62,8 @@ module Fontist
62
62
  def self.formula_index_path
63
63
  Fontist.formulas_repo_path.join("index.yml")
64
64
  end
65
+
66
+ def self.formula_filename_index_path
67
+ Fontist.formulas_repo_path.join("filename_index.yml")
68
+ end
65
69
  end
data/lib/fontist/cli.rb CHANGED
@@ -29,12 +29,14 @@ module Fontist
29
29
  desc "install FONT", "Install font"
30
30
  option :force, type: :boolean, aliases: :f,
31
31
  desc: "Install even if it's already installed in system"
32
- option :confirm_license, type: :boolean, desc: "Confirm license agreement"
32
+ option :accept_all_licenses, type: :boolean, aliases: "--confirm-license", desc: "Accept all license agreements"
33
+ option :hide_licenses, type: :boolean, desc: "Hide license texts"
33
34
  def install(font)
34
35
  Fontist::Font.install(
35
36
  font,
36
37
  force: options[:force],
37
- confirmation: options[:confirm_license] ? "yes" : "no"
38
+ confirmation: options[:accept_all_licenses] ? "yes" : "no",
39
+ hide_licenses: options[:hide_licenses]
38
40
  )
39
41
  success
40
42
  rescue Fontist::Errors::GeneralError => e
@@ -52,12 +54,11 @@ module Fontist
52
54
  end
53
55
  map remove: :uninstall
54
56
 
55
- desc "status [FONT]", "Show status of FONT or all fonts in fontist"
57
+ desc "status [FONT]", "Show paths of FONT or all fonts"
56
58
  def status(font = nil)
57
- formulas = Fontist::Font.status(font)
58
- return error("No font is installed.", STATUS_MISSING_FONT_ERROR) if formulas.empty?
59
+ paths = Fontist::Font.status(font)
60
+ return error("No font is installed.", STATUS_MISSING_FONT_ERROR) if paths.empty?
59
61
 
60
- print_formulas(formulas)
61
62
  success
62
63
  rescue Fontist::Errors::GeneralError => e
63
64
  handle_error(e)
@@ -90,11 +91,13 @@ module Fontist
90
91
  end
91
92
 
92
93
  desc "manifest-install MANIFEST", "Install fonts from MANIFEST (yaml)"
93
- option :confirm_license, type: :boolean, desc: "Confirm license agreement"
94
+ option :accept_all_licenses, type: :boolean, aliases: "--confirm-license", desc: "Accept all license agreements"
95
+ option :hide_licenses, type: :boolean, desc: "Hide license texts"
94
96
  def manifest_install(manifest)
95
97
  paths = Fontist::Manifest::Install.from_file(
96
98
  manifest,
97
- confirmation: options[:confirm_license] ? "yes" : "no"
99
+ confirmation: options[:accept_all_licenses] ? "yes" : "no",
100
+ hide_licenses: options[:hide_licenses]
98
101
  )
99
102
 
100
103
  print_yaml(paths)
@@ -155,20 +158,6 @@ module Fontist
155
158
  Fontist.ui.say(YAML.dump(object))
156
159
  end
157
160
 
158
- def print_formulas(formulas)
159
- formulas.each do |formula, fonts|
160
- Fontist.ui.success(formula.key)
161
-
162
- fonts.each do |font, styles|
163
- Fontist.ui.success(" #{font.name}")
164
-
165
- styles.each do |style, path|
166
- Fontist.ui.success(" #{style.type} (#{path})")
167
- end
168
- end
169
- end
170
- end
171
-
172
161
  # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
173
162
  def print_list(formulas)
174
163
  formulas.each do |formula, fonts|
data/lib/fontist/font.rb CHANGED
@@ -1,10 +1,12 @@
1
1
  require "fontist/font_installer"
2
+ require "fontist/font_path"
2
3
 
3
4
  module Fontist
4
5
  class Font
5
6
  def initialize(options = {})
6
7
  @name = options[:name]
7
8
  @confirmation = options[:confirmation] || "no"
9
+ @hide_licenses = options[:hide_licenses]
8
10
  @force = options[:force] || false
9
11
 
10
12
  check_or_create_fontist_path!
@@ -18,8 +20,8 @@ module Fontist
18
20
  new(name: name).find
19
21
  end
20
22
 
21
- def self.install(name, confirmation: "no", force: false)
22
- new(name: name, confirmation: confirmation, force: force).install
23
+ def self.install(name, options = {})
24
+ new(options.merge(name: name)).install
23
25
  end
24
26
 
25
27
  def self.uninstall(name)
@@ -47,9 +49,9 @@ module Fontist
47
49
  end
48
50
 
49
51
  def status
50
- return installed_statuses unless @name
52
+ return installed_paths unless @name
51
53
 
52
- font_status || downloadable_font || raise_non_supported_font
54
+ find_system_font || downloadable_font || raise_non_supported_font
53
55
  end
54
56
 
55
57
  def list
@@ -64,7 +66,7 @@ module Fontist
64
66
 
65
67
  private
66
68
 
67
- attr_reader :name, :confirmation
69
+ attr_reader :name
68
70
 
69
71
  def find_system_font
70
72
  paths = Fontist::SystemFont.find(name)
@@ -73,9 +75,14 @@ module Fontist
73
75
  return
74
76
  end
75
77
 
78
+ print_paths(paths)
79
+ end
80
+
81
+ def print_paths(paths)
76
82
  Fontist.ui.say("Fonts found at:")
77
83
  paths.each do |path|
78
- Fontist.ui.say("- #{path}")
84
+ font_path = FontPath.new(path)
85
+ Fontist.ui.say(font_path.to_s)
79
86
  end
80
87
  end
81
88
 
@@ -94,6 +101,10 @@ module Fontist
94
101
  @formula ||= Fontist::Formula.find(name)
95
102
  end
96
103
 
104
+ def formulas
105
+ @formulas ||= Fontist::Formula.find_many(name)
106
+ end
107
+
97
108
  def downloadable_font
98
109
  if formula
99
110
  raise Fontist::Errors::MissingFontError.new(name)
@@ -101,8 +112,10 @@ module Fontist
101
112
  end
102
113
 
103
114
  def download_font
104
- if formula
105
- check_and_confirm_required_license(formula)
115
+ return if formulas.empty?
116
+
117
+ formulas.flat_map do |formula|
118
+ confirmation = check_and_confirm_required_license(formula)
106
119
  paths = font_installer(formula).install(confirmation: confirmation)
107
120
 
108
121
  Fontist.ui.say("Fonts installed at:")
@@ -113,19 +126,24 @@ module Fontist
113
126
  end
114
127
 
115
128
  def check_and_confirm_required_license(formula)
116
- if formula.license_required && !confirmation.casecmp("yes").zero?
117
- @confirmation = show_license_and_ask_for_input(formula.license)
129
+ return @confirmation unless formula.license_required
118
130
 
119
- unless confirmation&.casecmp?("yes")
120
- raise Fontist::Errors::LicensingError.new(
121
- "Fontist will not download these fonts unless you accept the terms."
122
- )
123
- end
124
- end
131
+ show_license(formula.license) unless @hide_licenses
132
+ return @confirmation if @confirmation.casecmp?("yes")
133
+
134
+ confirmation = ask_for_agreement
135
+ return confirmation if confirmation&.casecmp?("yes")
136
+
137
+ raise Fontist::Errors::LicensingError.new(
138
+ "Fontist will not download these fonts unless you accept the terms."
139
+ )
125
140
  end
126
141
 
127
- def show_license_and_ask_for_input(license)
142
+ def show_license(license)
128
143
  Fontist.ui.say(license_agrement_message(license))
144
+ end
145
+
146
+ def ask_for_agreement
129
147
  Fontist.ui.ask(
130
148
  "\nDo you accept all presented font licenses, and want Fontist " \
131
149
  "to download these fonts for you? => TYPE 'Yes' or 'No':"
@@ -161,37 +179,14 @@ module Fontist
161
179
  Fontist::FontistFont.find(name)
162
180
  end
163
181
 
164
- def installed_statuses
165
- installed_styles(all_formulas)
182
+ def installed_paths
183
+ print_paths(SystemFont.font_paths)
166
184
  end
167
185
 
168
186
  def all_formulas
169
187
  Fontist::Formula.all
170
188
  end
171
189
 
172
- def font_status
173
- return unless formula
174
-
175
- statuses = installed_styles([formula])
176
- statuses.empty? ? nil : statuses
177
- end
178
-
179
- def installed_styles(formulas)
180
- filter_blank(formulas) do |formula|
181
- filter_blank(formula.fonts) do |font|
182
- filter_blank(font.styles) do |style|
183
- path(style)
184
- end
185
- end
186
- end
187
- end
188
-
189
- def filter_blank(elements)
190
- elements.map { |e| [e, yield(e)] }
191
- .to_h
192
- .reject { |_k, v| v.nil? || v.empty? }
193
- end
194
-
195
190
  def path(style)
196
191
  font_paths.detect do |path|
197
192
  File.basename(path) == style.font
@@ -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
@@ -0,0 +1,29 @@
1
+ require "fontist/indexes/filename_index"
2
+
3
+ module Fontist
4
+ class FontPath
5
+ def initialize(path)
6
+ @path = path
7
+ end
8
+
9
+ def to_s
10
+ [].tap do |s|
11
+ s << "-"
12
+ s << @path
13
+ s << "(from #{formulas.join(' or ')} formula)" if formulas.any?
14
+ end.join(" ")
15
+ end
16
+
17
+ def formulas
18
+ @formulas ||= if fontist_font?
19
+ Indexes::FilenameIndex.from_yaml.load_index_formulas(File.basename(@path)).map(&:name)
20
+ else
21
+ []
22
+ end
23
+ end
24
+
25
+ def fontist_font?
26
+ @path.start_with?(Fontist.fonts_path.to_s)
27
+ end
28
+ end
29
+ end