imw 0.2.10 → 0.2.11

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -2,15 +2,20 @@
2
2
  source :gemcutter
3
3
  gem 'activesupport', '2.3.5', :require => 'active_support'
4
4
  gem 'addressable', :require => 'addressable/uri'
5
- gem 'rake'
6
- gem 'rest-client', '>= 1.6.1', :require => 'restclient'
7
5
  gem 'uuidtools'
6
+ gem 'rake'
7
+
8
+ # The following Gems qre required for specific transport schemes and
9
+ # are not used by core IMW functions.
10
+ group :schemes do
11
+ gem 'aws-s3', :require => 'aws/s3'
12
+ gem 'dbi'
13
+ gem 'rest-client', '>= 1.6.1', :require => 'restclient'
14
+ end
8
15
 
9
16
  # The following Gems qre required for specific data formats and are
10
17
  # not used by core IMW functions.
11
18
  group :formats do
12
- gem 'aws-s3', :require => 'aws/s3'
13
- gem 'dbi'
14
19
  gem 'fastercsv'
15
20
  gem 'hpricot'
16
21
  gem 'json'
data/Gemfile.lock CHANGED
@@ -13,7 +13,7 @@ GEM
13
13
  deprecated (= 2.0.1)
14
14
  deprecated (2.0.1)
15
15
  fastercsv (1.5.3)
16
- hpricot (0.8.2)
16
+ hpricot (0.8.3)
17
17
  json (1.4.6)
18
18
  mime-types (1.16)
19
19
  pdf-reader (0.8.6)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.10
1
+ 0.2.11
@@ -127,10 +127,9 @@ module IMW
127
127
  # Write the text with a trailing newline to this resource.
128
128
  #
129
129
  # @param [String, #to_s] text
130
- def puts text
130
+ def << text
131
131
  io.write text.to_s + "\n"
132
132
  end
133
- alias_method :<<, :puts
134
133
 
135
134
  # Return the lines in this file.
136
135
  #
@@ -160,7 +159,7 @@ module IMW
160
159
  # @param [String, Array, #each] data object to emit
161
160
  def emit data, options={}
162
161
  data.each do |element| # works if data is an Array or a String
163
- io.puts(element.to_s)
162
+ io << (element.to_s)
164
163
  end
165
164
  end
166
165
 
@@ -29,13 +29,14 @@ module IMW
29
29
  # @param [String, IMW::Resource] new_uri
30
30
  # @return [IMW::Resource] the new resource
31
31
  def cp new_uri
32
- IMW::Tools::Transferer.new(:cp, self, new_uri).transfer!
32
+ #IMW::Tools::Transferer.new(:cp, self, new_uri).transfer!
33
+ IMW::Schemes::S3.get(self, new_uri)
33
34
  end
34
35
 
35
36
  # The AWS::S3::S3Object corresponding to this resource.
36
37
  def s3_object
37
- self.class.make_connection!
38
- @s3_object ||= AWS::S3::S3Object.new(path, bucket)
38
+ ::IMW::Schemes::S3.make_connection!
39
+ @s3_object ||= AWS::S3::S3Object.new(path, :bucket => bucket)
39
40
  end
40
41
 
41
42
  # Does this resource exist on S3?
@@ -80,7 +81,7 @@ module IMW
80
81
  def self.put source, destination
81
82
  source = IMW.open(source)
82
83
  destintation = IMW.open(destination)
83
- raise IMW::ArgumentError.new("destination must be on S3 -- #{destination.uri} given") unless destination.on_s3?
84
+ raise IMW::ArgumentError.new("destination must be on S3 -- #{destination} given") unless destination.on_s3?
84
85
  make_connection!
85
86
  AWS::S3::S3Object.store(destination.path, source.io, destination.bucket)
86
87
  destination
@@ -93,9 +94,10 @@ module IMW
93
94
  # @return [IMW::Resource] the new resource
94
95
  def self.get source, destination
95
96
  source = IMW.open(source)
96
- destination = IMW.open(destination)
97
+ destination = IMW.open!(destination)
98
+ raise IMW::ArgumentError.new("source must be on S3 -- #{source} given") unless source.on_s3?
97
99
  make_connection!
98
- AWS::S3::Object.stream(source.path, source.bucket) do |chunk|
100
+ AWS::S3::S3Object.stream(source.path, source.bucket) do |chunk|
99
101
  destination.write(chunk)
100
102
  end
101
103
  destination.close
@@ -11,12 +11,12 @@ module IMW
11
11
  #
12
12
  # Any remote resources will be downloaded into the directory.
13
13
  #
14
- # If any of the resources are (local and) archives, they will first be
14
+ # If any of the resources are archives, they will first be
15
15
  # extracted, with only their contents winding up in the final
16
16
  # directory (the file hierarchy of the archive will be preserved).
17
17
  #
18
- # If any of the resources are (local and) compressed, they will
19
- # first be uncompressed before being added to the directory.
18
+ # If any of the resources are compressed, they will first be
19
+ # uncompressed before being added to the directory.
20
20
  #
21
21
  # As an example:
22
22
  #
@@ -90,7 +90,7 @@ module IMW
90
90
  # @return [IMW::Tools::Aggregator]
91
91
  def aggregate *paths_or_inputs
92
92
  @errors = []
93
- paths_or_inputs.each do |path_or_input|
93
+ paths_or_inputs.flatten.compact.each do |path_or_input|
94
94
  input = IMW.open(path_or_input)
95
95
  if input.is_local?
96
96
  aggregate_local_input(input)
@@ -38,8 +38,9 @@ module IMW
38
38
  # @return [Hash]
39
39
  def normalized_extension_counts
40
40
  @normalized_extension_counts ||= returning({}) do |weighted|
41
+ num_files = resources.reject(&:is_directory?).length.to_f
41
42
  extension_counts.each_pair do |extension, count|
42
- weighted[extension] = count.to_f / num_files.to_f
43
+ weighted[extension] = count.to_f / num_files
43
44
  end
44
45
  end
45
46
  end
data/lib/imw/utils.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'fileutils'
3
- require 'active_support'
3
+ require 'active_support/core_ext/object/blank'
4
+ require 'active_support/core_ext/object/misc'
4
5
  require 'imw/utils/error'
5
6
  require 'imw/utils/log'
6
7
  require 'imw/utils/paths'
@@ -24,11 +24,11 @@ module IMWTest
24
24
  # length of the filename returned.
25
25
  def self.basename options = {}
26
26
  length = (options[:length] or FILENAME_MAX_LENGTH)
27
- filename = (1..length).map { |i| FILENAME_CHARS.rand }.join
27
+ filename = (1..length).map { |i| FILENAME_CHARS.choice }.join
28
28
 
29
29
  # filenames beginning with hyphens suck
30
30
  while (filename[0,1] == '-') do
31
- filename[0] = FILENAME_CHARS.rand
31
+ filename[0] = FILENAME_CHARS.choice
32
32
  end
33
33
  filename
34
34
  end
@@ -38,7 +38,7 @@ module IMWTest
38
38
  def self.text options = {}
39
39
  length = (options[:length] or TEXT_MAX_LENGTH)
40
40
  char_pool = options[:newlines] ? TEXT_CHARS : STRING_CHARS
41
- (1..length).map { |i| char_pool.rand }.join
41
+ (1..length).map { |i| char_pool.choice }.join
42
42
  end
43
43
 
44
44
  # Create a random file by matching the extension of the given
@@ -190,7 +190,7 @@ module IMWTest
190
190
  FileUtils.mkdir_p(directory)
191
191
 
192
192
  (rand(options[:num_files]) + 2).times do
193
- ext = options[:extensions].rand
193
+ ext = options[:extensions].choice
194
194
  name = self.basename
195
195
  if ext == 'dir' then
196
196
  if depth <= options[:max_depth] then
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imw
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
4
+ hash: 1
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 10
10
- version: 0.2.10
9
+ - 11
10
+ version: 0.2.11
11
11
  platform: ruby
12
12
  authors:
13
13
  - Dhruv Bansal
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-10-29 00:00:00 -05:00
19
+ date: 2010-11-15 00:00:00 -06:00
20
20
  default_executable: imw
21
21
  dependencies: []
22
22