fontist 1.8.1 → 1.8.6

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 +5 -5
  2. data/.github/workflows/rspec.yml +2 -2
  3. data/README.md +14 -0
  4. data/fontist.gemspec +7 -5
  5. data/lib/fontist.rb +4 -0
  6. data/lib/fontist/cli.rb +22 -24
  7. data/lib/fontist/errors.rb +51 -2
  8. data/lib/fontist/font.rb +33 -54
  9. data/lib/fontist/font_installer.rb +4 -0
  10. data/lib/fontist/font_path.rb +29 -0
  11. data/lib/fontist/formula.rb +4 -4
  12. data/lib/fontist/import/create_formula.rb +3 -2
  13. data/lib/fontist/import/extractors.rb +4 -0
  14. data/lib/fontist/import/extractors/cpio_extractor.rb +39 -0
  15. data/lib/fontist/import/extractors/gzip_extractor.rb +27 -0
  16. data/lib/fontist/import/extractors/rpm_extractor.rb +45 -0
  17. data/lib/fontist/import/extractors/tar_extractor.rb +47 -0
  18. data/lib/fontist/import/google/skiplist.yml +3 -0
  19. data/lib/fontist/import/recursive_extraction.rb +21 -7
  20. data/lib/fontist/import/sil_import.rb +99 -0
  21. data/lib/fontist/index.rb +4 -65
  22. data/lib/fontist/indexes/base_index.rb +82 -0
  23. data/lib/fontist/indexes/filename_index.rb +19 -0
  24. data/lib/fontist/indexes/font_index.rb +21 -0
  25. data/lib/fontist/indexes/index_formula.rb +36 -0
  26. data/lib/fontist/manifest/install.rb +3 -2
  27. data/lib/fontist/manifest/locations.rb +1 -1
  28. data/lib/fontist/system_font.rb +33 -36
  29. data/lib/fontist/system_index.rb +46 -4
  30. data/lib/fontist/utils.rb +5 -0
  31. data/lib/fontist/utils/cache.rb +12 -4
  32. data/lib/fontist/utils/cpio/cpio.rb +199 -0
  33. data/lib/fontist/utils/cpio_extractor.rb +47 -0
  34. data/lib/fontist/utils/gzip_extractor.rb +24 -0
  35. data/lib/fontist/utils/locking.rb +17 -0
  36. data/lib/fontist/utils/rpm_extractor.rb +37 -0
  37. data/lib/fontist/utils/tar_extractor.rb +61 -0
  38. data/lib/fontist/version.rb +1 -1
  39. metadata +53 -13
  40. data/lib/fontist/index_formula.rb +0 -30
@@ -0,0 +1,47 @@
1
+ module Fontist
2
+ module Utils
3
+ module CpioExtractor
4
+ def cpio_extract(resource)
5
+ file = @downloaded ? resource : download_file(resource)
6
+
7
+ dir = extract_cpio_file(file)
8
+
9
+ largest_file_in_dir(dir)
10
+ end
11
+
12
+ private
13
+
14
+ def extract_cpio_file(archive_path)
15
+ archive_file = File.open(archive_path, "rb")
16
+ dir = Dir.mktmpdir
17
+ extract_cpio_file_to_dir(archive_file, dir)
18
+
19
+ dir
20
+ end
21
+
22
+ def extract_cpio_file_to_dir(archive_file, dir)
23
+ cpio_reader_class.new(archive_file).each do |entry, file|
24
+ path = File.join(dir, entry.name)
25
+ if entry.directory?
26
+ FileUtils.mkdir_p(path)
27
+ else
28
+ File.write(path, file.read, mode: "wb")
29
+ end
30
+ end
31
+ end
32
+
33
+ def cpio_reader_class
34
+ @cpio_reader_class ||= begin
35
+ require "fontist/utils/cpio/cpio"
36
+ CPIO::ASCIIReader
37
+ end
38
+ end
39
+
40
+ def largest_file_in_dir(dir)
41
+ Dir.glob(File.join(dir, "**/*")).max_by do |path|
42
+ File.size(path)
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,24 @@
1
+ module Fontist
2
+ module Utils
3
+ module GzipExtractor
4
+ def gzip_extract(resource)
5
+ file = @downloaded ? resource : download_file(resource)
6
+
7
+ extract_gzip_file(file)
8
+ end
9
+
10
+ private
11
+
12
+ def extract_gzip_file(file)
13
+ Zlib::GzipReader.open(file) do |gz|
14
+ basename = File.basename(file, ".*")
15
+ dir = Dir.mktmpdir
16
+ path = File.join(dir, basename)
17
+ File.write(path, gz.read, mode: "wb")
18
+
19
+ path
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,17 @@
1
+ module Fontist
2
+ module Utils
3
+ module Locking
4
+ def lock(lock_path)
5
+ File.dirname(lock_path).tap do |dir|
6
+ FileUtils.mkdir_p(dir) unless File.exist?(dir)
7
+ end
8
+
9
+ f = File.open(lock_path, File::CREAT)
10
+ f.flock(File::LOCK_EX)
11
+ yield
12
+ ensure
13
+ f.flock(File::LOCK_UN)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,37 @@
1
+ module Fontist
2
+ module Utils
3
+ module RpmExtractor
4
+ def rpm_extract(resource)
5
+ file = download_file(resource)
6
+
7
+ extract_rpm_file(file)
8
+ end
9
+
10
+ private
11
+
12
+ def extract_rpm_file(file)
13
+ rpm = rpm_class.new(file)
14
+ content = rpm.payload.read
15
+ path = rpm_target_path(file.path, rpm.tags)
16
+ File.write(path, content, mode: "wb")
17
+
18
+ path
19
+ end
20
+
21
+ def rpm_class
22
+ @rpm_class ||= begin
23
+ require "arr-pm"
24
+ RPM::File
25
+ end
26
+ end
27
+
28
+ def rpm_target_path(archive, tags)
29
+ basename = File.basename(archive, ".*")
30
+ archive_format = tags[:payloadformat]
31
+ compression_format = tags[:payloadcompressor] == "gzip" ? "gz" : tags[:payloadcompressor]
32
+ filename = basename + "." + archive_format + "." + compression_format
33
+ File.join(Dir.mktmpdir, filename)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,61 @@
1
+ module Fontist
2
+ module Utils
3
+ module TarExtractor
4
+ def tar_extract(resource)
5
+ file = @downloaded ? resource : download_file(resource)
6
+
7
+ dir = extract_tar_file(file)
8
+
9
+ save_fonts(dir)
10
+ end
11
+
12
+ private
13
+
14
+ def extract_tar_file(file)
15
+ archive_file = File.open(file, "rb")
16
+ dir = Dir.mktmpdir
17
+ tar_reader_class.new(archive_file) do |tar|
18
+ tar.each do |tarfile|
19
+ save_tar_file(tarfile, dir)
20
+ end
21
+ end
22
+
23
+ dir
24
+ end
25
+
26
+ def tar_reader_class
27
+ @tar_reader_class ||= begin
28
+ require "rubygems/package"
29
+ Gem::Package::TarReader
30
+ end
31
+ end
32
+
33
+ def save_tar_file(file, dir)
34
+ path = File.join(dir, file.full_name)
35
+
36
+ if file.directory?
37
+ FileUtils.mkdir_p(path)
38
+ else
39
+ File.open(path, "wb") do |f|
40
+ f.print(file.read)
41
+ end
42
+ end
43
+ end
44
+
45
+ def save_fonts(dir)
46
+ Array.new.tap do |fonts_paths|
47
+ Dir.glob(File.join(dir, "**/*")).each do |path|
48
+ filename = File.basename(path)
49
+ next unless font_file?(filename)
50
+
51
+ target_filename = target_filename(filename)
52
+ font_path = fonts_path.join(target_filename).to_s
53
+ FileUtils.mv(path, font_path)
54
+
55
+ fonts_paths << font_path
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -1,3 +1,3 @@
1
1
  module Fontist
2
- VERSION = "1.8.1".freeze
2
+ VERSION = "1.8.6".freeze
3
3
  end
metadata CHANGED
@@ -1,16 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fontist
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.1
4
+ version: 1.8.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
- - Abu Nashir
9
- autorequire:
8
+ autorequire:
10
9
  bindir: exe
11
10
  cert_chain: []
12
- date: 2020-12-20 00:00:00.000000000 Z
11
+ date: 2021-02-05 00:00:00.000000000 Z
13
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
14
27
  - !ruby/object:Gem::Dependency
15
28
  name: down
16
29
  requirement: !ruby/object:Gem::Requirement
@@ -179,6 +192,20 @@ dependencies:
179
192
  - - ">="
180
193
  - !ruby/object:Gem::Version
181
194
  version: '0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: nokogiri
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - "~>"
200
+ - !ruby/object:Gem::Version
201
+ version: '1.0'
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - "~>"
207
+ - !ruby/object:Gem::Version
208
+ version: '1.0'
182
209
  - !ruby/object:Gem::Dependency
183
210
  name: rake
184
211
  requirement: !ruby/object:Gem::Requirement
@@ -263,10 +290,9 @@ dependencies:
263
290
  - - "~>"
264
291
  - !ruby/object:Gem::Version
265
292
  version: '1.0'
266
- description: A libarary find or download fonts
293
+ description: Install openly-licensed fonts on Windows, Linux and Mac!
267
294
  email:
268
- - operations@ribose.com
269
- - abunashir@gmail.com
295
+ - open.source@ribose.com
270
296
  executables:
271
297
  - fontist
272
298
  extensions: []
@@ -290,6 +316,7 @@ files:
290
316
  - lib/fontist/errors.rb
291
317
  - lib/fontist/font.rb
292
318
  - lib/fontist/font_installer.rb
319
+ - lib/fontist/font_path.rb
293
320
  - lib/fontist/fontist_font.rb
294
321
  - lib/fontist/formula.rb
295
322
  - lib/fontist/formula_paths.rb
@@ -299,9 +326,13 @@ files:
299
326
  - lib/fontist/import/create_formula.rb
300
327
  - lib/fontist/import/extractors.rb
301
328
  - lib/fontist/import/extractors/cab_extractor.rb
329
+ - lib/fontist/import/extractors/cpio_extractor.rb
302
330
  - lib/fontist/import/extractors/extractor.rb
331
+ - lib/fontist/import/extractors/gzip_extractor.rb
303
332
  - lib/fontist/import/extractors/ole_extractor.rb
333
+ - lib/fontist/import/extractors/rpm_extractor.rb
304
334
  - lib/fontist/import/extractors/seven_zip_extractor.rb
335
+ - lib/fontist/import/extractors/tar_extractor.rb
305
336
  - lib/fontist/import/extractors/zip_extractor.rb
306
337
  - lib/fontist/import/files/collection_file.rb
307
338
  - lib/fontist/import/files/file_requirement.rb
@@ -325,10 +356,14 @@ files:
325
356
  - lib/fontist/import/otfinfo/template.erb
326
357
  - lib/fontist/import/otfinfo_generate.rb
327
358
  - lib/fontist/import/recursive_extraction.rb
359
+ - lib/fontist/import/sil_import.rb
328
360
  - lib/fontist/import/template_helper.rb
329
361
  - lib/fontist/import/text_helper.rb
330
362
  - lib/fontist/index.rb
331
- - lib/fontist/index_formula.rb
363
+ - lib/fontist/indexes/base_index.rb
364
+ - lib/fontist/indexes/filename_index.rb
365
+ - lib/fontist/indexes/font_index.rb
366
+ - lib/fontist/indexes/index_formula.rb
332
367
  - lib/fontist/manifest.rb
333
368
  - lib/fontist/manifest/install.rb
334
369
  - lib/fontist/manifest/locations.rb
@@ -337,14 +372,20 @@ files:
337
372
  - lib/fontist/system_index.rb
338
373
  - lib/fontist/utils.rb
339
374
  - lib/fontist/utils/cache.rb
375
+ - lib/fontist/utils/cpio/cpio.rb
376
+ - lib/fontist/utils/cpio_extractor.rb
340
377
  - lib/fontist/utils/downloader.rb
341
378
  - lib/fontist/utils/dsl.rb
342
379
  - lib/fontist/utils/dsl/collection_font.rb
343
380
  - lib/fontist/utils/dsl/font.rb
344
381
  - lib/fontist/utils/exe_extractor.rb
382
+ - lib/fontist/utils/gzip_extractor.rb
383
+ - lib/fontist/utils/locking.rb
345
384
  - lib/fontist/utils/msi_extractor.rb
385
+ - lib/fontist/utils/rpm_extractor.rb
346
386
  - lib/fontist/utils/seven_zip_extractor.rb
347
387
  - lib/fontist/utils/system.rb
388
+ - lib/fontist/utils/tar_extractor.rb
348
389
  - lib/fontist/utils/ui.rb
349
390
  - lib/fontist/utils/zip_extractor.rb
350
391
  - lib/fontist/version.rb
@@ -355,7 +396,7 @@ metadata:
355
396
  homepage_uri: https://github.com/fontist/fontist
356
397
  source_code_uri: https://github.com/fontist/fontist
357
398
  changelog_uri: https://github.com/fontist/fontist
358
- post_install_message: Please run `fontist update` to fetch formulas
399
+ post_install_message: Please run `fontist update` to fetch formulas.
359
400
  rdoc_options: []
360
401
  require_paths:
361
402
  - lib
@@ -370,9 +411,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
370
411
  - !ruby/object:Gem::Version
371
412
  version: '0'
372
413
  requirements: []
373
- rubyforge_project:
374
- rubygems_version: 2.6.14.4
375
- signing_key:
414
+ rubygems_version: 3.0.3
415
+ signing_key:
376
416
  specification_version: 4
377
- summary: A libarary find or download fonts
417
+ summary: Install openly-licensed fonts on Windows, Linux and Mac!
378
418
  test_files: []
@@ -1,30 +0,0 @@
1
- module Fontist
2
- class IndexFormula
3
- def initialize(path)
4
- @path = path
5
- end
6
-
7
- def to_s
8
- normalized
9
- end
10
-
11
- def to_full
12
- Formula.new_from_file(full_path)
13
- end
14
-
15
- def ==(other)
16
- to_s == other.to_s
17
- end
18
-
19
- private
20
-
21
- def normalized
22
- escaped = Regexp.escape(Fontist.formulas_path.to_s + "/")
23
- @path.sub(Regexp.new("^" + escaped), "")
24
- end
25
-
26
- def full_path
27
- Fontist.formulas_path.join(normalized).to_s
28
- end
29
- end
30
- end