yore 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.
@@ -0,0 +1,187 @@
1
+ require 'rubygems'
2
+ gem 'RequirePaths'; require 'require_paths'
3
+ require_paths '../../..'
4
+
5
+ require 'ihl_ruby/misc_utils'
6
+
7
+ require 'fileutils'
8
+
9
+ require 'yore_core'
10
+
11
+ def ensure_clean_bucket(aName)
12
+ `s3cmd createbucket #{aName}`
13
+ `s3cmd deleteall #{aName}`
14
+ end
15
+
16
+ describe YoreCore::Yore do
17
+ before(:each) do
18
+ @yore = YoreCore::Yore.new
19
+ end
20
+
21
+ it "should collect a list of files into a single file with a .contents file" do
22
+ # create a temp dir
23
+ temp_dir = MiscUtils::make_temp_dir('yore_spec')
24
+ # create source and dest subfolders
25
+ source_dir = File.expand_path('source',temp_dir)
26
+ dest_dir = File.expand_path('dest',temp_dir)
27
+ FileUtils.mkdir_p([source_dir,dest_dir])
28
+ # create some dirs and files in source
29
+ ['a','a/1','b','c'].each {|p| FileUtils.mkdir_p(File.expand_path(p,source_dir))}
30
+ %w(a/blah.txt a/1/blahblah.txt b/apples.txt c/carrots.txt).each do |f|
31
+ MiscUtils::make_temp_file(f,source_dir)
32
+ end
33
+ # collect into dest file
34
+ # get recursive file list, without carrots
35
+ filelist = MiscUtils::recursive_file_list(source_dir) {|p| not p =~ /carrots.txt/}
36
+ dest_file = File.join(dest_dir,'destfile.bzb')
37
+
38
+ @yore.collect(filelist,dest_file)
39
+
40
+ # check contains filelist files ignoring .contents
41
+ cmd = "tar --list --file=#{dest_file}"
42
+ filelist_out = `#{cmd}`
43
+ i = 0
44
+ filelist_out.each_line {|line|
45
+ next if line==".contents\n"
46
+ i.should < filelist.length
47
+ line.chomp("\n").should == MiscUtils.path_debase(filelist[i],source_dir) # .bite('/')
48
+ i += 1
49
+ }
50
+ # could also check .contents file against actual contents
51
+ end
52
+
53
+ it "should encrypt and unencrypt a file with a standard iv but a supplied key" do
54
+ orig_content = 'abcdef123456'
55
+ temp_file1 = MiscUtils.make_temp_file(nil,nil,orig_content)
56
+ temp_file2 = temp_file1+'.enc'
57
+ temp_file3 = temp_file1+'.dec'
58
+
59
+ @yore.pack(temp_file1,temp_file2)
60
+ @yore.unpack(temp_file2,temp_file3)
61
+
62
+ file3_content = MiscUtils.string_from_file(temp_file3)
63
+ file3_content.should == orig_content
64
+ end
65
+
66
+ it "should create a backup filename combining a prefix, date, day and standard extension, and be able to decode the filename back to a date" do
67
+ @yore.configure({
68
+ :prefix => 'spec',
69
+ :first_hour => 4
70
+ })
71
+ now = Time.local(2009, 1, 1, 0, 0, 0, 0)
72
+ exp_filename = "spec-20081231.rew"
73
+ calc_filename = @yore.encode_file_name(now)
74
+ calc_filename.should == exp_filename
75
+ @yore.decode_file_name(calc_filename).should == Time.local(2008, 12, 31)
76
+ end
77
+
78
+ it "should upload and download files intact" do
79
+ bucket = 'yore_spec'
80
+ ensure_clean_bucket(bucket)
81
+ @yore.configure({
82
+ :bucket => bucket
83
+ })
84
+ content = 'this is my test content'
85
+ temp_dir = MiscUtils.make_temp_dir()
86
+ temp_file = MiscUtils.make_temp_file(nil, temp_dir, content)
87
+ puts @yore.upload(temp_file)
88
+ orig_file = temp_file+'.orig'
89
+ File.rename(temp_file, orig_file)
90
+ puts @yore.download(temp_file)
91
+ down_file_content = MiscUtils.string_from_file(temp_file)
92
+ down_file_content.should == content
93
+ end
94
+
95
+ it "should backup and restore multiple directories of file" do
96
+ # create a temp dir
97
+ temp_dir = MiscUtils::make_temp_dir('yore_spec')
98
+ # create source and dest subfolders
99
+ source_dir = File.expand_path('source',temp_dir)
100
+ source1 = File.join(source_dir,'source1')
101
+ source2 = File.join(source_dir,'source2')
102
+ dest_dir = File.expand_path('dest',temp_dir)
103
+ bucket = 'yore_spec'
104
+
105
+ FileUtils.mkdir_p([source1,source2,dest_dir])
106
+ # create some dirs and files in source
107
+ ['a','a/1','b','c'].each {|p| FileUtils.mkdir_p(File.expand_path(p,source1))}
108
+ %w(a/blah.txt a/1/blahblah.txt b/apples.txt c/carrots.txt).each do |f|
109
+ MiscUtils::make_temp_file(f,source1)
110
+ end
111
+ ['w','x/1','y/2','z'].each {|p| FileUtils.mkdir_p(File.expand_path(p,source2))}
112
+ %w(w/zonk.txt x/1/eggs.txt y/2/bloop.txt z/zax.txt).each do |f|
113
+ MiscUtils::make_temp_file(f,source2)
114
+ end
115
+
116
+ # create job file
117
+ job_template = <<EOF
118
+ <?xml version="1.0" encoding="UTF-8"?>
119
+ <Yore>
120
+ <SimpleItems>
121
+ <Item Name="crypto_iv">3A63775C1E3F291B0925578165EB917E</Item>
122
+ <Item Name="crypto_key">07692FC8656F04AE5518B80D38681E038A3C12050DF6CC97CEEC33D800D5E2FE</Item>
123
+ <Item Name="prefix">backup</Item>
124
+ <Item Name="log_level">DEBUG</Item>
125
+ <Item Name="bucket">${BUCKET}</Item>
126
+ </SimpleItems>
127
+ <Sources>
128
+ <Source>
129
+ <IncludePath>${SOURCE1}</IncludePath>
130
+ <IncludePath>${SOURCE2}</IncludePath>
131
+ </Source>
132
+ </Sources>
133
+ </Yore>
134
+ EOF
135
+
136
+ job_content = StringUtils::render_template(job_template,{
137
+ 'SOURCE1' => source1,
138
+ 'SOURCE2' => source2,
139
+ 'BUCKET' => bucket
140
+ })
141
+ MiscUtils::string_to_file(job_content,job_file = MiscUtils::temp_file)
142
+
143
+ ensure_clean_bucket(bucket)
144
+ @yore.configure({
145
+ :bucket => bucket
146
+ })
147
+
148
+ # call yore script with ruby from the command line, then download result and check contents
149
+ puts cmd = "#{File.expand_path('../lib/yore',THIS_DIR)} backup #{job_file}"
150
+ puts result = `#{cmd}`
151
+
152
+ retrieved_fname = File.expand_path(@yore.encode_file_name(), dest_dir)
153
+ collection_fname = MiscUtils::temp_file
154
+
155
+ puts @yore.download(retrieved_fname)
156
+ puts @yore.unpack(retrieved_fname,collection_fname)
157
+
158
+ filelist = MiscUtils::recursive_file_list(source_dir,false)
159
+
160
+ # check contains filelist files ignoring .contents
161
+ cmd = "tar --list --file=#{collection_fname}"
162
+ filelist_out = `#{cmd}`
163
+ filelist_out = filelist_out.split("\n").sort
164
+ filelist_out.should == filelist
165
+ # i = 0
166
+ # filelist_out.each {|line|
167
+ # next if line==".contents\n"
168
+ # i.should < filelist.length
169
+ # line.chomp("\n").should == MiscUtils.path_debase(filelist[i],source_dir) # .bite('/')
170
+ # i += 1
171
+ # }
172
+ # could also check .contents file against actual contents
173
+ end
174
+
175
+ it "should assign proper boolean values" do
176
+ class Blah
177
+ SOMECONSTANT = {:a => 'AAA', :b => true, :c => false}
178
+ end
179
+
180
+ puts Blah::SOMECONSTANT.inspect
181
+ end
182
+
183
+ it "should provide configurable criteria for keeping old files"
184
+
185
+ it "should clean a folder full of files, removing files that don't match configurable criteria for keeping old files"
186
+ end
187
+
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --colour
@@ -0,0 +1,10 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ gem 'rspec'
6
+ require 'spec'
7
+ end
8
+
9
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
10
+ require 'yore'
@@ -0,0 +1,19 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Yore>
3
+ <SimpleItems>
4
+ <Item Name="keep_daily">14</Item>
5
+ <Item Name="keep_weekly">12</Item>
6
+ <Item Name="keep_monthly">12</Item>
7
+ <Item Name="crypto_iv">3A63775C1E3F291B0925578165EB917E</Item>
8
+ <Item Name="crypto_key">07692FC8656F04AE5518B80D38681E038A3C12050DF6CC97CEEC33D800D5E2FE</Item>
9
+ <Item Name="first_hour">4</Item>
10
+ <Item Name="prefix">backup</Item>
11
+ <Item Name="log_level">DEBUG</Item>
12
+ </SimpleItems>
13
+ <Sources>
14
+ <Source>
15
+ <IncludePath>test_source</IncludePath>
16
+ <!-- <ExcludePath></ExcludePath> -->
17
+ </Source>
18
+ </Sources>
19
+ </Yore>
data/spec/yore_spec.rb ADDED
@@ -0,0 +1,199 @@
1
+ require 'rubygems'
2
+ require File.dirname(__FILE__) + '/spec_helper.rb'
3
+
4
+ gem 'RequirePaths'; require 'require_paths'
5
+ require_paths '../lib','../../..'
6
+
7
+
8
+ ## Time to add your specs!
9
+ # http://rspec.info/
10
+ #describe "Place your specs here" do
11
+ #
12
+ # it "find this spec in spec directory" do
13
+ # violated "Be sure to write your specs"
14
+ # end
15
+ #end
16
+
17
+ require 'ihl_ruby/misc_utils'
18
+
19
+ require 'fileutils'
20
+
21
+ require 'yore/yore_core'
22
+
23
+ def ensure_clean_bucket(aName)
24
+ `s3cmd createbucket #{aName}`
25
+ `s3cmd deleteall #{aName}`
26
+ end
27
+
28
+ describe YoreCore::Yore do
29
+ before(:each) do
30
+ @yore = YoreCore::Yore.new
31
+ end
32
+
33
+ it "should collect a list of files into a single file with a .contents file" do
34
+ # create a temp dir
35
+ temp_dir = MiscUtils::make_temp_dir('yore_spec')
36
+ # create source and dest subfolders
37
+ source_dir = File.expand_path('source',temp_dir)
38
+ dest_dir = File.expand_path('dest',temp_dir)
39
+ FileUtils.mkdir_p([source_dir,dest_dir])
40
+ # create some dirs and files in source
41
+ ['a','a/1','b','c'].each {|p| FileUtils.mkdir_p(File.expand_path(p,source_dir))}
42
+ %w(a/blah.txt a/1/blahblah.txt b/apples.txt c/carrots.txt).each do |f|
43
+ MiscUtils::make_temp_file(f,source_dir)
44
+ end
45
+ # collect into dest file
46
+ # get recursive file list, without carrots
47
+ filelist = MiscUtils::recursive_file_list(source_dir) {|p| not p =~ /carrots.txt/}
48
+ dest_file = File.join(dest_dir,'destfile.bzb')
49
+
50
+ @yore.collect(filelist,dest_file)
51
+
52
+ # check contains filelist files ignoring .contents
53
+ cmd = "tar --list --file=#{dest_file}"
54
+ filelist_out = `#{cmd}`
55
+ i = 0
56
+ filelist_out.each_line {|line|
57
+ next if line==".contents\n"
58
+ i.should < filelist.length
59
+ line.chomp("\n").should == MiscUtils.path_debase(filelist[i],source_dir) # .bite('/')
60
+ i += 1
61
+ }
62
+ # could also check .contents file against actual contents
63
+ end
64
+
65
+ it "should encrypt and unencrypt a file with a standard iv but a supplied key" do
66
+ orig_content = 'abcdef123456'
67
+ temp_file1 = MiscUtils.make_temp_file(nil,nil,orig_content)
68
+ temp_file2 = temp_file1+'.enc'
69
+ temp_file3 = temp_file1+'.dec'
70
+
71
+ @yore.pack(temp_file1,temp_file2)
72
+ @yore.unpack(temp_file2,temp_file3)
73
+
74
+ file3_content = MiscUtils.string_from_file(temp_file3)
75
+ file3_content.should == orig_content
76
+ end
77
+
78
+ it "should create a backup filename combining a prefix, date, day and standard extension, and be able to decode the filename back to a date" do
79
+ @yore.configure({
80
+ :prefix => 'spec',
81
+ :first_hour => 4
82
+ })
83
+ now = Time.local(2009, 1, 1, 0, 0, 0, 0)
84
+ exp_filename = "spec-20081231.rew"
85
+ calc_filename = @yore.encode_file_name(now)
86
+ calc_filename.should == exp_filename
87
+ @yore.decode_file_name(calc_filename).should == Time.local(2008, 12, 31)
88
+ end
89
+
90
+ it "should upload and download files intact" do
91
+ bucket = 'yore_spec'
92
+ ensure_clean_bucket(bucket)
93
+ @yore.configure({
94
+ :bucket => bucket
95
+ })
96
+ content = 'this is my test content'
97
+ temp_dir = MiscUtils.make_temp_dir()
98
+ temp_file = MiscUtils.make_temp_file(nil, temp_dir, content)
99
+ puts @yore.upload(temp_file)
100
+ orig_file = temp_file+'.orig'
101
+ File.rename(temp_file, orig_file)
102
+ puts @yore.download(temp_file)
103
+ down_file_content = MiscUtils.string_from_file(temp_file)
104
+ down_file_content.should == content
105
+ end
106
+
107
+ it "should backup and restore multiple directories of file" do
108
+ # create a temp dir
109
+ temp_dir = MiscUtils::make_temp_dir('yore_spec')
110
+ # create source and dest subfolders
111
+ source_dir = File.expand_path('source',temp_dir)
112
+ source1 = File.join(source_dir,'source1')
113
+ source2 = File.join(source_dir,'source2')
114
+ dest_dir = File.expand_path('dest',temp_dir)
115
+ bucket = 'yore_spec'
116
+
117
+ FileUtils.mkdir_p([source1,source2,dest_dir])
118
+ # create some dirs and files in source
119
+ ['a','a/1','b','c'].each {|p| FileUtils.mkdir_p(File.expand_path(p,source1))}
120
+ %w(a/blah.txt a/1/blahblah.txt b/apples.txt c/carrots.txt).each do |f|
121
+ MiscUtils::make_temp_file(f,source1)
122
+ end
123
+ ['w','x/1','y/2','z'].each {|p| FileUtils.mkdir_p(File.expand_path(p,source2))}
124
+ %w(w/zonk.txt x/1/eggs.txt y/2/bloop.txt z/zax.txt).each do |f|
125
+ MiscUtils::make_temp_file(f,source2)
126
+ end
127
+
128
+ # create job file
129
+ job_template = <<EOF
130
+ <?xml version="1.0" encoding="UTF-8"?>
131
+ <Yore>
132
+ <SimpleItems>
133
+ <Item Name="crypto_iv">3A63775C1E3F291B0925578165EB917E</Item>
134
+ <Item Name="crypto_key">07692FC8656F04AE5518B80D38681E038A3C12050DF6CC97CEEC33D800D5E2FE</Item>
135
+ <Item Name="prefix">backup</Item>
136
+ <Item Name="log_level">DEBUG</Item>
137
+ <Item Name="bucket">${BUCKET}</Item>
138
+ </SimpleItems>
139
+ <Sources>
140
+ <Source>
141
+ <IncludePath>${SOURCE1}</IncludePath>
142
+ <IncludePath>${SOURCE2}</IncludePath>
143
+ </Source>
144
+ </Sources>
145
+ </Yore>
146
+ EOF
147
+
148
+ job_content = StringUtils::render_template(job_template,{
149
+ 'SOURCE1' => source1,
150
+ 'SOURCE2' => source2,
151
+ 'BUCKET' => bucket
152
+ })
153
+ MiscUtils::string_to_file(job_content,job_file = MiscUtils::temp_file)
154
+
155
+ ensure_clean_bucket(bucket)
156
+ @yore.configure({
157
+ :bucket => bucket
158
+ })
159
+
160
+ # call yore script with ruby from the command line, then download result and check contents
161
+ puts cmd = "ruby #{File.expand_path('../bin/yore.rb',THIS_DIR)} backup #{job_file}"
162
+ puts result = `#{cmd}`
163
+
164
+ retrieved_fname = File.expand_path(@yore.encode_file_name(), dest_dir)
165
+ collection_fname = MiscUtils::temp_file
166
+
167
+ puts @yore.download(retrieved_fname)
168
+ puts @yore.unpack(retrieved_fname,collection_fname)
169
+
170
+ filelist = MiscUtils::recursive_file_list(source_dir,false)
171
+
172
+ # check contains filelist files ignoring .contents
173
+ cmd = "tar --list --file=#{collection_fname}"
174
+ filelist_out = `#{cmd}`
175
+ filelist_out = filelist_out.split("\n").sort
176
+ filelist_out.should == filelist
177
+ # i = 0
178
+ # filelist_out.each {|line|
179
+ # next if line==".contents\n"
180
+ # i.should < filelist.length
181
+ # line.chomp("\n").should == MiscUtils.path_debase(filelist[i],source_dir) # .bite('/')
182
+ # i += 1
183
+ # }
184
+ # could also check .contents file against actual contents
185
+ end
186
+
187
+ it "should assign proper boolean values" do
188
+ class Blah
189
+ SOMECONSTANT = {:a => 'AAA', :b => true, :c => false}
190
+ end
191
+
192
+ puts Blah::SOMECONSTANT.inspect
193
+ end
194
+
195
+
196
+ it "should provide configurable criteria for keeping old files"
197
+
198
+ it "should clean a folder full of files, removing files that don't match configurable criteria for keeping old files"
199
+ end
data/tasks/rspec.rake ADDED
@@ -0,0 +1,21 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ require 'spec'
6
+ end
7
+ begin
8
+ require 'spec/rake/spectask'
9
+ rescue LoadError
10
+ puts <<-EOS
11
+ To use rspec for testing you must install rspec gem:
12
+ gem install rspec
13
+ EOS
14
+ exit(0)
15
+ end
16
+
17
+ desc "Run the specs under spec/models"
18
+ Spec::Rake::SpecTask.new do |t|
19
+ t.spec_opts = ['--options', "spec/spec.opts"]
20
+ t.spec_files = FileList['spec/**/*_spec.rb']
21
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yore
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Gary McGhee
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-01-25 00:00:00 +09:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: RequirePaths
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.0.1
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: cmdparse
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.0.2
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: s3sync
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 1.2.5
44
+ version:
45
+ - !ruby/object:Gem::Dependency
46
+ name: newgem
47
+ type: :development
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 1.2.3
54
+ version:
55
+ - !ruby/object:Gem::Dependency
56
+ name: hoe
57
+ type: :development
58
+ version_requirement:
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: 1.8.0
64
+ version:
65
+ description: FIX (describe your package)
66
+ email:
67
+ - contact@buzz@ware@com@au
68
+ executables:
69
+ - yore
70
+ extensions: []
71
+
72
+ extra_rdoc_files:
73
+ - History.txt
74
+ - Manifest.txt
75
+ - PostInstall.txt
76
+ - README.rdoc
77
+ files:
78
+ - bin/yore
79
+ - History.txt
80
+ - lib/ihl_ruby/enum.rb
81
+ - lib/ihl_ruby/extend_base_classes.rb
82
+ - lib/ihl_ruby/misc_utils.rb
83
+ - lib/ihl_ruby/string_utils.rb
84
+ - lib/ihl_ruby/xml_utils.rb
85
+ - lib/yore.orig.rb
86
+ - lib/yore/yore_core.rb
87
+ - Manifest.txt
88
+ - PostInstall.txt
89
+ - Rakefile
90
+ - README.rdoc
91
+ - script/console
92
+ - script/destroy
93
+ - script/generate
94
+ - spec/rewind_spec.rb
95
+ - spec/spec.opts
96
+ - spec/spec_helper.rb
97
+ - spec/test_job_a.xml
98
+ - spec/yore_spec.rb
99
+ - tasks/rspec.rake
100
+ has_rdoc: true
101
+ homepage: FIX (url)
102
+ post_install_message:
103
+ rdoc_options:
104
+ - --main
105
+ - README.rdoc
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: "0"
113
+ version:
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: "0"
119
+ version:
120
+ requirements: []
121
+
122
+ rubyforge_project: buzzware
123
+ rubygems_version: 1.3.1
124
+ signing_key:
125
+ specification_version: 2
126
+ summary: FIX (describe your package)
127
+ test_files: []
128
+