ptools 1.2.6 → 1.2.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES +8 -0
- data/MANIFEST +3 -0
- data/lib/ptools.rb +55 -21
- data/ptools.gemspec +1 -1
- data/test/test_constants.rb +1 -1
- data/test/test_nlconvert.rb +11 -0
- data/test/test_which.rb +16 -0
- metadata +11 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19b48052d410d086d24c61ef25da0b3e87b32c00
|
4
|
+
data.tar.gz: 49b572916684c747255775890a6e7188f286eced
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70977a568a82dd6885804f7b47391f096da6b66b965944838c85cb47b6eba501bec70e0bbe69ea65a02621707532a3bf24846dbd4011a9ef66b8dc5a03b63f58
|
7
|
+
data.tar.gz: f81220180763b1fd1157712b16942c0fc5e588d3795b6be1fbaf7945201677333593f45dce298156e947434f18e1cfe7c990bbccd5edc3eac83a30fce56fe491
|
data/CHANGES
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
== 1.2.7 - 6-Dec-2014
|
2
|
+
* File.which now expands ~ for paths. Thanks go to dg-vrnetze for the patch.
|
3
|
+
* Use /dev/null for cygwin instead of NUL.
|
4
|
+
* Use mv instead of cp in the nl_convert method.
|
5
|
+
* Solaris now handled explicitly in nl_convert, and OSX now considered Unix.
|
6
|
+
* Modified the binary? method to check 4096 bytes at most.
|
7
|
+
* Thanks to Matt Hoyle for many of the changes implemented in this release.
|
8
|
+
|
1
9
|
== 1.2.6 - 14-Jul-2014
|
2
10
|
* Updated the png? and jpg? methods so they explicitly specify the
|
3
11
|
offset argument so that it works with 1.9.2 and earlier. Thanks go to
|
data/MANIFEST
CHANGED
data/lib/ptools.rb
CHANGED
@@ -3,7 +3,7 @@ require 'win32/file' if File::ALT_SEPARATOR
|
|
3
3
|
|
4
4
|
class File
|
5
5
|
# The version of the ptools library.
|
6
|
-
PTOOLS_VERSION = '1.2.
|
6
|
+
PTOOLS_VERSION = '1.2.7'
|
7
7
|
|
8
8
|
# :stopdoc:
|
9
9
|
|
@@ -40,7 +40,7 @@ class File
|
|
40
40
|
#
|
41
41
|
def self.image?(file)
|
42
42
|
bool = IMAGE_EXT.include?(File.extname(file).downcase) # Match ext
|
43
|
-
bool = bmp?(file) || jpg?(file) || png?(file) || gif?(file) # Check data
|
43
|
+
bool = bmp?(file) || jpg?(file) || png?(file) || gif?(file) || tiff?(file) # Check data
|
44
44
|
bool
|
45
45
|
end
|
46
46
|
|
@@ -59,7 +59,7 @@ class File
|
|
59
59
|
#
|
60
60
|
def self.null
|
61
61
|
case RbConfig::CONFIG['host_os']
|
62
|
-
when /mswin|win32|msdos|
|
62
|
+
when /mswin|win32|msdos|mingw|windows/i
|
63
63
|
'NUL'
|
64
64
|
when /amiga/i
|
65
65
|
'NIL:'
|
@@ -77,7 +77,7 @@ class File
|
|
77
77
|
# Returns whether or not +file+ is a binary non-image file, i.e. executable,
|
78
78
|
# shared object, ect. Note that this is NOT guaranteed to be 100% accurate.
|
79
79
|
# It performs a "best guess" based on a simple test of the first
|
80
|
-
# +File.blksize+ characters.
|
80
|
+
# +File.blksize+ characters, or 4096, whichever is smaller.
|
81
81
|
#
|
82
82
|
# Example:
|
83
83
|
#
|
@@ -89,7 +89,9 @@ class File
|
|
89
89
|
#
|
90
90
|
def self.binary?(file)
|
91
91
|
return false if image?(file)
|
92
|
-
|
92
|
+
bytes = File.stat(file).blksize
|
93
|
+
bytes = 4096 if bytes > 4096
|
94
|
+
s = (File.read(file, bytes) || "")
|
93
95
|
s = s.encode('US-ASCII', :undef => :replace).split(//)
|
94
96
|
((s.size - s.grep(" ".."~").size) / s.size.to_f) > 0.30
|
95
97
|
end
|
@@ -125,6 +127,8 @@ class File
|
|
125
127
|
|
126
128
|
# Iterate over each path glob the dir + program.
|
127
129
|
path.split(File::PATH_SEPARATOR).each{ |dir|
|
130
|
+
dir = File.expand_path(dir)
|
131
|
+
|
128
132
|
next unless File.exist?(dir) # In case of bogus second argument
|
129
133
|
file = File.join(dir, program)
|
130
134
|
|
@@ -269,28 +273,22 @@ class File
|
|
269
273
|
# 'dos2unix'. The possible values for +platform+ include:
|
270
274
|
#
|
271
275
|
# * MS Windows -> dos, windows, win32, mswin
|
272
|
-
# * Unix/BSD -> unix, linux, bsd
|
273
|
-
# * Mac -> mac, macintosh, apple
|
276
|
+
# * Unix/BSD -> unix, linux, bsd, osx, darwin, sunos, solaris
|
277
|
+
# * Mac -> mac, macintosh, apple
|
278
|
+
#
|
279
|
+
# You may also specify 'local', in which case your CONFIG['host_os'] value
|
280
|
+
# will be used. This is the default.
|
274
281
|
#
|
275
|
-
# Note that this method is only valid for an ftype of "file".
|
276
|
-
# TypeError will be raised.
|
282
|
+
# Note that this method is only valid for an ftype of "file". Otherwise a
|
283
|
+
# TypeError will be raised. If an invalid format value is received, an
|
277
284
|
# ArgumentError is raised.
|
278
285
|
#
|
279
|
-
def self.nl_convert(old_file, new_file = old_file, platform = '
|
286
|
+
def self.nl_convert(old_file, new_file = old_file, platform = 'local')
|
280
287
|
unless File::Stat.new(old_file).file?
|
281
288
|
raise ArgumentError, 'Only valid for plain text files'
|
282
289
|
end
|
283
290
|
|
284
|
-
|
285
|
-
when /dos|windows|win32|mswin|cygwin|mingw/i
|
286
|
-
format = "\cM\cJ"
|
287
|
-
when /unix|linux|bsd/i
|
288
|
-
format = "\cJ"
|
289
|
-
when /mac|apple|macintosh|osx/i
|
290
|
-
format = "\cM"
|
291
|
-
else
|
292
|
-
raise ArgumentError, "Invalid platform string"
|
293
|
-
end
|
291
|
+
format = nl_for_platform(platform)
|
294
292
|
|
295
293
|
orig = $\ # $OUTPUT_RECORD_SEPARATOR
|
296
294
|
$\ = format
|
@@ -313,7 +311,7 @@ class File
|
|
313
311
|
end
|
314
312
|
|
315
313
|
File.delete(old_file)
|
316
|
-
FileUtils.
|
314
|
+
FileUtils.mv(tf.path, old_file)
|
317
315
|
else
|
318
316
|
begin
|
319
317
|
nf = File.new(new_file, 'w')
|
@@ -413,6 +411,21 @@ class File
|
|
413
411
|
|
414
412
|
private
|
415
413
|
|
414
|
+
def self.nl_for_platform(platform)
|
415
|
+
platform = RbConfig::CONFIG["host_os"] if platform == 'local'
|
416
|
+
|
417
|
+
case platform
|
418
|
+
when /dos|windows|win32|mswin|mingw/i
|
419
|
+
return "\cM\cJ"
|
420
|
+
when /unix|linux|bsd|cygwin|osx|darwin|solaris|sunos/i
|
421
|
+
return "\cJ"
|
422
|
+
when /mac|apple|macintosh/i
|
423
|
+
return "\cM"
|
424
|
+
else
|
425
|
+
raise ArgumentError, "Invalid platform string"
|
426
|
+
end
|
427
|
+
end
|
428
|
+
|
416
429
|
def self.bmp?(file)
|
417
430
|
IO.read(file, 3) == "BM6"
|
418
431
|
end
|
@@ -428,4 +441,25 @@ class File
|
|
428
441
|
def self.gif?(file)
|
429
442
|
['GIF89a', 'GIF97a'].include?(IO.read(file, 6))
|
430
443
|
end
|
444
|
+
|
445
|
+
def self.tiff?(file)
|
446
|
+
return false if File.size(file) < 12
|
447
|
+
|
448
|
+
bytes = IO.read(file, 4)
|
449
|
+
|
450
|
+
# II is Intel, MM is Motorola
|
451
|
+
if bytes[0..1] != 'II'&& bytes[0..1] != 'MM'
|
452
|
+
return false
|
453
|
+
end
|
454
|
+
|
455
|
+
if bytes[0..1] == 'II' && bytes[2..3].ord != 42
|
456
|
+
return false
|
457
|
+
end
|
458
|
+
|
459
|
+
if bytes[0..1] == 'MM' && bytes[2..3].reverse.ord != 42
|
460
|
+
return false
|
461
|
+
end
|
462
|
+
|
463
|
+
true
|
464
|
+
end
|
431
465
|
end
|
data/ptools.gemspec
CHANGED
data/test/test_constants.rb
CHANGED
@@ -15,7 +15,7 @@ class TC_Ptools_Constants < Test::Unit::TestCase
|
|
15
15
|
end
|
16
16
|
|
17
17
|
test "PTOOLS_VERSION constant is set to expected value" do
|
18
|
-
assert_equal('1.2.
|
18
|
+
assert_equal('1.2.7', File::PTOOLS_VERSION)
|
19
19
|
end
|
20
20
|
|
21
21
|
test "IMAGE_EXT constant is set to array of values" do
|
data/test/test_nlconvert.rb
CHANGED
@@ -25,6 +25,17 @@ class TC_Ptools_NLConvert < Test::Unit::TestCase
|
|
25
25
|
@unix_file = 'nix_test_file.txt'
|
26
26
|
end
|
27
27
|
|
28
|
+
test "nl_for_platform basic functionality" do
|
29
|
+
assert_respond_to(File, :nl_for_platform)
|
30
|
+
end
|
31
|
+
|
32
|
+
test "nl_for_platform" do
|
33
|
+
assert_equal( "\cM\cJ", File.nl_for_platform('dos') )
|
34
|
+
assert_equal( "\cJ", File.nl_for_platform('unix') )
|
35
|
+
assert_equal( "\cM", File.nl_for_platform('mac') )
|
36
|
+
assert_nothing_raised{ File.nl_for_platform('local') }
|
37
|
+
end
|
38
|
+
|
28
39
|
test "nl_convert basic functionality" do
|
29
40
|
assert_respond_to(File, :nl_convert)
|
30
41
|
end
|
data/test/test_which.rb
CHANGED
@@ -11,6 +11,7 @@ require 'test-unit'
|
|
11
11
|
require 'rbconfig'
|
12
12
|
require 'fileutils'
|
13
13
|
require 'ptools'
|
14
|
+
require 'tempfile'
|
14
15
|
|
15
16
|
class TC_FileWhich < Test::Unit::TestCase
|
16
17
|
def self.startup
|
@@ -95,6 +96,21 @@ class TC_FileWhich < Test::Unit::TestCase
|
|
95
96
|
assert_raises(ArgumentError){ File.which(@ruby, '') }
|
96
97
|
end
|
97
98
|
|
99
|
+
test "resolves with with ~" do
|
100
|
+
omit_if(@@windows, "~ tests skipped on MS Windows")
|
101
|
+
begin
|
102
|
+
old_home = ENV['HOME']
|
103
|
+
|
104
|
+
ENV['HOME'] = Dir::Tmpname.tmpdir
|
105
|
+
program = Tempfile.new(['program', '.sh'])
|
106
|
+
File.chmod(755, program.path)
|
107
|
+
|
108
|
+
assert_not_nil(File.which(File.basename(program.path), '~/'))
|
109
|
+
ensure
|
110
|
+
ENV['HOME'] = old_home
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
98
114
|
def teardown
|
99
115
|
@exe = nil
|
100
116
|
@ruby = nil
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ptools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel J. Berger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -96,21 +96,21 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
96
|
version: '0'
|
97
97
|
requirements: []
|
98
98
|
rubyforge_project:
|
99
|
-
rubygems_version: 2.
|
99
|
+
rubygems_version: 2.2.2
|
100
100
|
signing_key:
|
101
101
|
specification_version: 4
|
102
102
|
summary: Extra methods for the File class
|
103
103
|
test_files:
|
104
|
+
- test/test_binary.rb
|
105
|
+
- test/test_constants.rb
|
104
106
|
- test/test_head.rb
|
105
|
-
- test/
|
106
|
-
- test/test_tail.rb
|
107
|
-
- test/test_wc.rb
|
107
|
+
- test/test_image.rb
|
108
108
|
- test/test_is_sparse.rb
|
109
|
+
- test/test_middle.rb
|
110
|
+
- test/test_nlconvert.rb
|
109
111
|
- test/test_null.rb
|
112
|
+
- test/test_tail.rb
|
110
113
|
- test/test_touch.rb
|
111
|
-
- test/
|
114
|
+
- test/test_wc.rb
|
112
115
|
- test/test_whereis.rb
|
113
|
-
- test/
|
114
|
-
- test/test_image.rb
|
115
|
-
- test/test_constants.rb
|
116
|
-
- test/test_nlconvert.rb
|
116
|
+
- test/test_which.rb
|