unpacker 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -11,6 +11,7 @@ begin
11
11
  gem.homepage = "http://github.com/underlog/unpacker"
12
12
  gem.authors = ["Petyo Ivanov"]
13
13
  gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ gem.add_dependency "shellshot"
14
15
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
16
  end
16
17
  Jeweler::GemcutterTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
@@ -1,17 +1,28 @@
1
+ require 'shellshot'
1
2
  require 'fileutils'
2
3
  require 'tmpdir'
3
4
 
4
5
  module Unpacker
5
6
 
6
7
  class UnrecognizedArchiveError < StandardError; end
7
- class UnpackedFailedError < StandardError; end
8
8
 
9
9
  SUPPORTED_FILEEXTS = %w[tar rar zip gz bz tgz bgz tar]
10
10
 
11
- def self.unpack(file, tmpdir = "/tmp", &block)
11
+ def self.unpack(file, tmpdir = "/tmp", &block)
12
12
  Dir.mktmpdir 'unpacker' do |dir|
13
- cmd = command_by_file_ext(file)% [file, dir]
14
- system("#{cmd} 1>/dev/null") or raise UnrecognizedArchiveError($?)
13
+ case file
14
+ when /rar$/
15
+ Shellshot.exec [ "unrar", "x", "-y", file, dir ], :stdout => false
16
+ when /(tar|tgz|tar\.gz|tar\.bz|tbz)$/
17
+ Shellshot.exec [ "tar", "xf", file, "--directory", dir ], :stdout => false
18
+ when /zip$/
19
+ Shellshot.exec [ "unzip", file, "-d", dir ], :stdout => false
20
+ when /gz$/
21
+ Shellshot.exec [ "gunzip", "-c", file ], :stdout => File.join(dir, "gz-contents")
22
+ else
23
+ raise UnrecognizedArchiveError
24
+ end
25
+
15
26
  block.call(Dir.new(dir))
16
27
  end
17
28
  end
@@ -21,85 +32,23 @@ module Unpacker
21
32
  end
22
33
 
23
34
  def self.valid?(file_path, file_name = file_path)
24
- cmd = test_cmd_by_file_ext(file_name)% file_path
25
- system("#{cmd} 1>/dev/null 2>/dev/null")
26
- end
27
-
28
- # :stopdoc:
29
- VERSION = '1.0.1'
30
- LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
31
- PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
32
- # :startdoc:
33
-
34
- # Returns the version string for the library.
35
- #
36
- def self.version
37
- VERSION
38
- end
39
-
40
- # Returns the library path for the module. If any arguments are given,
41
- # they will be joined to the end of the libray path using
42
- # <tt>File.join</tt>.
43
- #
44
- def self.libpath( *args )
45
- args.empty? ? LIBPATH : ::File.join(LIBPATH, args.flatten)
46
- end
47
-
48
- # Returns the lpath for the module. If any arguments are given,
49
- # they will be joined to the end of the path using
50
- # <tt>File.join</tt>.
51
- #
52
- def self.path( *args )
53
- args.empty? ? PATH : ::File.join(PATH, args.flatten)
54
- end
55
-
56
- # Utility method used to require all files ending in .rb that lie in the
57
- # directory below this file that has the same name as the filename passed
58
- # in. Optionally, a specific _directory_ name can be passed in such that
59
- # the _filename_ does not have to be equivalent to the directory.
60
- #
61
- def self.require_all_libs_relative_to( fname, dir = nil )
62
- dir ||= ::File.basename(fname, '.*')
63
- search_me = ::File.expand_path(
64
- ::File.join(::File.dirname(fname), dir, '**', '*.rb'))
65
-
66
- Dir.glob(search_me).sort.each {|rb| require rb}
67
- end
68
-
69
- private
70
-
71
- def self.test_cmd_by_file_ext(file_name)
72
- case file_name
73
- when /rar$/
74
- 'unrar t "%s"'
75
- when /(tar|tar\.bz|tbz)$/
76
- 'tar tf "%s"'
77
- when /zip$/
78
- 'zip -T "%s"'
79
- when /gz|tgz$/
80
- 'gunzip -t "%s"'
81
- else
82
- raise UnrecognizedArchiveError
83
- end
84
- end
85
-
86
- def self.command_by_file_ext(file_name)
87
- case file_name
88
- when /rar$/
89
- 'unrar x -y "%s" "%s"'
90
- when /(tar|tgz|tar\.gz|tar\.bz|tbz)$/
91
- 'tar xf "%s" --directory "%s"'
92
- when /zip$/
93
- 'unzip "%s" -d "%s"'
94
- when /gz$/
95
- '(gunzip -c "%s" > "%s/gz-contents")'
96
- else
97
- raise UnrecognizedArchiveError
98
- end
35
+ cmd = case file_name
36
+ when /rar$/
37
+ [ 'unrar', 't', file_path ]
38
+ when /(tar|tar\.bz|tbz)$/
39
+ [ 'tar', 'tf', file_path ]
40
+ when /zip$/
41
+ [ 'zip', '-T', file_path ]
42
+ when /gz|tgz$/
43
+ [ 'gunzip', '-t', file_path ]
44
+ else
45
+ raise UnrecognizedArchiveError
46
+ end
47
+ Shellshot.exec cmd, :stdall => false
48
+ true
49
+ rescue
50
+ false
99
51
  end
100
52
 
101
53
  end # module Unpacker
102
54
 
103
- Unpacker.require_all_libs_relative_to(__FILE__)
104
-
105
- # EOF
@@ -2,6 +2,7 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
2
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
3
  require 'unpacker'
4
4
  require 'spec'
5
+ require 'ruby-debug'
5
6
  require 'spec/autorun'
6
7
 
7
8
  Dir[ File.join(File.dirname(__FILE__), 'matchers/*') ].each do |matcher|
@@ -0,0 +1,82 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{unpacker}
8
+ s.version = "0.2.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Petyo Ivanov"]
12
+ s.date = %q{2010-04-02}
13
+ s.default_executable = %q{unpacker}
14
+ s.description = %q{The tool relies on the presence of the command-line tools.}
15
+ s.email = %q{underlog@gmail.com}
16
+ s.executables = ["unpacker"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE",
19
+ "README.rdoc"
20
+ ]
21
+ s.files = [
22
+ ".bnsignore",
23
+ ".document",
24
+ ".gitignore",
25
+ "History.txt",
26
+ "LICENSE",
27
+ "README.rdoc",
28
+ "Rakefile",
29
+ "VERSION",
30
+ "bin/unpacker",
31
+ "lib/unpacker.rb",
32
+ "spec/fixtures/archive-contents/sample-file",
33
+ "spec/fixtures/file.rar",
34
+ "spec/fixtures/file.tar",
35
+ "spec/fixtures/file.tar.bz",
36
+ "spec/fixtures/file.tar.gz",
37
+ "spec/fixtures/file.tbz",
38
+ "spec/fixtures/file.tgz",
39
+ "spec/fixtures/file.zip",
40
+ "spec/fixtures/invalid-file.gz",
41
+ "spec/fixtures/invalid-file.rar",
42
+ "spec/fixtures/invalid-file.tar.gz",
43
+ "spec/fixtures/invalid-file.zip",
44
+ "spec/fixtures/lipsum.txt.gz",
45
+ "spec/matchers/unpacked_correctly.rb",
46
+ "spec/matchers/valid_archive.rb",
47
+ "spec/spec.opts",
48
+ "spec/spec_helper.rb",
49
+ "spec/unpacker_spec.rb",
50
+ "test/test_unpacker.rb",
51
+ "unpacker.gemspec"
52
+ ]
53
+ s.homepage = %q{http://github.com/underlog/unpacker}
54
+ s.rdoc_options = ["--charset=UTF-8"]
55
+ s.require_paths = ["lib"]
56
+ s.rubygems_version = %q{1.3.6}
57
+ s.summary = %q{Abstraction for extracting various archives}
58
+ s.test_files = [
59
+ "spec/matchers/unpacked_correctly.rb",
60
+ "spec/matchers/valid_archive.rb",
61
+ "spec/spec_helper.rb",
62
+ "spec/unpacker_spec.rb",
63
+ "test/test_unpacker.rb"
64
+ ]
65
+
66
+ if s.respond_to? :specification_version then
67
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
68
+ s.specification_version = 3
69
+
70
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
71
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
72
+ s.add_runtime_dependency(%q<shellshot>, [">= 0"])
73
+ else
74
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
75
+ s.add_dependency(%q<shellshot>, [">= 0"])
76
+ end
77
+ else
78
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
79
+ s.add_dependency(%q<shellshot>, [">= 0"])
80
+ end
81
+ end
82
+
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
7
+ - 2
8
8
  - 0
9
- version: 0.1.0
9
+ version: 0.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Petyo Ivanov
@@ -31,6 +31,18 @@ dependencies:
31
31
  version: 1.2.9
32
32
  type: :development
33
33
  version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: shellshot
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ type: :runtime
45
+ version_requirements: *id002
34
46
  description: The tool relies on the presence of the command-line tools.
35
47
  email: underlog@gmail.com
36
48
  executables:
@@ -70,6 +82,7 @@ files:
70
82
  - spec/spec_helper.rb
71
83
  - spec/unpacker_spec.rb
72
84
  - test/test_unpacker.rb
85
+ - unpacker.gemspec
73
86
  has_rdoc: true
74
87
  homepage: http://github.com/underlog/unpacker
75
88
  licenses: []