druid-tools 0.2.6 → 0.3.0
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/.gitignore +4 -1
- data/Gemfile +9 -1
- data/Gemfile.lock +70 -0
- data/README.md +27 -7
- data/Rakefile +3 -0
- data/VERSION +1 -1
- data/druid-tools.gemspec +3 -2
- data/lib/druid_tools.rb +1 -0
- data/lib/druid_tools/access_druid.rb +25 -0
- data/lib/druid_tools/druid.rb +39 -11
- data/spec/access_druid_spec.rb +28 -0
- data/spec/druid_tools_spec.rb +81 -27
- data/spec/spec_helper.rb +1 -0
- metadata +27 -14
- data/.rvmrc +0 -1
data/.gitignore
CHANGED
data/Gemfile
CHANGED
@@ -1,4 +1,12 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
|
+
source 'http://sul-gems.stanford.edu'
|
3
|
+
|
4
|
+
group :development do
|
5
|
+
gem "ruby-debug", :platform => :ruby_18
|
6
|
+
gem "rcov", :platform => :ruby_18
|
7
|
+
gem "simplecov", :platform => [:ruby_19, :ruby_20]
|
8
|
+
gem "debugger", :platform => :ruby_19
|
9
|
+
gem "pry-debugger", :platform => :ruby_19
|
10
|
+
end
|
2
11
|
|
3
|
-
# Specify your gem's dependencies in druid-tools.gemspec
|
4
12
|
gemspec
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
druid-tools (0.3.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
remote: http://sul-gems.stanford.edu/
|
9
|
+
specs:
|
10
|
+
coderay (1.0.9)
|
11
|
+
columnize (0.3.6)
|
12
|
+
debugger (1.6.2)
|
13
|
+
columnize (>= 0.3.1)
|
14
|
+
debugger-linecache (~> 1.2.0)
|
15
|
+
debugger-ruby_core_source (~> 1.2.3)
|
16
|
+
debugger-linecache (1.2.0)
|
17
|
+
debugger-ruby_core_source (1.2.3)
|
18
|
+
diff-lcs (1.2.4)
|
19
|
+
linecache (0.46)
|
20
|
+
rbx-require-relative (> 0.0.4)
|
21
|
+
lyberteam-gems-devel (1.0.1)
|
22
|
+
rake (>= 0.8.7)
|
23
|
+
rest-client
|
24
|
+
method_source (0.8.2)
|
25
|
+
mime-types (1.24)
|
26
|
+
multi_json (1.8.2)
|
27
|
+
pry (0.9.12.2)
|
28
|
+
coderay (~> 1.0.5)
|
29
|
+
method_source (~> 0.8)
|
30
|
+
slop (~> 3.4)
|
31
|
+
pry-debugger (0.2.2)
|
32
|
+
debugger (~> 1.3)
|
33
|
+
pry (~> 0.9.10)
|
34
|
+
rake (10.1.0)
|
35
|
+
rbx-require-relative (0.0.9)
|
36
|
+
rcov (1.0.0)
|
37
|
+
rest-client (1.6.7)
|
38
|
+
mime-types (>= 1.16)
|
39
|
+
rspec (2.14.1)
|
40
|
+
rspec-core (~> 2.14.0)
|
41
|
+
rspec-expectations (~> 2.14.0)
|
42
|
+
rspec-mocks (~> 2.14.0)
|
43
|
+
rspec-core (2.14.5)
|
44
|
+
rspec-expectations (2.14.2)
|
45
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
46
|
+
rspec-mocks (2.14.3)
|
47
|
+
ruby-debug (0.10.4)
|
48
|
+
columnize (>= 0.1)
|
49
|
+
ruby-debug-base (~> 0.10.4.0)
|
50
|
+
ruby-debug-base (0.10.4)
|
51
|
+
linecache (>= 0.3)
|
52
|
+
simplecov (0.7.1)
|
53
|
+
multi_json (~> 1.0)
|
54
|
+
simplecov-html (~> 0.7.1)
|
55
|
+
simplecov-html (0.7.1)
|
56
|
+
slop (3.4.6)
|
57
|
+
|
58
|
+
PLATFORMS
|
59
|
+
ruby
|
60
|
+
|
61
|
+
DEPENDENCIES
|
62
|
+
debugger
|
63
|
+
druid-tools!
|
64
|
+
lyberteam-gems-devel (~> 1.0.0)
|
65
|
+
pry-debugger
|
66
|
+
rake (~> 10.1.0)
|
67
|
+
rcov
|
68
|
+
rspec (~> 2.14.0)
|
69
|
+
ruby-debug
|
70
|
+
simplecov
|
data/README.md
CHANGED
@@ -35,7 +35,7 @@ Tools to manipulate DRUID trees and content directories
|
|
35
35
|
d.rmdir
|
36
36
|
# Link content from another source into a druid tree
|
37
37
|
d.mkdir_with_final_link('/some/other/content/location')
|
38
|
-
|
38
|
+
|
39
39
|
### Content-specific methods create the relevant directories if they don't exist
|
40
40
|
|
41
41
|
Pass `false` as a parameter to prevent directory creation, or `true` (default) to create directories.
|
@@ -50,25 +50,45 @@ Pass `false` as a parameter to prevent directory creation, or `true` (default) t
|
|
50
50
|
=> "/dor/workspace/ab/123/cd/4567/ab123cd4567/metadata"
|
51
51
|
d.temp_dir(false)
|
52
52
|
=> "/dor/workspace/ab/123/cd/4567/ab123cd4567/temp"
|
53
|
-
|
53
|
+
|
54
54
|
### Locate existing content within the druid tree
|
55
55
|
|
56
56
|
# In the correct directory
|
57
57
|
d.find_metadata('contentMetadata.xml')
|
58
58
|
=> "/dor/workspace/ab/123/cd/4567/ab123cd4567/metadata/contentMetadata.xml"
|
59
|
-
|
59
|
+
|
60
60
|
# In other known previous locations, for backward compatibility
|
61
61
|
d.find_metadata('contentMetadata.xml')
|
62
62
|
=> "/dor/workspace/ab/123/cd/4567/ab123cd4567/contentMetadata.xml"
|
63
63
|
|
64
64
|
d.find_metadata('contentMetadata.xml')
|
65
65
|
=> "/dor/workspace/ab/123/cd/4567/contentMetadata.xml"
|
66
|
-
|
66
|
+
|
67
67
|
d.find_content('this/file/does/not/exist.jpg')
|
68
68
|
=> nil
|
69
|
-
|
70
|
-
## History
|
71
69
|
|
70
|
+
### Pruning: removes leaves of tree up to non-empty branches
|
71
|
+
|
72
|
+
d1 = DruidTools::Druid.new 'druid:cd456ef7890', '/workspace'
|
73
|
+
d1.mkdir
|
74
|
+
d2 = DruidTools::Druid.new 'druid:cd456gh1234', '/workspace'
|
75
|
+
d2.mkdir
|
76
|
+
|
77
|
+
# /workspace/cd/456/gh/1234/cd456gh1234 pruned down to /workspace/cd/456
|
78
|
+
# /workspace/cd/456/ef/7890/cd456ef7890 left intact
|
79
|
+
d2.prune!
|
80
|
+
|
81
|
+
### Stacks and Purl compatible Druid. All files at the leaf directories
|
82
|
+
|
83
|
+
pd = DruidTools::PurlDruid.new 'druid:ab123cd4567', '/purl'
|
84
|
+
pd.path
|
85
|
+
=> "/purl/ab/123/cd/4567"
|
86
|
+
pd.content_dir
|
87
|
+
=> "/purl/ab/123/cd/4567"
|
88
|
+
|
89
|
+
### History
|
90
|
+
|
91
|
+
- <b>0.3.0</b> - Added #prune method. Added AccessDruid for stacks and purl access
|
72
92
|
- <b>0.2.6</b> - Fixed VERSION warning message, and documentation cleanup
|
73
93
|
- <b>0.2.5</b> - Added glob pattern as DruidTools::Druid.glob
|
74
94
|
- <b>0.2.4</b> - Allow non-String as .new parameter and added InvalidDruidError
|
@@ -77,4 +97,4 @@ Pass `false` as a parameter to prevent directory creation, or `true` (default) t
|
|
77
97
|
- <b>0.2.1</b> - Do not error out during symlink creation if it already exists
|
78
98
|
- <b>0.2.0</b> - Added DruidTools::Druid.valid?
|
79
99
|
- <b>0.1.0</b> - Additional support for alternate content locations
|
80
|
-
- <b>0.0.1</b> - Initial Release
|
100
|
+
- <b>0.0.1</b> - Initial Release
|
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/druid-tools.gemspec
CHANGED
@@ -16,6 +16,7 @@ Gem::Specification.new do |gem|
|
|
16
16
|
gem.require_paths = ['lib']
|
17
17
|
gem.version = File.read('VERSION').strip
|
18
18
|
|
19
|
-
gem.add_development_dependency 'rake', '
|
20
|
-
gem.add_development_dependency 'rspec', '
|
19
|
+
gem.add_development_dependency 'rake', '~> 10.1.0'
|
20
|
+
gem.add_development_dependency 'rspec', '~> 2.14.0'
|
21
|
+
gem.add_development_dependency 'lyberteam-gems-devel', '~> 1.0.0'
|
21
22
|
end
|
data/lib/druid_tools.rb
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
|
2
|
+
module DruidTools
|
3
|
+
|
4
|
+
# Overrides the Druid#tree method
|
5
|
+
class AccessDruid < Druid
|
6
|
+
|
7
|
+
self.prefix = 'druid'
|
8
|
+
|
9
|
+
def tree
|
10
|
+
@druid.scan(self.class.pattern).flatten
|
11
|
+
end
|
12
|
+
|
13
|
+
# all content lives in the base druid directory
|
14
|
+
def path(extra=nil, create=false)
|
15
|
+
result = File.join(*([base,tree].compact))
|
16
|
+
mkdir(extra) if create and not File.exists?(result)
|
17
|
+
result
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
PurlDruid = AccessDruid
|
23
|
+
StacksDruid = AccessDruid
|
24
|
+
|
25
|
+
end
|
data/lib/druid_tools/druid.rb
CHANGED
@@ -3,10 +3,10 @@ require 'pathname'
|
|
3
3
|
module DruidTools
|
4
4
|
class Druid
|
5
5
|
attr_accessor :druid, :base
|
6
|
-
|
6
|
+
|
7
7
|
class << self
|
8
8
|
attr_accessor :prefix
|
9
|
-
|
9
|
+
|
10
10
|
# @return [Regexp] matches druid:aa111aa1111 or aa111aa1111
|
11
11
|
def pattern
|
12
12
|
/\A(?:#{self.prefix}:)?([a-z]{2})(\d{3})([a-z]{2})(\d{4})\z/
|
@@ -25,19 +25,19 @@ module DruidTools
|
|
25
25
|
|
26
26
|
end
|
27
27
|
self.prefix = 'druid'
|
28
|
-
|
28
|
+
|
29
29
|
[:content, :metadata, :temp].each do |dir_type|
|
30
30
|
self.class_eval <<-EOC
|
31
31
|
def #{dir_type}_dir(create=true)
|
32
32
|
path("#{dir_type}",create)
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
def find_#{dir_type}(path)
|
36
36
|
find(:#{dir_type},path)
|
37
37
|
end
|
38
38
|
EOC
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
# @param druid [String] A valid druid
|
42
42
|
# @param base [String] The directory used by #path
|
43
43
|
def initialize(druid, base='.')
|
@@ -49,21 +49,21 @@ module DruidTools
|
|
49
49
|
@base = base
|
50
50
|
@druid = druid
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
def id
|
54
54
|
@druid.scan(self.class.pattern).flatten.join('')
|
55
55
|
end
|
56
|
-
|
56
|
+
|
57
57
|
def tree
|
58
58
|
@druid.scan(self.class.pattern).flatten + [id]
|
59
59
|
end
|
60
|
-
|
60
|
+
|
61
61
|
def path(extra=nil, create=false)
|
62
62
|
result = File.join(*([base,tree,extra].compact))
|
63
63
|
mkdir(extra) if create and not File.exists?(result)
|
64
64
|
result
|
65
65
|
end
|
66
|
-
|
66
|
+
|
67
67
|
def mkdir(extra=nil)
|
68
68
|
new_path = path(extra)
|
69
69
|
if(File.symlink? new_path)
|
@@ -74,7 +74,7 @@ module DruidTools
|
|
74
74
|
end
|
75
75
|
FileUtils.mkdir_p(new_path)
|
76
76
|
end
|
77
|
-
|
77
|
+
|
78
78
|
def find(type, path)
|
79
79
|
possibles = [self.path(type.to_s),self.path,File.expand_path('..',self.path)]
|
80
80
|
loc = possibles.find { |p| File.exists?(File.join(p,path)) }
|
@@ -107,7 +107,7 @@ module DruidTools
|
|
107
107
|
FileUtils.mkdir_p(real_path)
|
108
108
|
FileUtils.ln_s(source, new_path, :force=>true)
|
109
109
|
end
|
110
|
-
|
110
|
+
|
111
111
|
def rmdir(extra=nil)
|
112
112
|
parts = tree
|
113
113
|
parts << extra unless extra.nil?
|
@@ -123,5 +123,33 @@ module DruidTools
|
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
126
|
+
def pathname
|
127
|
+
Pathname self.path
|
128
|
+
end
|
129
|
+
|
130
|
+
def base_pathname
|
131
|
+
Pathname self.base
|
132
|
+
end
|
133
|
+
|
134
|
+
def prune!
|
135
|
+
this_path = pathname
|
136
|
+
parent = this_path.parent
|
137
|
+
parent.rmtree if parent.exist? && parent != base_pathname
|
138
|
+
prune_ancestors parent.parent
|
139
|
+
end
|
140
|
+
|
141
|
+
protected
|
142
|
+
|
143
|
+
# @param [Pathname] outermost_branch The branch at which pruning begins
|
144
|
+
# @return [void] Ascend the druid tree and prune empty branches
|
145
|
+
def prune_ancestors(outermost_branch)
|
146
|
+
while outermost_branch.children.size == 0
|
147
|
+
outermost_branch.rmdir
|
148
|
+
outermost_branch = outermost_branch.parent
|
149
|
+
break if outermost_branch == base_pathname
|
150
|
+
end
|
151
|
+
rescue
|
152
|
+
end
|
153
|
+
|
126
154
|
end
|
127
155
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe DruidTools::PurlDruid do
|
4
|
+
|
5
|
+
let(:purl_root) { Dir.mktmpdir }
|
6
|
+
|
7
|
+
let(:druid) { DruidTools::PurlDruid.new 'druid:cd456ef7890', purl_root }
|
8
|
+
|
9
|
+
after(:each) do
|
10
|
+
FileUtils.remove_entry purl_root
|
11
|
+
end
|
12
|
+
|
13
|
+
it "overrides Druid#tree so that the leaf is not Druid#id" do
|
14
|
+
expect(druid.tree).to eq(['cd','456','ef','7890'])
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#content_dir" do
|
18
|
+
|
19
|
+
it "creates content directories at leaf of the druid tree" do
|
20
|
+
expect(druid.content_dir).to match(/ef\/7890$/)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "does not create a 'content' subdirectory" do
|
24
|
+
expect(druid.content_dir).to_not match(/content$/)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
data/spec/druid_tools_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
#puts $LOAD_PATH.join("\n")
|
3
|
-
require '
|
3
|
+
require 'tmpdir'
|
4
4
|
|
5
5
|
describe DruidTools::Druid do
|
6
6
|
before (:all) do
|
@@ -11,7 +11,7 @@ describe DruidTools::Druid do
|
|
11
11
|
@druid_2 = 'druid:cd456gh1234'
|
12
12
|
@tree_2 = File.join(@fixture_dir,'cd/456/gh/1234/cd456gh1234')
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
after(:each) do
|
16
16
|
FileUtils.rm_rf(File.join(@fixture_dir,'cd'))
|
17
17
|
end
|
@@ -48,23 +48,23 @@ describe DruidTools::Druid do
|
|
48
48
|
DruidTools::Druid.new('druid:cd456ef7890',@fixture_dir).druid.should == 'druid:cd456ef7890'
|
49
49
|
DruidTools::Druid.new('cd456ef7890',@fixture_dir).druid.should == 'druid:cd456ef7890'
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
it "should extract the ID from the stem" do
|
53
53
|
DruidTools::Druid.new('druid:cd456ef7890',@fixture_dir).id.should == 'cd456ef7890'
|
54
54
|
DruidTools::Druid.new('cd456ef7890',@fixture_dir).id.should == 'cd456ef7890'
|
55
55
|
end
|
56
|
-
|
56
|
+
|
57
57
|
it "should raise an exception if the druid is invalid" do
|
58
58
|
lambda { DruidTools::Druid.new('nondruid:cd456ef7890',@fixture_dir) }.should raise_error(ArgumentError)
|
59
59
|
lambda { DruidTools::Druid.new('druid:cd4567ef890',@fixture_dir) }.should raise_error(ArgumentError)
|
60
60
|
end
|
61
|
-
|
61
|
+
|
62
62
|
it "should build a druid tree from a druid" do
|
63
63
|
druid = DruidTools::Druid.new(@druid_1,@fixture_dir)
|
64
64
|
druid.tree.should == ['cd','456','ef','7890','cd456ef7890']
|
65
65
|
druid.path.should == @tree_1
|
66
66
|
end
|
67
|
-
|
67
|
+
|
68
68
|
it "should create and destroy druid directories" do
|
69
69
|
File.exists?(@tree_1).should be_false
|
70
70
|
File.exists?(@tree_2).should be_false
|
@@ -79,7 +79,7 @@ describe DruidTools::Druid do
|
|
79
79
|
druid_2.mkdir
|
80
80
|
File.exists?(@tree_1).should be_true
|
81
81
|
File.exists?(@tree_2).should be_true
|
82
|
-
|
82
|
+
|
83
83
|
druid_2.rmdir
|
84
84
|
File.exists?(@tree_1).should be_true
|
85
85
|
File.exists?(@tree_2).should be_false
|
@@ -94,7 +94,7 @@ describe DruidTools::Druid do
|
|
94
94
|
before :all do
|
95
95
|
DruidTools::Druid.prefix = 'sulair'
|
96
96
|
end
|
97
|
-
|
97
|
+
|
98
98
|
after :all do
|
99
99
|
DruidTools::Druid.prefix = 'druid'
|
100
100
|
end
|
@@ -105,14 +105,14 @@ describe DruidTools::Druid do
|
|
105
105
|
DruidTools::Druid.new('cd456ef7890',@fixture_dir).druid.should == 'sulair:cd456ef7890'
|
106
106
|
end
|
107
107
|
end
|
108
|
-
|
108
|
+
|
109
109
|
describe "content directories" do
|
110
110
|
it "should know where its content goes" do
|
111
111
|
druid = DruidTools::Druid.new(@druid_1,@fixture_dir)
|
112
112
|
druid.content_dir(false).should == File.join(@tree_1,'content')
|
113
113
|
druid.metadata_dir(false).should == File.join(@tree_1,'metadata')
|
114
114
|
druid.temp_dir(false).should == File.join(@tree_1,'temp')
|
115
|
-
|
115
|
+
|
116
116
|
File.exists?(File.join(@tree_1,'content')).should be_false
|
117
117
|
File.exists?(File.join(@tree_1,'metadata')).should be_false
|
118
118
|
File.exists?(File.join(@tree_1,'temp')).should be_false
|
@@ -123,31 +123,31 @@ describe DruidTools::Druid do
|
|
123
123
|
druid.content_dir.should == File.join(@tree_1,'content')
|
124
124
|
druid.metadata_dir.should == File.join(@tree_1,'metadata')
|
125
125
|
druid.temp_dir.should == File.join(@tree_1,'temp')
|
126
|
-
|
126
|
+
|
127
127
|
File.exists?(File.join(@tree_1,'content')).should be_true
|
128
128
|
File.exists?(File.join(@tree_1,'metadata')).should be_true
|
129
129
|
File.exists?(File.join(@tree_1,'temp')).should be_true
|
130
130
|
end
|
131
|
-
|
131
|
+
|
132
132
|
it "should match glob" do
|
133
133
|
druid = DruidTools::Druid.new(@druid_1,@fixture_dir)
|
134
134
|
druid.mkdir
|
135
135
|
Dir.glob(File.join(File.dirname(druid.path), DruidTools::Druid::glob)).size.should == 1
|
136
136
|
end
|
137
137
|
end
|
138
|
-
|
138
|
+
|
139
139
|
describe "content discovery" do
|
140
140
|
before :all do
|
141
141
|
@druid = DruidTools::Druid.new(@druid_1,@fixture_dir)
|
142
142
|
@filelist = %w(1 2 3 4).collect { |num| "someFile#{num}" }
|
143
143
|
end
|
144
|
-
|
144
|
+
|
145
145
|
it "should find content in content directories" do
|
146
146
|
location = @druid.content_dir
|
147
147
|
File.open(File.join(location,'someContent'),'w') { |f| f.write 'This is the content' }
|
148
148
|
@druid.find_content('someContent').should == File.join(location,'someContent')
|
149
149
|
end
|
150
|
-
|
150
|
+
|
151
151
|
it "should find content in the root directory" do
|
152
152
|
location = @druid.path(nil,true)
|
153
153
|
File.open(File.join(location,'someContent'),'w') { |f| f.write 'This is the content' }
|
@@ -159,7 +159,7 @@ describe DruidTools::Druid do
|
|
159
159
|
File.open(File.join(location,'someContent'),'w') { |f| f.write 'This is the content' }
|
160
160
|
@druid.find_content('someContent').should == File.join(location,'someContent')
|
161
161
|
end
|
162
|
-
|
162
|
+
|
163
163
|
it "should not find content in the wrong content directory" do
|
164
164
|
location = @druid.metadata_dir
|
165
165
|
File.open(File.join(location,'someContent'),'w') { |f| f.write 'This is the content' }
|
@@ -208,48 +208,102 @@ describe DruidTools::Druid do
|
|
208
208
|
end
|
209
209
|
|
210
210
|
end
|
211
|
-
|
211
|
+
|
212
212
|
describe "#mkdir error handling" do
|
213
213
|
it "raises SameContentExistsError if the directory already exists" do
|
214
214
|
druid_2 = DruidTools::Druid.new(@druid_2,@fixture_dir)
|
215
215
|
druid_2.mkdir
|
216
216
|
lambda { druid_2.mkdir }.should raise_error(DruidTools::SameContentExistsError)
|
217
217
|
end
|
218
|
-
|
218
|
+
|
219
219
|
it "raises DifferentContentExistsError if a link already exists in the workspace for this druid" do
|
220
220
|
source_dir = '/tmp/content_dir'
|
221
|
-
FileUtils.mkdir_p(source_dir)
|
221
|
+
FileUtils.mkdir_p(source_dir)
|
222
222
|
dr = DruidTools::Druid.new(@druid_2,@fixture_dir)
|
223
223
|
dr.mkdir_with_final_link(source_dir)
|
224
224
|
lambda { dr.mkdir }.should raise_error(DruidTools::DifferentContentExistsError)
|
225
225
|
end
|
226
226
|
end
|
227
|
-
|
227
|
+
|
228
228
|
describe "#mkdir_with_final_link" do
|
229
|
-
|
229
|
+
|
230
230
|
before(:each) do
|
231
231
|
@source_dir = '/tmp/content_dir'
|
232
|
-
FileUtils.mkdir_p(@source_dir)
|
232
|
+
FileUtils.mkdir_p(@source_dir)
|
233
233
|
@dr = DruidTools::Druid.new(@druid_2,@fixture_dir)
|
234
234
|
end
|
235
|
-
|
235
|
+
|
236
236
|
it "creates a druid tree in the workspace with the final directory being a link to the passed in source" do
|
237
237
|
@dr.mkdir_with_final_link(@source_dir)
|
238
238
|
|
239
239
|
File.should be_symlink(@dr.path)
|
240
240
|
File.readlink(@tree_2).should == @source_dir
|
241
241
|
end
|
242
|
-
|
242
|
+
|
243
243
|
it "should not error out if the link to source already exists" do
|
244
244
|
@dr.mkdir_with_final_link(@source_dir)
|
245
245
|
File.should be_symlink(@dr.path)
|
246
246
|
File.readlink(@tree_2).should == @source_dir
|
247
247
|
end
|
248
|
-
|
248
|
+
|
249
249
|
it "raises DifferentContentExistsError if a directory already exists in the workspace for this druid" do
|
250
250
|
@dr.mkdir(@fixture_dir)
|
251
251
|
lambda { @dr.mkdir_with_final_link(@source_di) }.should raise_error(DruidTools::DifferentContentExistsError)
|
252
252
|
end
|
253
253
|
end
|
254
|
-
|
254
|
+
|
255
|
+
describe "#prune!" do
|
256
|
+
|
257
|
+
let(:workspace) { Dir.mktmpdir }
|
258
|
+
|
259
|
+
let(:dr1) { DruidTools::Druid.new @druid_1, workspace }
|
260
|
+
let(:dr2) { DruidTools::Druid.new @druid_2, workspace }
|
261
|
+
let(:pathname1) { dr1.pathname }
|
262
|
+
|
263
|
+
after(:each) do
|
264
|
+
FileUtils.remove_entry workspace
|
265
|
+
end
|
266
|
+
|
267
|
+
context "shared ancestor" do
|
268
|
+
|
269
|
+
before(:each) do
|
270
|
+
dr1.mkdir
|
271
|
+
dr2.mkdir
|
272
|
+
dr1.prune!
|
273
|
+
end
|
274
|
+
|
275
|
+
it "deletes the outermost directory" do
|
276
|
+
expect(File).to_not exist(dr1.path)
|
277
|
+
end
|
278
|
+
|
279
|
+
it "deletes empty ancestor directories" do
|
280
|
+
expect(File).to_not exist(pathname1.parent)
|
281
|
+
expect(File).to_not exist(pathname1.parent.parent)
|
282
|
+
end
|
283
|
+
|
284
|
+
it "stops at ancestor directories that have children" do
|
285
|
+
# 'cd/456' should still exist because of druid2
|
286
|
+
shared_ancestor = pathname1.parent.parent.parent
|
287
|
+
expect(shared_ancestor.to_s).to match(/cd\/456$/)
|
288
|
+
expect(File).to exist(shared_ancestor)
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
292
|
+
it "removes all directories up to the base path when there are no common ancestors" do
|
293
|
+
dr1.mkdir
|
294
|
+
dr1.prune!
|
295
|
+
expect(File).to_not exist(File.join(workspace, 'cd'))
|
296
|
+
expect(File).to exist(workspace)
|
297
|
+
end
|
298
|
+
|
299
|
+
it "removes directories with symlinks" do
|
300
|
+
source_dir = File.join workspace, 'src_dir'
|
301
|
+
FileUtils.mkdir_p(source_dir)
|
302
|
+
dr2.mkdir_with_final_link(source_dir)
|
303
|
+
dr2.prune!
|
304
|
+
expect(File).to_not exist(dr2.path)
|
305
|
+
expect(File).to_not exist(File.join(workspace, 'cd'))
|
306
|
+
end
|
307
|
+
end
|
308
|
+
|
255
309
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: druid-tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,14 +10,14 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-
|
13
|
+
date: 2013-11-07 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rake
|
17
17
|
requirement: !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
|
-
- -
|
20
|
+
- - ~>
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: 10.1.0
|
23
23
|
type: :development
|
@@ -25,7 +25,7 @@ dependencies:
|
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
none: false
|
27
27
|
requirements:
|
28
|
-
- -
|
28
|
+
- - ~>
|
29
29
|
- !ruby/object:Gem::Version
|
30
30
|
version: 10.1.0
|
31
31
|
- !ruby/object:Gem::Dependency
|
@@ -33,7 +33,7 @@ dependencies:
|
|
33
33
|
requirement: !ruby/object:Gem::Requirement
|
34
34
|
none: false
|
35
35
|
requirements:
|
36
|
-
- -
|
36
|
+
- - ~>
|
37
37
|
- !ruby/object:Gem::Version
|
38
38
|
version: 2.14.0
|
39
39
|
type: :development
|
@@ -41,9 +41,25 @@ dependencies:
|
|
41
41
|
version_requirements: !ruby/object:Gem::Requirement
|
42
42
|
none: false
|
43
43
|
requirements:
|
44
|
-
- -
|
44
|
+
- - ~>
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: 2.14.0
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: lyberteam-gems-devel
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.0.0
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ~>
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 1.0.0
|
47
63
|
description: Tools to manipulate DRUID trees and content directories
|
48
64
|
email:
|
49
65
|
- mbklein@stanford.edu
|
@@ -52,8 +68,8 @@ extensions: []
|
|
52
68
|
extra_rdoc_files: []
|
53
69
|
files:
|
54
70
|
- .gitignore
|
55
|
-
- .rvmrc
|
56
71
|
- Gemfile
|
72
|
+
- Gemfile.lock
|
57
73
|
- LICENSE
|
58
74
|
- README.md
|
59
75
|
- Rakefile
|
@@ -91,9 +107,11 @@ files:
|
|
91
107
|
- druid-tools.gemspec
|
92
108
|
- lib/druid-tools.rb
|
93
109
|
- lib/druid_tools.rb
|
110
|
+
- lib/druid_tools/access_druid.rb
|
94
111
|
- lib/druid_tools/druid.rb
|
95
112
|
- lib/druid_tools/exceptions.rb
|
96
113
|
- lib/druid_tools/version.rb
|
114
|
+
- spec/access_druid_spec.rb
|
97
115
|
- spec/druid_tools_spec.rb
|
98
116
|
- spec/spec_helper.rb
|
99
117
|
homepage: http://github.com/sul-dlss/druid-tools
|
@@ -110,24 +128,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
110
128
|
- - ! '>='
|
111
129
|
- !ruby/object:Gem::Version
|
112
130
|
version: '0'
|
113
|
-
segments:
|
114
|
-
- 0
|
115
|
-
hash: -3564401623141727809
|
116
131
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
132
|
none: false
|
118
133
|
requirements:
|
119
134
|
- - ! '>='
|
120
135
|
- !ruby/object:Gem::Version
|
121
136
|
version: '0'
|
122
|
-
segments:
|
123
|
-
- 0
|
124
|
-
hash: -3564401623141727809
|
125
137
|
requirements: []
|
126
138
|
rubyforge_project:
|
127
|
-
rubygems_version: 1.8.
|
139
|
+
rubygems_version: 1.8.25
|
128
140
|
signing_key:
|
129
141
|
specification_version: 3
|
130
142
|
summary: Tools to manipulate DRUID trees and content directories
|
131
143
|
test_files:
|
144
|
+
- spec/access_druid_spec.rb
|
132
145
|
- spec/druid_tools_spec.rb
|
133
146
|
- spec/spec_helper.rb
|
data/.rvmrc
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
rvm use 1.8.7@druid-tools --create
|