auser-suitcase 0.0.2

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.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Ari Lerner
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,31 @@
1
+ = Suitcase
2
+
3
+ Easy-peasy transfer of bulk files with the Suitcase!
4
+
5
+ Suitcase takes care of the ugly work for you when dealing with lots of dependencies and and peculiarities with transferring dependencies.
6
+
7
+ == Simple case:
8
+
9
+ Suitcase::Zipper.add("file_to_transfer.txt")
10
+ Suitcase::Zipper.add("directory_to_transfer/")
11
+
12
+ Suitcase::Zipper.zip!("/full/path/to/filename.tar.gz") # => "/full/path/to/filename.tar.gz"
13
+
14
+ == Suitcase will download the latest gems for you and add them to the suitcase simply by calling
15
+
16
+ Suitcase::Zipper.gems "auser-poolparty", "nanite", ...
17
+
18
+ It first attempts to download it from github and then falls back and tries with rubyforge.
19
+
20
+ They are added to the suitcase under the gems/ namespace.
21
+
22
+ == Suitcase will download packages for you off the internet as well given a source, for instance:
23
+
24
+ Suitcase::Zipper.packages("ftp://ftp.ruby-lang.org/pub/ruby/stable-snapshot.tar.gz", "#{Dir.pwd}/packages")
25
+
26
+ will download the ruby stable-snapshot.tar.gz and put it into the suitcase
27
+
28
+
29
+ == Copyright
30
+
31
+ Copyright (c) 2009 Ari Lerner. See LICENSE for details.
data/VERSION.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ :major: 0
3
+ :minor: 0
4
+ :patch: 2
data/lib/suitcase.rb ADDED
@@ -0,0 +1,5 @@
1
+ $:.unshift(File.join(File.dirname(__FILE__), "suitcase"))
2
+
3
+ %w(zipper unzipper).each do |lib|
4
+ require lib
5
+ end
@@ -0,0 +1,15 @@
1
+ require 'rubygems'
2
+ require "zlib"
3
+ require 'archive/tar/minitar'
4
+
5
+ module Suitcase
6
+ class UnZipper
7
+
8
+ # TODO: Add a meaningful, portable unzip!
9
+ def self.unzip!(filepath, to=Dir.pwd)
10
+ # tgz = Zlib::GzipReader.new(File.open(filepath, 'rb'))
11
+ # Archive::Tar::Minitar.unpack( tgz, to )
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,103 @@
1
+ require 'rubygems'
2
+ require 'archive/tar/minitar'
3
+
4
+ module Suitcase
5
+ class Zipper
6
+
7
+ def self.items(default_dirs={})
8
+ @items ||= default_dirs
9
+ end
10
+
11
+ def self.zip!(filepath)
12
+ filepath = filepath.include?(".tar.gz") ? filepath : "#{filepath}.tar.gz"
13
+ File.open(filepath,"w") do |tarfile|
14
+ Archive::Tar::Minitar::Writer.open(tarfile) do |tar|
15
+ items.each do |name, path|
16
+ data = open(path).read
17
+ tar.add_file_simple(name, :size=>data.size, :mode=>0644) { |f| f.write(data) }
18
+ end
19
+ end
20
+ end
21
+ filepath
22
+ end
23
+
24
+ def self.build_dir!(dirpath)
25
+ ::FileUtils.mkdir_p dirpath unless ::File.directory? dirpath
26
+ items.each do |name, path|
27
+ end_path = "#{dirpath}/#{name}"
28
+ unless name == ::File.basename(name)
29
+ ::FileUtils.mkdir_p ::File.dirname(end_path) unless ::File.directory? ::File.dirname(end_path)
30
+ end
31
+ ::FileUtils.cp path, end_path
32
+ end
33
+ dirpath
34
+ end
35
+
36
+ def self.flush!
37
+ @items = nil
38
+ end
39
+
40
+ def self.add(files_and_directories=[], namespace="")
41
+ files_and_directories.each do |file|
42
+ f = ::File.expand_path(file)
43
+ if ::File.file? f
44
+ items.merge!(("#{namespace}/#{::File.basename(f)}").to_s => f)
45
+ elsif ::File.directory? f
46
+ Dir["#{f}/*"].each do |f|
47
+ add(f, "#{namespace.empty? ? "" : "#{namespace}/"}#{::File.basename(::File.dirname(f))}")
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+ def self.gems(gem_list, gem_location)
54
+ require 'rubygems/dependency_installer'
55
+ gem_list = [gem_list] unless gem_list.is_a?(Array)
56
+ ensure_location_exists gem_location
57
+
58
+ cache_dir = "#{gem_location}/cache"
59
+ ::FileUtils.mkdir_p cache_dir rescue nil unless File.exist? cache_dir
60
+
61
+ locally_installed_gems = Gem::SourceIndex.from_installed_gems.map {|n,s| s.name }
62
+
63
+ locally_installable_gems = gem_list & locally_installed_gems
64
+ remotely_installable = gem_list - locally_installable_gems
65
+
66
+ # First, add the locally installed gems
67
+ locally_installable_gems.each do |spec|
68
+ spec = Gem::SourceIndex.from_installed_gems.find_name(spec).last#.sort_by {|a,b| a.version <=> b.version }.last
69
+ f = Dir[File.join(Gem.dir, 'cache', "#{spec.full_name}.gem")].first
70
+ add(f, "gems")
71
+ end
72
+
73
+ remotely_installable.each do |g|
74
+ di = Gem::DependencyInstaller.new
75
+ spec, url = di.find_spec_by_name_and_version(g).first
76
+ f = begin
77
+ Gem::RemoteFetcher.fetcher.download spec, "http://gems.github.com", gem_location
78
+ rescue Exception => e
79
+ Gem::RemoteFetcher.fetcher.download spec, url, gem_location
80
+ end
81
+ add(f, "gems")
82
+ end
83
+ end
84
+
85
+ def self.packages(package_list, package_location="#{Dir.pwd}/packages")
86
+ ensure_location_exists package_location
87
+ package_list.each do |package|
88
+ f = "#{package_location}/#{package.split('/').last}"
89
+ unless ::File.file? f
90
+ puts "downloading #{package} to #{f}"
91
+ `curl -L #{package} > #{package_location}/#{package.split('/').last}`
92
+ end
93
+
94
+ add(f, "packages")
95
+ end
96
+ end
97
+
98
+ def self.ensure_location_exists(loc)
99
+ ::FileUtils.mkdir_p loc unless ::File.directory? loc
100
+ end
101
+
102
+ end
103
+ end
@@ -0,0 +1,89 @@
1
+ require 'test_helper'
2
+
3
+ class DependenciesTest < Test::Unit::TestCase
4
+ context "basics" do
5
+ should "should have a method called dedependencies" do
6
+ assert Suitcase::Zipper.respond_to?(:items)
7
+ end
8
+ should "should have a package(file) method" do
9
+ assert Suitcase::Zipper.respond_to?(:add)
10
+ end
11
+ end
12
+ context "adding gems" do
13
+ before do
14
+ Suitcase::Zipper.flush!
15
+ end
16
+ should "should have no gems before any are added" do
17
+ assert_equal Suitcase::Zipper.items.size, 0
18
+ assert_equal Suitcase::Zipper.items.class, Hash
19
+ end
20
+ should "be able to add files to the suitcase" do
21
+ Suitcase::Zipper.add("#{::File.dirname(__FILE__)}/test_helper.rb")
22
+ assert_equal Suitcase::Zipper.items.size, 1
23
+ end
24
+ should "be able to add directories to the suitcase" do
25
+ Suitcase::Zipper.add("#{::File.dirname(__FILE__)}/test_dir")
26
+ assert_equal Suitcase::Zipper.items.size, 2
27
+ assert Suitcase::Zipper.items["test_dir/box.rb"] =~ /test_dir\/box\.rb/
28
+ end
29
+ should "be able to add directories into namespaces" do
30
+ Suitcase::Zipper.add("#{::File.dirname(__FILE__)}/test_dir", "box")
31
+ assert Suitcase::Zipper.items["box/test_dir/box.rb"] =~ /test_dir\/box\.rb/
32
+ end
33
+ # UNCOMMENT THESE TO LIVE-TEST THE USAGE
34
+ should "be able to add gems to the suitcase" do
35
+ Suitcase::Zipper.gems("rake", Dir.pwd)
36
+ Suitcase::Zipper.build_dir! "#{Dir.pwd}/cache"
37
+ assert ::File.file?(::File.expand_path("#{Dir.pwd}/cache/gems/rake-0.8.4.gem"))
38
+ end
39
+ should "find the gem online if it is not locally installed" do
40
+ Suitcase::Zipper.gems("aaronp-meow", Dir.pwd)
41
+ assert ::File.file?(::File.expand_path("#{Dir.pwd}/cache/aaronp-meow-1.1.0.gem"))
42
+ end
43
+ # should "be able to add packages to the suitcase" do
44
+ # Suitcase::Zipper.packages("ftp://ftp.ruby-lang.org/pub/ruby/stable-snapshot.tar.gz", "#{Dir.pwd}/packages")
45
+ # assert_equal Suitcase::Zipper.items["packages/stable-snapshot.tar.gz"], ::File.expand_path("packages/stable-snapshot.tar.gz")
46
+ # end
47
+ should "zip the packages into a tarball without the extension" do
48
+ filepath = "#{::File.dirname(__FILE__)}/package"
49
+ Suitcase::Zipper.add("test_dir")
50
+ Suitcase::Zipper.add("test_helper.rb")
51
+ Suitcase::Zipper.zip!(filepath)
52
+ assert ::File.file?("#{filepath}.tar.gz")
53
+ end
54
+ should "zip the packages into a tarball with the extension" do
55
+ filepath = "#{::File.dirname(__FILE__)}/package.tar.gz"
56
+ Suitcase::Zipper.add("test_dir")
57
+ Suitcase::Zipper.add("test_helper.rb")
58
+ Suitcase::Zipper.zip!(filepath)
59
+ assert ::File.file?("#{filepath}")
60
+ end
61
+ should "be able to unpack the packages" do
62
+ filepath = "#{::File.dirname(__FILE__)}/package.tar.gz"
63
+ Suitcase::Zipper.add("test_dir")
64
+ Suitcase::Zipper.add("test_helper.rb")
65
+ Suitcase::Zipper.zip!(filepath)
66
+
67
+ Suitcase::UnZipper.unzip!(filepath, "#{Dir.pwd}")
68
+ assert ::File.directory?("#{::File.dirname(filepath)}")
69
+ end
70
+ should "have a method called build_dir!" do
71
+ assert Suitcase::Zipper.respond_to?(:build_dir!)
72
+ end
73
+ should "call build_dir" do
74
+ Suitcase::Zipper.add("test_dir")
75
+ Suitcase::Zipper.add("test_helper.rb")
76
+
77
+ pth = Suitcase::Zipper.build_dir!("/tmp/poolparty/deps")
78
+
79
+ assert ::File.directory?("/tmp/poolparty/deps")
80
+ assert_equal pth, "/tmp/poolparty/deps"
81
+ ::FileUtils.rm_rf "/tmp/poolparty/deps"
82
+ end
83
+ after do
84
+ ::FileUtils.rm_rf "#{Dir.pwd}/packages"
85
+ ::FileUtils.rm_rf "#{Dir.pwd}/cache"
86
+ ::FileUtils.rm_rf "#{Dir.pwd}/package.tar.gz"
87
+ end
88
+ end
89
+ end
@@ -0,0 +1 @@
1
+ puts "I'm in a box!"
@@ -0,0 +1 @@
1
+ Test txt file
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+ require "context"
5
+
6
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
7
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
8
+ require 'suitcase/zipper'
9
+ require 'suitcase/unzipper'
10
+
11
+ class Test::Unit::TestCase
12
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: auser-suitcase
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Ari Lerner
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-04-08 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: arilerner@mac.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.rdoc
24
+ - LICENSE
25
+ files:
26
+ - README.rdoc
27
+ - VERSION.yml
28
+ - lib/suitcase
29
+ - lib/suitcase/unzipper.rb
30
+ - lib/suitcase/zipper.rb
31
+ - lib/suitcase.rb
32
+ - test/suitcase_test.rb
33
+ - test/test_dir
34
+ - test/test_dir/box.rb
35
+ - test/test_dir/test.txt
36
+ - test/test_helper.rb
37
+ - LICENSE
38
+ has_rdoc: true
39
+ homepage: http://github.com/auser/suitcase
40
+ post_install_message:
41
+ rdoc_options:
42
+ - --inline-source
43
+ - --charset=UTF-8
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: "0"
51
+ version:
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ requirements: []
59
+
60
+ rubyforge_project:
61
+ rubygems_version: 1.2.0
62
+ signing_key:
63
+ specification_version: 2
64
+ summary: TODO
65
+ test_files: []
66
+