bincache 0.0.1
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/.document +5 -0
- data/.gitignore +22 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/bin/bincache +20 -0
- data/bincache.gemspec +60 -0
- data/lib/bincache.rb +114 -0
- data/scripts/script1 +2 -0
- data/scripts/script2 +2 -0
- data/scripts/script3 +2 -0
- data/test/helper.rb +10 -0
- data/test/test_bincache.rb +7 -0
- metadata +95 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Martin Rhoads
|
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,17 @@
|
|
1
|
+
= bincache
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
13
|
+
* Send me a pull request. Bonus points for topic branches.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2010 Martin Rhoads. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "bincache"
|
8
|
+
gem.summary = %Q{bines scripts}
|
9
|
+
gem.description = %Q{longer description of your gem}
|
10
|
+
gem.email = "martinrhoads@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/ermal14/bincache"
|
12
|
+
gem.authors = ["Martin Rhoads"]
|
13
|
+
gem.add_development_dependency "right_aws", ">= 0"
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
Jeweler::GemcutterTasks.new
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'rake/testtask'
|
22
|
+
Rake::TestTask.new(:test) do |test|
|
23
|
+
test.libs << 'lib' << 'test'
|
24
|
+
test.pattern = 'test/**/test_*.rb'
|
25
|
+
test.verbose = true
|
26
|
+
end
|
27
|
+
|
28
|
+
begin
|
29
|
+
require 'rcov/rcovtask'
|
30
|
+
Rcov::RcovTask.new do |test|
|
31
|
+
test.libs << 'test'
|
32
|
+
test.pattern = 'test/**/test_*.rb'
|
33
|
+
test.verbose = true
|
34
|
+
end
|
35
|
+
rescue LoadError
|
36
|
+
task :rcov do
|
37
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
task :test => :check_dependencies
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rake/rdoctask'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "bincache #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/bin/bincache
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This is a CLI runner for BinCache
|
4
|
+
#
|
5
|
+
#
|
6
|
+
# bincache dir script1 script2 ... scriptn
|
7
|
+
|
8
|
+
## dev env
|
9
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__)))
|
10
|
+
|
11
|
+
require 'rubygems'
|
12
|
+
require 'bincache'
|
13
|
+
|
14
|
+
dir = ARGV.shift
|
15
|
+
scripts = []
|
16
|
+
ARGV.each { |s| scripts << File.read(s) }
|
17
|
+
b = BinCache.new
|
18
|
+
b.run_series(dir,scripts)
|
19
|
+
|
20
|
+
|
data/bincache.gemspec
ADDED
@@ -0,0 +1,60 @@
|
|
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{bincache}
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Martin Rhoads"]
|
12
|
+
s.date = %q{2010-10-09}
|
13
|
+
s.default_executable = %q{bincache}
|
14
|
+
s.description = %q{longer description of your gem}
|
15
|
+
s.email = %q{martinrhoads@gmail.com}
|
16
|
+
s.executables = ["bincache"]
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"LICENSE",
|
19
|
+
"README.rdoc"
|
20
|
+
]
|
21
|
+
s.files = [
|
22
|
+
".document",
|
23
|
+
".gitignore",
|
24
|
+
"LICENSE",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"bin/bincache",
|
29
|
+
"bincache.gemspec",
|
30
|
+
"lib/bincache.rb",
|
31
|
+
"scripts/script1",
|
32
|
+
"scripts/script2",
|
33
|
+
"scripts/script3",
|
34
|
+
"test/helper.rb",
|
35
|
+
"test/test_bincache.rb"
|
36
|
+
]
|
37
|
+
s.homepage = %q{http://github.com/ermal14/bincache}
|
38
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
39
|
+
s.require_paths = ["lib"]
|
40
|
+
s.rubygems_version = %q{1.3.7}
|
41
|
+
s.summary = %q{bines scripts}
|
42
|
+
s.test_files = [
|
43
|
+
"test/helper.rb",
|
44
|
+
"test/test_bincache.rb"
|
45
|
+
]
|
46
|
+
|
47
|
+
if s.respond_to? :specification_version then
|
48
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
49
|
+
s.specification_version = 3
|
50
|
+
|
51
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
52
|
+
s.add_development_dependency(%q<right_aws>, [">= 0"])
|
53
|
+
else
|
54
|
+
s.add_dependency(%q<right_aws>, [">= 0"])
|
55
|
+
end
|
56
|
+
else
|
57
|
+
s.add_dependency(%q<right_aws>, [">= 0"])
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
data/lib/bincache.rb
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
#!/bin/env ruby
|
2
|
+
|
3
|
+
require 'digest/md5'
|
4
|
+
require 'rubygems'
|
5
|
+
require 'right_aws'
|
6
|
+
|
7
|
+
class BinCache
|
8
|
+
|
9
|
+
def initialize()
|
10
|
+
@bucket = 'devs-us-west'
|
11
|
+
@prefix = 'martin/bincache/'
|
12
|
+
@download_dir = '/private/tmp'
|
13
|
+
|
14
|
+
print_and_exit "s3 keys not set. Please let S3_ACCESS_KEY and S3_SECRET__KEY" unless ENV['S3_ACCESS_KEY'] && ENV['S3_SECRET__KEY']
|
15
|
+
|
16
|
+
@right_s3 = RightAws::S3.new(ENV['S3_ACCESS_KEY'],ENV['S3_SECRET__KEY'])
|
17
|
+
@right_s3_bucket = @right_s3.bucket(@bucket)
|
18
|
+
@right_s3_interface = RightAws::S3Interface.new(ENV['S3_ACCESS_KEY'],ENV['S3_SECRET__KEY'])
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
def bincache(script,dir)
|
23
|
+
script_hash = Digest::MD5.hexdigest(script)
|
24
|
+
end
|
25
|
+
|
26
|
+
def run_series(directory, scripts)
|
27
|
+
## exit if given bogus input
|
28
|
+
print_and_exit "bogus input in run_series" if directory.nil? || scripts.nil?
|
29
|
+
|
30
|
+
## clear out directory if we are starting a new sequence
|
31
|
+
`rm -rf #{directory} && mkdir -p #{directory}` && return if scripts.empty?
|
32
|
+
|
33
|
+
## hash the scripts
|
34
|
+
hash = Digest::MD5.hexdigest(scripts.inspect)
|
35
|
+
|
36
|
+
## pop the last script
|
37
|
+
pop = scripts.pop
|
38
|
+
|
39
|
+
## recurse if we have not ran this script yet
|
40
|
+
eval("#{__method__}(directory,scripts)") unless check_for_hash?(hash)
|
41
|
+
|
42
|
+
## step this script
|
43
|
+
step(pop,directory,hash)
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
def check_for_hash?(hash)
|
48
|
+
key = RightAws::S3::Key.create( @right_s3_bucket, "#{@prefix}#{hash}" )
|
49
|
+
key.exists?
|
50
|
+
end
|
51
|
+
|
52
|
+
def step(script,directory,hash)
|
53
|
+
if download_hash? hash
|
54
|
+
`rm -rf #{directory}`
|
55
|
+
`cd #{File.dirname directory} && tar -xzvf #{File.join(@download_dir,hash)} `
|
56
|
+
else
|
57
|
+
`mkdir -p #{directory}`
|
58
|
+
Dir.chdir directory
|
59
|
+
res = `#{script}`
|
60
|
+
`cd #{File.dirname directory} && tar -czvf #{@download_dir}/#{hash} #{File.basename directory} `
|
61
|
+
upload_file("#{@download_dir}/#{hash}")
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
## IO.popen 'tar cfz -', 'w+' do |pipe|
|
68
|
+
|
69
|
+
def upload_file(file)
|
70
|
+
key_name = @prefix.dup
|
71
|
+
key_name << File.basename(file)
|
72
|
+
@right_s3_interface.put(@bucket, key_name , File.read(file) )
|
73
|
+
end
|
74
|
+
|
75
|
+
def download_hash?(hash)
|
76
|
+
begin
|
77
|
+
File.open(File.join(@download_dir,hash) , 'w') {|f| f.write( @right_s3_interface.get_object(@bucket, "#{@prefix}#{hash}") ) }
|
78
|
+
rescue
|
79
|
+
return false
|
80
|
+
end
|
81
|
+
true
|
82
|
+
end
|
83
|
+
|
84
|
+
## This function will compute a recursive md5 hash of a given directory (may be releative)
|
85
|
+
## directory names are taken into consideration
|
86
|
+
## the full path is taken into consideration
|
87
|
+
def recurse_and_hash_tree(node)
|
88
|
+
|
89
|
+
## exit program if given a bunk file/dir
|
90
|
+
print_and_exit "given a bunk file/node" unless File.exist? node
|
91
|
+
|
92
|
+
## if we have a file then return it's hash
|
93
|
+
return Digest::MD5.hexdigest( node + File.read(node) ) if File.file? node
|
94
|
+
|
95
|
+
## we should have a directory now. exit otherwise...
|
96
|
+
print_and_exit "is there a strange device in this dir?" unless File.directory? node
|
97
|
+
|
98
|
+
## recurse through each element in the directory and remember their hashes
|
99
|
+
children_hash = ""
|
100
|
+
Dir.glob(File.join node, '*' ) { |element| children_hash << recurse_and_hash_tree(element) }
|
101
|
+
|
102
|
+
## return the mashed up hash
|
103
|
+
return Digest::MD5.hexdigest( node + children_hash )
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
def print_and_exit(message)
|
108
|
+
STDERR.puts "cought an error in bincache"
|
109
|
+
STDERR.puts message
|
110
|
+
Kernel.exit 1
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
|
data/scripts/script1
ADDED
data/scripts/script2
ADDED
data/scripts/script3
ADDED
data/test/helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bincache
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Martin Rhoads
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-10-09 00:00:00 -07:00
|
19
|
+
default_executable: bincache
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: right_aws
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
35
|
+
description: longer description of your gem
|
36
|
+
email: martinrhoads@gmail.com
|
37
|
+
executables:
|
38
|
+
- bincache
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- LICENSE
|
43
|
+
- README.rdoc
|
44
|
+
files:
|
45
|
+
- .document
|
46
|
+
- .gitignore
|
47
|
+
- LICENSE
|
48
|
+
- README.rdoc
|
49
|
+
- Rakefile
|
50
|
+
- VERSION
|
51
|
+
- bin/bincache
|
52
|
+
- bincache.gemspec
|
53
|
+
- lib/bincache.rb
|
54
|
+
- scripts/script1
|
55
|
+
- scripts/script2
|
56
|
+
- scripts/script3
|
57
|
+
- test/helper.rb
|
58
|
+
- test/test_bincache.rb
|
59
|
+
has_rdoc: true
|
60
|
+
homepage: http://github.com/ermal14/bincache
|
61
|
+
licenses: []
|
62
|
+
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options:
|
65
|
+
- --charset=UTF-8
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
hash: 3
|
74
|
+
segments:
|
75
|
+
- 0
|
76
|
+
version: "0"
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
hash: 3
|
83
|
+
segments:
|
84
|
+
- 0
|
85
|
+
version: "0"
|
86
|
+
requirements: []
|
87
|
+
|
88
|
+
rubyforge_project:
|
89
|
+
rubygems_version: 1.3.7
|
90
|
+
signing_key:
|
91
|
+
specification_version: 3
|
92
|
+
summary: bines scripts
|
93
|
+
test_files:
|
94
|
+
- test/helper.rb
|
95
|
+
- test/test_bincache.rb
|