unix_utils 0.0.9 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,28 +1,39 @@
1
- == 0.0.9 / 2012-04-12
1
+ 0.0.10 / 2012-14-23
2
+
3
+ * Breaking changes
4
+
5
+ * Added UnixUtils.du_sk, which always returns bytes; removed UnixUtils.du, which returned block counts, which I doubt you wanted.
6
+
7
+ * Enhancements
8
+
9
+ * If you call a method with _s at the end, you get a string back. For example: UnixUtils.head_s
10
+ * UnixUtils.tmp_path no longer junks up tmp paths with lots of "unix_utils_RANDOMSTRING"
11
+
12
+ 0.0.9 / 2012-04-12
2
13
 
3
14
  * Bug fixes
4
15
 
5
16
  * Correct implementation of :read_from
6
17
 
7
- == 0.0.8 / 2012-04-12
18
+ 0.0.8 / 2012-04-12
8
19
 
9
20
  * Bug fixes
10
21
 
11
22
  * Let perl handle its own input files (ARGF)... my implementation using IO.select was not working.
12
23
 
13
- == 0.0.7 / 2012-04-11
24
+ 0.0.7 / 2012-04-11
14
25
 
15
26
  * Bug fixes
16
27
 
17
28
  * Make sure UnixUtils.tmp_path doesn't create too-long filenames
18
29
 
19
- == 0.0.6 / 2012-04-11
30
+ 0.0.6 / 2012-04-11
20
31
 
21
32
  * Enhancements
22
33
 
23
34
  * iconv command silently discards invalid characters
24
35
 
25
- == 0.0.5 / 2012-03-21
36
+ 0.0.5 / 2012-03-21
26
37
 
27
38
  * Enhancements
28
39
 
@@ -32,13 +43,13 @@
32
43
 
33
44
  * Thanks to @leomao10, make sed work more reliably on large files by using its input-file argument rather than piping in data
34
45
 
35
- == 0.0.4 / 2012-03-19
46
+ 0.0.4 / 2012-03-19
36
47
 
37
48
  * Bug fixes
38
49
 
39
50
  * NoMethodError when trying to print $stderr - thanks @leomao10 !
40
51
 
41
- == 0.0.3 / 2012-03-19
52
+ 0.0.3 / 2012-03-19
42
53
 
43
54
  * Enhancements
44
55
 
@@ -49,12 +60,12 @@
49
60
 
50
61
  * Correctly use pipes (I hope) - imitate POSIX::Spawn::Child's use of IO.select
51
62
 
52
- == 0.0.2 / 2012-02-16
63
+ 0.0.2 / 2012-02-16
53
64
 
54
65
  * Bug fixes
55
66
 
56
67
  * Fix use of splat internally so that it actually runs in MRI 1.8.7 and JRuby
57
68
 
58
- == 0.0.1 / 2012-02-16 (yanked!)
69
+ 0.0.1 / 2012-02-16 (yanked!)
59
70
 
60
71
  * Birthday!
@@ -4,11 +4,16 @@ Like FileUtils, but provides zip, unzip, bzip2, bunzip2, tar, untar, sed, du, md
4
4
 
5
5
  Works in MRI 1.8.7+, MRI 1.9.2+, and JRuby 1.6.7+
6
6
 
7
- ## Where it's used
7
+ ## Real-world usage
8
8
 
9
- * [Brighter Planet CM1 Impact Estimate web service](http://impact.brighterplanet.com)
10
- * [Brighter Planet Reference Data web service](http://data.brighterplanet.com)
11
- * Extracted from [`remote_table`](https://github.com/seamusabshere/remote_table)
9
+ <p><a href="http://brighterplanet.com"><img src="https://s3.amazonaws.com/static.brighterplanet.com/assets/logos/flush-left/inline/green/rasterized/brighter_planet-160-transparent.png" alt="Brighter Planet logo"/></a></p>
10
+
11
+ We use `unix_utils` for [data science at Brighter Planet](http://brighterplanet.com/research) and in production at
12
+
13
+ * [Brighter Planet's impact estimate web service](http://impact.brighterplanet.com)
14
+ * [Brighter Planet's reference data web service](http://data.brighterplanet.com)
15
+
16
+ Originally extracted from [`remote_table`](https://github.com/seamusabshere/remote_table)
12
17
 
13
18
  ## Philosophy
14
19
 
@@ -3,7 +3,7 @@ require 'tmpdir'
3
3
  require 'uri'
4
4
  require 'stringio'
5
5
  require 'posix/spawn'
6
-
6
+ require 'securerandom'
7
7
  require "unix_utils/version"
8
8
 
9
9
  module UnixUtils
@@ -70,9 +70,9 @@ module UnixUtils
70
70
  end
71
71
  end
72
72
 
73
- def self.du(srcdir)
73
+ def self.du_sk(srcdir)
74
74
  srcdir = ::File.expand_path srcdir
75
- argv = ['du', srcdir]
75
+ argv = ['du', '-sk', srcdir]
76
76
  stdout = spawn argv
77
77
  stdout.strip.split(/\s+/).first.to_i
78
78
  end
@@ -245,10 +245,9 @@ module UnixUtils
245
245
  def self.tmp_path(ancestor, extname = nil) # :nodoc:
246
246
  ancestor = ancestor.to_s
247
247
  extname ||= ::File.extname ancestor
248
- basename = ::File.basename ancestor.sub(/^unix_utils-[0-9]+-/, '')
248
+ basename = ::File.basename ancestor.gsub(/unix_utils_[a-f0-9]{8,}_/, '')
249
249
  basename.gsub! /\W+/, '_'
250
- ::Kernel.srand
251
- ::File.join ::Dir.tmpdir, "unix_utils-#{::Kernel.rand(1e11)}-#{basename[0..(231-extname.length)]}#{extname}"
250
+ ::File.join ::Dir.tmpdir, "unix_utils_#{::SecureRandom.hex(4)}_#{basename[0..(234-extname.length)]}#{extname}"
252
251
  end
253
252
 
254
253
  def self.spawn(argv, options = {}) # :nodoc:
@@ -324,4 +323,18 @@ module UnixUtils
324
323
  ensure
325
324
  [stdin, stdout, stderr, input, output, error].each { |io| io.close if io and not io.closed? }
326
325
  end
326
+
327
+ def self.method_missing(method_id, *args)
328
+ base_method_id = method_id.to_s.chomp('_s')
329
+ if respond_to?(base_method_id)
330
+ begin
331
+ outfile = send(*([base_method_id]+args))
332
+ ::File.read outfile
333
+ ensure
334
+ ::FileUtils.rm_f outfile
335
+ end
336
+ else
337
+ super
338
+ end
339
+ end
327
340
  end
@@ -1,3 +1,3 @@
1
1
  module UnixUtils
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
3
3
  end
@@ -7,8 +7,6 @@ require 'minitest/reporters'
7
7
  MiniTest::Unit.runner = MiniTest::SuiteRunner.new
8
8
  MiniTest::Unit.runner.reporters << MiniTest::Reporters::SpecReporter.new
9
9
 
10
- $LOAD_PATH.unshift(File.dirname(__FILE__))
11
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
12
10
  require 'unix_utils'
13
11
 
14
12
  require 'stringio'
@@ -25,7 +23,7 @@ module TestHelper
25
23
  when :file
26
24
  checksum = UnixUtils.shasum infile_or_srcdir, 256
27
25
  when :directory
28
- size = UnixUtils.du infile_or_srcdir
26
+ size = UnixUtils.du_sk infile_or_srcdir
29
27
  end
30
28
  destdir = UnixUtils.send(*([method_id] + args))
31
29
  safe_delete destdir
@@ -34,7 +32,7 @@ module TestHelper
34
32
  when :file
35
33
  UnixUtils.shasum(infile_or_srcdir, 256).must_equal checksum
36
34
  when :directory
37
- UnixUtils.du(infile_or_srcdir).must_equal size
35
+ UnixUtils.du_sk(infile_or_srcdir).must_equal size
38
36
  end
39
37
  end
40
38
 
@@ -55,9 +55,9 @@ describe UnixUtils do
55
55
  end
56
56
  end
57
57
 
58
- describe :du do
58
+ describe :du_sk do
59
59
  it "calculates the size of a directory in bytes" do
60
- UnixUtils.du('directory').must_equal 16
60
+ UnixUtils.du_sk('directory').must_equal 8
61
61
  end
62
62
  end
63
63
 
@@ -342,6 +342,10 @@ describe UnixUtils do
342
342
  File.read(outfile).must_equal @a2z[2..-1].join("\n")
343
343
  safe_delete outfile
344
344
  end
345
+ it 'has a related tail_s method' do
346
+ str = UnixUtils.tail_s(@infile, 3)
347
+ str.must_equal @a2z.last(3).join("\n")
348
+ end
345
349
  end
346
350
 
347
351
  describe :head do
@@ -360,6 +364,10 @@ describe UnixUtils do
360
364
  File.read(outfile).must_equal(@a2z.first(3).join("\n") + "\n")
361
365
  safe_delete outfile
362
366
  end
367
+ it 'has a related head_s method' do
368
+ str = UnixUtils.head_s(@infile, 3)
369
+ str.must_equal(@a2z.first(3).join("\n") + "\n")
370
+ end
363
371
  end
364
372
 
365
373
  describe :cut do
@@ -413,11 +421,23 @@ describe UnixUtils do
413
421
  File.extname(UnixUtils.tmp_path("dirname1/dirname2/basename.extname", '.foobar')).must_equal '.foobar'
414
422
  end
415
423
  it "doesn't create excessively long filenames" do
416
- 100.times { File.basename(UnixUtils.tmp_path("a"*5000)).length.must_be :<, 256 }
424
+ 100.times { File.basename(UnixUtils.tmp_path("a"*5000)).length.must_equal(255) }
417
425
  end
418
426
  it "doesn't include directory part of ancestor" do
419
427
  UnixUtils.tmp_path("dirname1/dirname2/basename.extname").wont_include 'dirname1'
420
428
  end
429
+ it "includes unix_utils part only once" do
430
+ one = UnixUtils.tmp_path('basename.extname')
431
+ File.basename(one).start_with?('unix_utils').must_equal true
432
+ one.scan(/unix_utils/).length.must_equal 1
433
+ again = UnixUtils.tmp_path(one)
434
+ File.basename(again).start_with?('unix_utils').must_equal true
435
+ again.scan(/unix_utils/).length.must_equal 1
436
+ and_again = UnixUtils.tmp_path(again)
437
+ File.basename(and_again).start_with?('unix_utils').must_equal true
438
+ and_again.scan(/unix_utils/).length.must_equal 1
439
+ and_again.must_include('basename_extname')
440
+ end
421
441
  end
422
442
 
423
443
  # not really for public consumption
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unix_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-12 00:00:00.000000000 Z
12
+ date: 2012-04-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: posix-spawn
@@ -37,8 +37,8 @@ extensions: []
37
37
  extra_rdoc_files: []
38
38
  files:
39
39
  - .gitignore
40
+ - CHANGELOG
40
41
  - Gemfile
41
- - History.txt
42
42
  - README.markdown
43
43
  - Rakefile
44
44
  - lib/unix_utils.rb