ptools 1.3.1 → 1.3.2

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
  SHA1:
3
- metadata.gz: 0041b6df231b056f194bffcee580248797c341c5
4
- data.tar.gz: 196e358a536fa6b2d7bc6243c3fe4d320c65860a
3
+ metadata.gz: 567b8c9e88bdaed3107c8248a607801686db5ef0
4
+ data.tar.gz: d6ea99f75c65ec236c1606d856a729f9b26b1659
5
5
  SHA512:
6
- metadata.gz: a611871af4c407b0ca637d1aa1a9e76854813a9ba52219a4abc97ac806d1af1e78e26fabc877abb97d099d7fa3a5d4fcfa6e083ec3e54a8eeb012410fb75fe17
7
- data.tar.gz: 11d52f61ad1fc09fabb0c0c5a2006db4c917df704dc9c7252d3d41567762697fcb48bae93842c0f9c90a855286eed80f7224cdafd39e658923a7d1828b8f1859
6
+ metadata.gz: 210ee8e720a6cf80f8136ff7fb951d24ec7c58880d666a12118e4bc7f85b9daeeba7892a71dbb56f46c81ebf36cb61da2d6d09604399073a1afb45b8f13d6441
7
+ data.tar.gz: 3e1f8324bd844ade8ca6dffe4d3b5df19382db1243c27f3278594276365cf25373102f26e909eadb264b306cfcda070bf1e899ed9773eebfaa90f1b9f793aefc
data/CHANGES CHANGED
@@ -1,3 +1,8 @@
1
+ == 1.3.2 - 11-Dec-2014
2
+ * Update to the File.tail method that deals prevents potential line ending
3
+ issues in JRuby.
4
+ * Added known issues with JRuby to the README.
5
+
1
6
  == 1.3.1 - 9-Dec-2014
2
7
  * Fixed some potential issues with File.tail. Thanks go to Matt Hoyle for
3
8
  the patch.
data/README CHANGED
@@ -3,7 +3,7 @@
3
3
  File class based on Unix command line tools.
4
4
 
5
5
  == Prerequisites
6
- On MS Windows you will need win32-file 0.5.4 or later.
6
+ On MS Windows you will need the win32-file gem.
7
7
 
8
8
  == Installation
9
9
  gem install ptools
@@ -27,7 +27,10 @@
27
27
  File.nl_convert("myfile", "newfile", "dos")
28
28
 
29
29
  == Known Bugs
30
- None known. Please report any bugs on the github project page.
30
+ The File.which and File.whereis methods may fail when using JRuby on Windows.
31
+ See https://github.com/jruby/jruby/issues/2291 for details.
32
+
33
+ Please report any other issues on the github project page.
31
34
 
32
35
  http://www.github.com/djberg96/ptools
33
36
 
@@ -42,6 +45,8 @@
42
45
  The binary?() method was based almost entirely on a blog post by Ryan
43
46
  Davis (who, in turn, based his code on Perl's -B switch).
44
47
 
48
+ Thanks go to Matt Hoyle for help with the File.tail method.
49
+
45
50
  == Future Plans
46
51
  Add whatever other tools people think might be useful.
47
52
 
data/Rakefile CHANGED
@@ -29,7 +29,11 @@ namespace 'gem' do
29
29
  desc 'Install the ptools gem'
30
30
  task :install => [:create] do
31
31
  file = Dir["*.gem"].first
32
- sh "gem install -l #{file}"
32
+ if RUBY_PLATFORM == 'java'
33
+ sh "jruby -S gem install -l #{file}"
34
+ else
35
+ sh "gem install -l #{file}"
36
+ end
33
37
  end
34
38
  end
35
39
 
@@ -75,13 +79,6 @@ namespace 'test' do
75
79
  t.test_files = FileList['test/test_image.rb']
76
80
  end
77
81
 
78
- Rake::TestTask.new('middle') do |t|
79
- t.libs << 'test'
80
- t.verbose = true
81
- t.warning = true
82
- t.test_files = FileList['test/test_middle.rb']
83
- end
84
-
85
82
  Rake::TestTask.new('nlconvert') do |t|
86
83
  t.libs << 'test'
87
84
  t.verbose = true
@@ -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.3.1'
6
+ PTOOLS_VERSION = '1.3.2'
7
7
 
8
8
  # :stopdoc:
9
9
 
@@ -247,6 +247,10 @@ class File
247
247
  # If you're looking for tail -f functionality, please use the file-tail
248
248
  # gem instead.
249
249
  #
250
+ #--
251
+ # Internally I'm using a 64 chunk of memory at a time. I may allow the size
252
+ # to be configured in the future as an optional 3rd argument.
253
+ #
250
254
  def self.tail(filename, num_lines=10)
251
255
  tail_size = 2**16 # 64k chunks
252
256
 
@@ -255,24 +259,26 @@ class File
255
259
  file_size = File.size(filename)
256
260
  read_bytes = file_size % tail_size
257
261
  read_bytes = tail_size if read_bytes == 0
258
- line_sep = File::ALT_SEPARATOR ? "\r\n" : "\n"
262
+
263
+ line_sep = File::ALT_SEPARATOR ? "\r\n" : "\n"
259
264
 
260
265
  buf = ''
261
266
 
262
- File.open(filename){ |fh|
263
- # Set the starting read position
264
- position = file_size - read_bytes
265
-
267
+ # Open in binary mode to ensure line endings aren't converted.
268
+ File.open(filename, 'rb'){ |fh|
269
+ position = file_size - read_bytes # Set the starting read position
270
+
266
271
  # Loop until we have the lines or run out of file
267
272
  while buf.scan(line_sep).size <= num_lines and position >= 0
268
273
  fh.seek(position, IO::SEEK_SET)
269
274
  buf = fh.read(read_bytes) + buf
270
275
  read_bytes = tail_size
271
- position -= read_bytes
276
+ position -= read_bytes
272
277
  end
273
278
  }
274
279
 
275
280
  lines = buf.split(line_sep).pop(num_lines)
281
+
276
282
  if block_given?
277
283
  lines.each{ |line| yield line }
278
284
  else
@@ -3,7 +3,7 @@ require 'rbconfig'
3
3
 
4
4
  Gem::Specification.new do |gem|
5
5
  gem.name = 'ptools'
6
- gem.version = '1.3.1'
6
+ gem.version = '1.3.2'
7
7
  gem.license = 'Artistic 2.0'
8
8
  gem.author = 'Daniel J. Berger'
9
9
  gem.email = 'djberg96@gmail.com'
@@ -16,15 +16,15 @@ class TC_Ptools_Binary < Test::Unit::TestCase
16
16
  @@bin_file = '/bin/ls'
17
17
  end
18
18
 
19
- Dir.chdir('test') if File.exist?('test')
19
+ @@dirname = File.dirname(__FILE__)
20
20
  end
21
21
 
22
22
  def setup
23
- @txt_file = File.join('txt', 'english.txt')
24
- @uni_file = File.join('txt', 'korean.txt')
25
- @png_file = File.join('img', 'test.png')
26
- @jpg_file = File.join('img', 'test.jpg')
27
- @gif_file = File.join('img', 'test.gif')
23
+ @txt_file = File.join(@@dirname, 'txt', 'english.txt')
24
+ @uni_file = File.join(@@dirname, 'txt', 'korean.txt')
25
+ @png_file = File.join(@@dirname, 'img', 'test.png')
26
+ @jpg_file = File.join(@@dirname, 'img', 'test.jpg')
27
+ @gif_file = File.join(@@dirname, 'img', 'test.gif')
28
28
  end
29
29
 
30
30
  test "File.binary? basic functionality" do
@@ -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.3.1', File::PTOOLS_VERSION)
18
+ assert_equal('1.3.2', File::PTOOLS_VERSION)
19
19
  end
20
20
 
21
21
  test "IMAGE_EXT constant is set to array of values" do
@@ -10,18 +10,18 @@ require 'ptools'
10
10
 
11
11
  class TC_Ptools_NLConvert < Test::Unit::TestCase
12
12
  def self.startup
13
- Dir.chdir('test') if File.exist?('test')
14
- @@test_file1 = 'test_nl_convert1.txt'
15
- @@test_file2 = 'test_nl_convert2.txt'
13
+ @@dirname = File.dirname(__FILE__)
14
+ @@test_file1 = File.join(@@dirname, 'test_nl_convert1.txt')
15
+ @@test_file2 = File.join(@@dirname, 'test_nl_convert2.txt')
16
16
  File.open(@@test_file1, 'w'){ |fh| 10.times{ |n| fh.puts "line #{n}" } }
17
17
  File.open(@@test_file2, 'w'){ |fh| 10.times{ |n| fh.puts "line #{n}" } }
18
18
  end
19
19
 
20
20
  def setup
21
- @test_file1 = 'test_nl_convert1.txt'
22
- @test_file2 = 'test_nl_convert2.txt'
23
- @dos_file = 'dos_test_file.txt'
24
- @mac_file = 'mac_test_file.txt'
21
+ @test_file1 = File.join(@@dirname, 'test_nl_convert1.txt')
22
+ @test_file2 = File.join(@@dirname, 'test_nl_convert2.txt')
23
+ @dos_file = File.join(@@dirname, 'dos_test_file.txt')
24
+ @mac_file = File.join(@@dirname, 'mac_test_file.txt')
25
25
  @unix_file = 'nix_test_file.txt'
26
26
  end
27
27
 
@@ -35,7 +35,7 @@ class TC_Ptools_NLConvert < Test::Unit::TestCase
35
35
  assert_equal( "\cM", File.nl_for_platform('mac') )
36
36
  assert_nothing_raised{ File.nl_for_platform('local') }
37
37
  end
38
-
38
+
39
39
  test "nl_convert basic functionality" do
40
40
  assert_respond_to(File, :nl_convert)
41
41
  end
@@ -9,48 +9,53 @@ require 'ptools'
9
9
 
10
10
  class TC_FileTail < Test::Unit::TestCase
11
11
  def self.startup
12
+ @@dirname = File.dirname(__FILE__)
12
13
 
13
- Dir.chdir('test') if File.exist?('test')
14
+ @@test_file1 = File.join(@@dirname, 'test_file1.txt')
15
+ @@test_file64 = File.join(@@dirname, 'test_file64.txt')
16
+ @@test_file128 = File.join(@@dirname, 'test_file128.txt')
14
17
 
15
- File.open('test_file1.txt', 'w'){ |fh|
18
+ @@test_file_trail = File.join(@@dirname, 'test_file_trail.txt')
19
+ @@test_file_trail_nl = File.join(@@dirname, 'test_file_trail_nl.txt')
20
+
21
+ File.open(@@test_file1, 'w'){ |fh|
16
22
  25.times{ |n| fh.puts "line#{n+1}" }
17
23
  }
18
24
 
19
25
  # Trailing newline test
20
- File.open('test_file_trail.txt', 'w'){ |fh|
26
+ File.open(@@test_file_trail, 'w'){ |fh|
21
27
  2.times{ |n| fh.puts "trail#{n+1}" }
22
28
  fh.write "trail3"
23
29
  }
24
- File.open('test_file_trail_nl.txt', 'w'){ |fh|
30
+ File.open(@@test_file_trail_nl, 'w'){ |fh|
25
31
  3.times{ |n| fh.puts "trail#{n+1}" }
26
32
  }
27
33
 
28
34
  # Larger files
29
35
  test_tail_fmt_str = "line data data data data data data data %5s"
30
36
 
31
- File.open('test_file64.txt', 'w'){ |fh|
32
- 2000.times{ |n|
33
- fh.puts test_tail_fmt_str % (n+1).to_s
37
+ File.open(@@test_file64, 'w'){ |fh|
38
+ 2000.times{ |n|
39
+ fh.puts test_tail_fmt_str % (n+1).to_s
34
40
  }
35
41
  }
36
42
 
37
- File.open('test_file128.txt', 'w'){ |fh|
38
- 4500.times{ |n|
43
+ File.open(@@test_file128, 'w'){ |fh|
44
+ 4500.times{ |n|
39
45
  fh.puts test_tail_fmt_str % (n+1).to_s
40
46
  }
41
-
42
47
  }
43
48
  end
44
49
 
45
50
  def setup
46
- @test_file = 'test_file1.txt'
47
- @test_trail = 'test_file_trail.txt'
48
- @test_trail_nl = 'test_file_trail_nl.txt'
49
- @test_file_64 = 'test_file64.txt'
50
- @test_file_128 = 'test_file128.txt'
51
+ @test_file = @@test_file1
52
+ @test_trail = @@test_file_trail
53
+ @test_trail_nl = @@test_file_trail_nl
54
+ @test_file_64 = @@test_file64
55
+ @test_file_128 = @@test_file128
51
56
 
52
57
  @expected_tail1 = %w{
53
- line16 line17 line18 line19 line20
58
+ line16 line17 line18 line19 line20
54
59
  line21 line22 line23 line24 line25
55
60
  }
56
61
 
@@ -62,8 +67,6 @@ class TC_FileTail < Test::Unit::TestCase
62
67
  @expected_tail_trail = %w{ trail2 trail3 }
63
68
 
64
69
  @test_tail_fmt_str = "line data data data data data data data %5s"
65
-
66
-
67
70
  end
68
71
 
69
72
  def test_tail_basic
@@ -105,8 +108,6 @@ class TC_FileTail < Test::Unit::TestCase
105
108
  assert_equal( expected_tail_128k, File.tail(@test_file_128, 4500) )
106
109
  end
107
110
 
108
-
109
-
110
111
  def teardown
111
112
  @test_file = nil
112
113
  @expected_tail1 = nil
@@ -114,10 +115,10 @@ class TC_FileTail < Test::Unit::TestCase
114
115
  end
115
116
 
116
117
  def self.shutdown
117
- File.delete('test_file1.txt') if File.exist?('test_file1.txt')
118
- File.delete('test_file64.txt') if File.exist?('test_file64.txt')
119
- File.delete('test_file128.txt') if File.exist?('test_file128.txt')
120
- File.delete('test_file_trail_nl.txt') if File.exist?('test_file_trail_nl.txt')
121
- File.delete('test_file_trail.txt') if File.exist?('test_file_trail.txt')
118
+ File.delete(@@test_file1) if File.exist?(@@test_file1)
119
+ File.delete(@@test_file64) if File.exist?(@@test_file64)
120
+ File.delete(@@test_file128) if File.exist?(@@test_file128)
121
+ File.delete(@@test_file_trail_nl) if File.exist?(@@test_file_trail_nl)
122
+ File.delete(@@test_file_trail) if File.exist?(@@test_file_trail)
122
123
  end
123
124
  end
@@ -9,13 +9,14 @@ require 'ptools'
9
9
 
10
10
  class TC_FileTouch < Test::Unit::TestCase
11
11
  def self.startup
12
- Dir.chdir('test') if File.exist?('test')
13
- File.open('test_file1.txt', 'w'){ |fh| 10.times{ |n| fh.puts "line #{n}" } }
12
+ @@dirname = File.dirname(__FILE__)
13
+ @@xfile = File.join(@@dirname, 'test_file1.txt')
14
+ File.open(@@xfile, 'w'){ |fh| 10.times{ |n| fh.puts "line #{n}" } }
14
15
  end
15
16
 
16
17
  def setup
17
- @test_file = 'delete.this'
18
- @xfile = 'test_file1.txt'
18
+ @test_file = File.join(@@dirname, 'delete.this')
19
+ @xfile = File.join(@@dirname, 'test_file1.txt')
19
20
  end
20
21
 
21
22
  def test_touch_basic
@@ -47,6 +48,6 @@ class TC_FileTouch < Test::Unit::TestCase
47
48
  end
48
49
 
49
50
  def self.shutdown
50
- File.delete('test_file1.txt') if File.exist?('test_file1.txt')
51
+ File.delete(@@xfile) if File.exist?(@@xfile)
51
52
  end
52
53
  end
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.3.1
4
+ version: 1.3.2
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-12-09 00:00:00.000000000 Z
11
+ date: 2014-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -95,20 +95,20 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
95
  version: '0'
96
96
  requirements: []
97
97
  rubyforge_project:
98
- rubygems_version: 2.2.2
98
+ rubygems_version: 2.4.5
99
99
  signing_key:
100
100
  specification_version: 4
101
101
  summary: Extra methods for the File class
102
102
  test_files:
103
- - test/test_binary.rb
104
- - test/test_constants.rb
105
- - test/test_head.rb
106
- - test/test_image.rb
107
- - test/test_is_sparse.rb
108
103
  - test/test_nlconvert.rb
109
- - test/test_null.rb
110
- - test/test_tail.rb
111
- - test/test_touch.rb
112
104
  - test/test_wc.rb
105
+ - test/test_head.rb
106
+ - test/test_null.rb
107
+ - test/test_is_sparse.rb
113
108
  - test/test_whereis.rb
109
+ - test/test_binary.rb
110
+ - test/test_touch.rb
111
+ - test/test_tail.rb
112
+ - test/test_constants.rb
113
+ - test/test_image.rb
114
114
  - test/test_which.rb