fontist 1.8.3 → 1.8.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/fontist.gemspec +6 -5
- data/lib/fontist/errors.rb +1 -0
- data/lib/fontist/font_installer.rb +4 -0
- data/lib/fontist/import/extractors.rb +4 -0
- data/lib/fontist/import/extractors/cpio_extractor.rb +39 -0
- data/lib/fontist/import/extractors/gzip_extractor.rb +27 -0
- data/lib/fontist/import/extractors/rpm_extractor.rb +45 -0
- data/lib/fontist/import/extractors/tar_extractor.rb +47 -0
- data/lib/fontist/import/recursive_extraction.rb +20 -6
- data/lib/fontist/utils.rb +4 -0
- data/lib/fontist/utils/cache.rb +1 -1
- data/lib/fontist/utils/cpio/cpio.rb +199 -0
- data/lib/fontist/utils/cpio_extractor.rb +47 -0
- data/lib/fontist/utils/gzip_extractor.rb +24 -0
- data/lib/fontist/utils/rpm_extractor.rb +37 -0
- data/lib/fontist/utils/tar_extractor.rb +61 -0
- data/lib/fontist/version.rb +1 -1
- metadata +31 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e12ad24d94f6220992c66f06c21872135932b1b64f7ae17c7aa414c2f80f12ad
|
4
|
+
data.tar.gz: 29665a7556a8fbeda7449616c688a90e694b8060c7f2b8158abcc41e049579c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92b8942a88a3f02c57fd9840060c8ba333f0378611477bf1ff9435296792a4b79f97616da3520ea8d6fbe1088498c6d15d9c885c02e740fdc4bc26811988b176
|
7
|
+
data.tar.gz: 41aab015006c2109db2a52ea6ace23aeaaa571e5153559c53e327c448be4684189c7d72d5785811ecf505b124a48fa5016f5cfe62cd0946f92d0d6aab6d9b870
|
data/fontist.gemspec
CHANGED
@@ -5,15 +5,15 @@ require "fontist/version"
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "fontist"
|
7
7
|
spec.version = Fontist::VERSION
|
8
|
-
spec.authors = ["Ribose Inc."
|
9
|
-
spec.email = ["
|
8
|
+
spec.authors = ["Ribose Inc."]
|
9
|
+
spec.email = ["open.source@ribose.com"]
|
10
10
|
|
11
|
-
spec.summary = %q{
|
12
|
-
spec.description = %q{
|
11
|
+
spec.summary = %q{Install openly-licensed fonts on Windows, Linux and Mac!}
|
12
|
+
spec.description = %q{Install openly-licensed fonts on Windows, Linux and Mac!}
|
13
13
|
spec.homepage = "https://github.com/fontist/fontist"
|
14
14
|
spec.license = "BSD-2-Clause"
|
15
15
|
|
16
|
-
spec.post_install_message = "Please run `fontist update` to fetch formulas"
|
16
|
+
spec.post_install_message = "Please run `fontist update` to fetch formulas."
|
17
17
|
|
18
18
|
spec.metadata["homepage_uri"] = spec.homepage
|
19
19
|
spec.metadata["source_code_uri"] = "https://github.com/fontist/fontist"
|
@@ -27,6 +27,7 @@ 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"
|
30
31
|
spec.add_runtime_dependency "down", "~> 5.0"
|
31
32
|
spec.add_runtime_dependency "libmspack", "~> 0.1.0"
|
32
33
|
spec.add_runtime_dependency "rubyzip", "~> 2.3.0"
|
data/lib/fontist/errors.rb
CHANGED
@@ -14,6 +14,7 @@ module Fontist
|
|
14
14
|
class TamperedFileError < GeneralError; end
|
15
15
|
class TimeoutError < GeneralError; end
|
16
16
|
class UnknownFontTypeError < GeneralError; end
|
17
|
+
class UnknownArchiveError < GeneralError; end
|
17
18
|
|
18
19
|
class FontError < GeneralError
|
19
20
|
attr_reader :font, :style
|
@@ -6,6 +6,10 @@ module Fontist
|
|
6
6
|
include Utils::ExeExtractor
|
7
7
|
include Utils::MsiExtractor
|
8
8
|
include Utils::SevenZipExtractor
|
9
|
+
include Utils::RpmExtractor
|
10
|
+
include Utils::GzipExtractor
|
11
|
+
include Utils::CpioExtractor
|
12
|
+
include Utils::TarExtractor
|
9
13
|
|
10
14
|
def initialize(formula)
|
11
15
|
@formula = formula
|
@@ -3,3 +3,7 @@ require_relative "extractors/zip_extractor"
|
|
3
3
|
require_relative "extractors/ole_extractor"
|
4
4
|
require_relative "extractors/seven_zip_extractor"
|
5
5
|
require_relative "extractors/cab_extractor"
|
6
|
+
require_relative "extractors/rpm_extractor"
|
7
|
+
require_relative "extractors/gzip_extractor"
|
8
|
+
require_relative "extractors/cpio_extractor"
|
9
|
+
require_relative "extractors/tar_extractor"
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Fontist
|
2
|
+
module Import
|
3
|
+
module Extractors
|
4
|
+
class CpioExtractor < Extractor
|
5
|
+
def extract
|
6
|
+
dir = Dir.mktmpdir
|
7
|
+
extract_cpio(@archive, dir)
|
8
|
+
dir
|
9
|
+
end
|
10
|
+
|
11
|
+
def format
|
12
|
+
"cpio"
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def extract_cpio(archive, dir)
|
18
|
+
archive_file = File.open(archive, "rb")
|
19
|
+
|
20
|
+
reader_class.new(archive_file).each do |entry, file|
|
21
|
+
path = File.join(dir, entry.name)
|
22
|
+
if entry.directory?
|
23
|
+
FileUtils.mkdir_p(path)
|
24
|
+
else
|
25
|
+
File.write(path, file.read)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def reader_class
|
31
|
+
@reader_class ||= begin
|
32
|
+
require "fontist/utils/cpio/cpio"
|
33
|
+
CPIO::ASCIIReader
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Fontist
|
2
|
+
module Import
|
3
|
+
module Extractors
|
4
|
+
class GzipExtractor < Extractor
|
5
|
+
def extract
|
6
|
+
dir = Dir.mktmpdir
|
7
|
+
extract_gzip(@archive, dir)
|
8
|
+
dir
|
9
|
+
end
|
10
|
+
|
11
|
+
def format
|
12
|
+
"gzip"
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def extract_gzip(archive, dir)
|
18
|
+
Zlib::GzipReader.open(archive) do |gz|
|
19
|
+
basename = File.basename(archive, ".*")
|
20
|
+
path = File.join(dir, basename)
|
21
|
+
File.write(path, gz.read)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Fontist
|
2
|
+
module Import
|
3
|
+
module Extractors
|
4
|
+
class RpmExtractor < Extractor
|
5
|
+
def extract
|
6
|
+
dir = Dir.mktmpdir
|
7
|
+
extract_rpm(@archive, dir)
|
8
|
+
dir
|
9
|
+
end
|
10
|
+
|
11
|
+
def format
|
12
|
+
"rpm"
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def extract_rpm(archive, dir)
|
18
|
+
file = File.open(archive, "rb")
|
19
|
+
rpm = rpm_class.new(file)
|
20
|
+
content = rpm.payload.read
|
21
|
+
path = target_path(archive, rpm.tags, dir)
|
22
|
+
|
23
|
+
File.write(path, content)
|
24
|
+
ensure
|
25
|
+
file.close
|
26
|
+
end
|
27
|
+
|
28
|
+
def rpm_class
|
29
|
+
@rpm_class ||= begin
|
30
|
+
require "arr-pm"
|
31
|
+
RPM::File
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def target_path(archive, tags, dir)
|
36
|
+
archive_format = tags[:payloadformat]
|
37
|
+
compression_format = tags[:payloadcompressor] == "gzip" ? "gz" : tags[:payloadcompressor]
|
38
|
+
basename = File.basename(archive, ".*")
|
39
|
+
filename = basename + "." + archive_format + "." + compression_format
|
40
|
+
File.join(dir, filename)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Fontist
|
2
|
+
module Import
|
3
|
+
module Extractors
|
4
|
+
class TarExtractor < Extractor
|
5
|
+
def extract
|
6
|
+
dir = Dir.mktmpdir
|
7
|
+
extract_tar(@archive, dir)
|
8
|
+
dir
|
9
|
+
end
|
10
|
+
|
11
|
+
def format
|
12
|
+
"tar"
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def extract_tar(archive, dir)
|
18
|
+
archive_file = File.open(archive, "rb")
|
19
|
+
reader_class.new(archive_file) do |tar|
|
20
|
+
tar.each do |tarfile|
|
21
|
+
save_tar_file(tarfile, dir)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def reader_class
|
27
|
+
@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
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -19,7 +19,7 @@ module Fontist
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def extension
|
22
|
-
|
22
|
+
fetch_extension(@archive)
|
23
23
|
end
|
24
24
|
|
25
25
|
def font_files
|
@@ -44,6 +44,10 @@ module Fontist
|
|
44
44
|
|
45
45
|
private
|
46
46
|
|
47
|
+
def fetch_extension(file)
|
48
|
+
File.extname(filename(file)).sub(/^\./, "")
|
49
|
+
end
|
50
|
+
|
47
51
|
def filename(file)
|
48
52
|
if file.respond_to?(:original_filename)
|
49
53
|
file.original_filename
|
@@ -82,16 +86,26 @@ module Fontist
|
|
82
86
|
|
83
87
|
# rubocop:disable Metrics/MethodLength
|
84
88
|
def choose_extractor(archive)
|
85
|
-
case
|
86
|
-
when
|
89
|
+
case fetch_extension(archive).downcase
|
90
|
+
when "msi"
|
87
91
|
Extractors::OleExtractor.new(archive)
|
88
|
-
when
|
92
|
+
when "cab"
|
89
93
|
Extractors::CabExtractor.new(archive)
|
90
|
-
when
|
94
|
+
when "exe"
|
91
95
|
extractor = Extractors::SevenZipExtractor.new(archive)
|
92
96
|
extractor.try ? extractor : Extractors::CabExtractor.new(archive)
|
93
|
-
|
97
|
+
when "zip"
|
94
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)}`."
|
95
109
|
end
|
96
110
|
end
|
97
111
|
# rubocop:enable Metrics/MethodLength
|
data/lib/fontist/utils.rb
CHANGED
@@ -9,6 +9,10 @@ require "fontist/utils/zip_extractor"
|
|
9
9
|
require "fontist/utils/exe_extractor"
|
10
10
|
require "fontist/utils/msi_extractor"
|
11
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"
|
12
16
|
|
13
17
|
module Fontist
|
14
18
|
module Utils
|
data/lib/fontist/utils/cache.rb
CHANGED
@@ -0,0 +1,199 @@
|
|
1
|
+
# code is obtained from https://github.com/jordansissel/ruby-arr-pm/blob/8071591173ebb90dea27d5acfdde69a37dcb2744/cpio.rb
|
2
|
+
# rubocop:disable all
|
3
|
+
class BoundedIO
|
4
|
+
attr_reader :length
|
5
|
+
attr_reader :remaining
|
6
|
+
|
7
|
+
def initialize(io, length, &eof_callback)
|
8
|
+
@io = io
|
9
|
+
@length = length
|
10
|
+
@remaining = length
|
11
|
+
|
12
|
+
@eof_callback = eof_callback
|
13
|
+
@eof = false
|
14
|
+
end
|
15
|
+
|
16
|
+
def read(size=nil)
|
17
|
+
return nil if eof?
|
18
|
+
size = @remaining if size.nil?
|
19
|
+
data = @io.read(size)
|
20
|
+
@remaining -= data.bytesize
|
21
|
+
eof?
|
22
|
+
data
|
23
|
+
end
|
24
|
+
|
25
|
+
def sysread(size)
|
26
|
+
raise EOFError, "end of file reached" if eof?
|
27
|
+
read(size)
|
28
|
+
end
|
29
|
+
|
30
|
+
def eof?
|
31
|
+
return false if @remaining > 0
|
32
|
+
return @eof if @eof
|
33
|
+
|
34
|
+
@eof_callback.call
|
35
|
+
@eof = true
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
module CPIO
|
40
|
+
FIELDS = [
|
41
|
+
:magic, :ino, :mode, :uid, :gid, :nlink, :mtime, :filesize, :devmajor,
|
42
|
+
:devminor, :rdevmajor, :rdevminor, :namesize, :check
|
43
|
+
]
|
44
|
+
end
|
45
|
+
|
46
|
+
class CPIO::ASCIIReader
|
47
|
+
FIELD_SIZES = {
|
48
|
+
:magic => 6,
|
49
|
+
:ino => 8,
|
50
|
+
:mode => 8,
|
51
|
+
:uid => 8,
|
52
|
+
:gid => 8,
|
53
|
+
:nlink => 8,
|
54
|
+
:mtime => 8,
|
55
|
+
:filesize => 8,
|
56
|
+
:devmajor => 8,
|
57
|
+
:devminor => 8,
|
58
|
+
:rdevmajor => 8,
|
59
|
+
:rdevminor => 8,
|
60
|
+
:namesize => 8,
|
61
|
+
:check => 8
|
62
|
+
}
|
63
|
+
HEADER_LENGTH = FIELD_SIZES.reduce(0) { |m, (_, v)| m + v }
|
64
|
+
HEADER_PACK = FIELD_SIZES.collect { |_, v| "A#{v}" }.join
|
65
|
+
|
66
|
+
FIELD_ORDER = [
|
67
|
+
:magic, :ino, :mode, :uid, :gid, :nlink, :mtime, :filesize, :devmajor,
|
68
|
+
:devminor, :rdevmajor, :rdevminor, :namesize, :check
|
69
|
+
]
|
70
|
+
|
71
|
+
def initialize(io)
|
72
|
+
@io = io
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
def io
|
78
|
+
@io
|
79
|
+
end
|
80
|
+
|
81
|
+
def each(&block)
|
82
|
+
while true
|
83
|
+
entry = read
|
84
|
+
break if entry.nil?
|
85
|
+
# The CPIO format has the end-of-stream marker as a file called "TRAILER!!!"
|
86
|
+
break if entry.name == "TRAILER!!!"
|
87
|
+
block.call(entry, entry.file)
|
88
|
+
verify_correct_read(entry) unless entry.directory?
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def verify_correct_read(entry)
|
93
|
+
# Read and throw away the whole file if not read at all.
|
94
|
+
entry.file.tap do |file|
|
95
|
+
if file.nil? || file.remaining == 0
|
96
|
+
# All OK! :)
|
97
|
+
elsif file.remaining == file.length
|
98
|
+
file.read(16384) while !file.eof?
|
99
|
+
else
|
100
|
+
# The file was only partially read? This should be an error by the
|
101
|
+
# user.
|
102
|
+
consumed = file.length - file.remaining
|
103
|
+
raise BadState, "Only #{consumed} bytes were read of the #{file.length} byte file: #{entry.name}"
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def read
|
109
|
+
entry = CPIOEntry.new
|
110
|
+
header = io.read(HEADER_LENGTH)
|
111
|
+
return nil if header.nil?
|
112
|
+
FIELD_ORDER.zip(header.unpack(HEADER_PACK)).each do |field, value|
|
113
|
+
entry.send("#{field}=", value.to_i(16))
|
114
|
+
end
|
115
|
+
|
116
|
+
entry.validate
|
117
|
+
entry.mtime = Time.at(entry.mtime)
|
118
|
+
read_name(entry, @io)
|
119
|
+
read_file(entry, @io)
|
120
|
+
entry
|
121
|
+
end
|
122
|
+
|
123
|
+
def read_name(entry, io)
|
124
|
+
entry.name = io.read(entry.namesize - 1) # - 1 for null terminator
|
125
|
+
nul = io.read(1)
|
126
|
+
raise ArgumentError, "Corrupt CPIO or bug? Name null terminator was not null: #{nul.inspect}" if nul != "\0"
|
127
|
+
padding_data = io.read(padding_name(entry))
|
128
|
+
# Padding should be all null bytes
|
129
|
+
if padding_data != ("\0" * padding_data.bytesize)
|
130
|
+
raise ArgumentError, "Corrupt CPIO or bug? Name null padding was #{padding_name(entry)} bytes: #{padding_data.inspect}"
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def read_file(entry, io)
|
135
|
+
if entry.directory?
|
136
|
+
entry.file = nil
|
137
|
+
#read_file_padding(entry, io)
|
138
|
+
nil
|
139
|
+
else
|
140
|
+
entry.file = BoundedIO.new(io, entry.filesize) do
|
141
|
+
read_file_padding(entry, io)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
def read_file_padding(entry, io)
|
147
|
+
padding_data = io.read(padding_file(entry))
|
148
|
+
if padding_data != ("\0" * padding_data.bytesize)
|
149
|
+
raise ArgumentError, "Corrupt CPIO or bug? File null padding was #{padding_file(entry)} bytes: #{padding_data.inspect}"
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
def padding_name(entry)
|
154
|
+
# name padding is padding up to a multiple of 4 after header+namesize
|
155
|
+
-(HEADER_LENGTH + entry.namesize) % 4
|
156
|
+
end
|
157
|
+
|
158
|
+
def padding_file(entry)
|
159
|
+
(-(HEADER_LENGTH + entry.filesize + 2) % 4)
|
160
|
+
end
|
161
|
+
public(:each)
|
162
|
+
end
|
163
|
+
|
164
|
+
class CPIOEntry
|
165
|
+
CPIO::FIELDS.each do |field|
|
166
|
+
attr_accessor field
|
167
|
+
end
|
168
|
+
|
169
|
+
attr_accessor :name
|
170
|
+
attr_accessor :file
|
171
|
+
|
172
|
+
DIRECTORY_FLAG = 0040000
|
173
|
+
|
174
|
+
def validate
|
175
|
+
raise "Invalid magic #{magic.inspect}" if magic != 0x070701
|
176
|
+
raise "Invalid ino #{ino.inspect}" if ino < 0
|
177
|
+
raise "Invalid mode #{mode.inspect}" if mode < 0
|
178
|
+
raise "Invalid uid #{uid.inspect}" if uid < 0
|
179
|
+
raise "Invalid gid #{gid.inspect}" if gid < 0
|
180
|
+
raise "Invalid nlink #{nlink.inspect}" if nlink < 0
|
181
|
+
raise "Invalid mtime #{mtime.inspect}" if mtime < 0
|
182
|
+
raise "Invalid filesize #{filesize.inspect}" if filesize < 0
|
183
|
+
raise "Invalid devmajor #{devmajor.inspect}" if devmajor < 0
|
184
|
+
raise "Invalid devminor #{devminor.inspect}" if devminor < 0
|
185
|
+
raise "Invalid rdevmajor #{rdevmajor.inspect}" if rdevmajor < 0
|
186
|
+
raise "Invalid rdevminor #{rdevminor.inspect}" if rdevminor < 0
|
187
|
+
raise "Invalid namesize #{namesize.inspect}" if namesize < 0
|
188
|
+
raise "Invalid check #{check.inspect}" if check < 0
|
189
|
+
end # def validate
|
190
|
+
|
191
|
+
def read(*args)
|
192
|
+
return nil if directory?
|
193
|
+
file.read(*args)
|
194
|
+
end
|
195
|
+
|
196
|
+
def directory?
|
197
|
+
mode & DIRECTORY_FLAG > 0
|
198
|
+
end
|
199
|
+
end
|
@@ -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,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
|
data/lib/fontist/version.rb
CHANGED
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.
|
4
|
+
version: 1.8.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
|
-
|
9
|
-
autorequire:
|
8
|
+
autorequire:
|
10
9
|
bindir: exe
|
11
10
|
cert_chain: []
|
12
|
-
date: 2021-01-
|
11
|
+
date: 2021-01-10 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
|
@@ -277,10 +290,9 @@ dependencies:
|
|
277
290
|
- - "~>"
|
278
291
|
- !ruby/object:Gem::Version
|
279
292
|
version: '1.0'
|
280
|
-
description:
|
293
|
+
description: Install openly-licensed fonts on Windows, Linux and Mac!
|
281
294
|
email:
|
282
|
-
-
|
283
|
-
- abunashir@gmail.com
|
295
|
+
- open.source@ribose.com
|
284
296
|
executables:
|
285
297
|
- fontist
|
286
298
|
extensions: []
|
@@ -313,9 +325,13 @@ files:
|
|
313
325
|
- lib/fontist/import/create_formula.rb
|
314
326
|
- lib/fontist/import/extractors.rb
|
315
327
|
- lib/fontist/import/extractors/cab_extractor.rb
|
328
|
+
- lib/fontist/import/extractors/cpio_extractor.rb
|
316
329
|
- lib/fontist/import/extractors/extractor.rb
|
330
|
+
- lib/fontist/import/extractors/gzip_extractor.rb
|
317
331
|
- lib/fontist/import/extractors/ole_extractor.rb
|
332
|
+
- lib/fontist/import/extractors/rpm_extractor.rb
|
318
333
|
- lib/fontist/import/extractors/seven_zip_extractor.rb
|
334
|
+
- lib/fontist/import/extractors/tar_extractor.rb
|
319
335
|
- lib/fontist/import/extractors/zip_extractor.rb
|
320
336
|
- lib/fontist/import/files/collection_file.rb
|
321
337
|
- lib/fontist/import/files/file_requirement.rb
|
@@ -352,15 +368,20 @@ files:
|
|
352
368
|
- lib/fontist/system_index.rb
|
353
369
|
- lib/fontist/utils.rb
|
354
370
|
- lib/fontist/utils/cache.rb
|
371
|
+
- lib/fontist/utils/cpio/cpio.rb
|
372
|
+
- lib/fontist/utils/cpio_extractor.rb
|
355
373
|
- lib/fontist/utils/downloader.rb
|
356
374
|
- lib/fontist/utils/dsl.rb
|
357
375
|
- lib/fontist/utils/dsl/collection_font.rb
|
358
376
|
- lib/fontist/utils/dsl/font.rb
|
359
377
|
- lib/fontist/utils/exe_extractor.rb
|
378
|
+
- lib/fontist/utils/gzip_extractor.rb
|
360
379
|
- lib/fontist/utils/locking.rb
|
361
380
|
- lib/fontist/utils/msi_extractor.rb
|
381
|
+
- lib/fontist/utils/rpm_extractor.rb
|
362
382
|
- lib/fontist/utils/seven_zip_extractor.rb
|
363
383
|
- lib/fontist/utils/system.rb
|
384
|
+
- lib/fontist/utils/tar_extractor.rb
|
364
385
|
- lib/fontist/utils/ui.rb
|
365
386
|
- lib/fontist/utils/zip_extractor.rb
|
366
387
|
- lib/fontist/version.rb
|
@@ -371,7 +392,7 @@ metadata:
|
|
371
392
|
homepage_uri: https://github.com/fontist/fontist
|
372
393
|
source_code_uri: https://github.com/fontist/fontist
|
373
394
|
changelog_uri: https://github.com/fontist/fontist
|
374
|
-
post_install_message: Please run `fontist update` to fetch formulas
|
395
|
+
post_install_message: Please run `fontist update` to fetch formulas.
|
375
396
|
rdoc_options: []
|
376
397
|
require_paths:
|
377
398
|
- lib
|
@@ -387,7 +408,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
387
408
|
version: '0'
|
388
409
|
requirements: []
|
389
410
|
rubygems_version: 3.0.3
|
390
|
-
signing_key:
|
411
|
+
signing_key:
|
391
412
|
specification_version: 4
|
392
|
-
summary:
|
413
|
+
summary: Install openly-licensed fonts on Windows, Linux and Mac!
|
393
414
|
test_files: []
|