bagit 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.txt +21 -0
- data/README.md +59 -0
- data/Rakefile +12 -10
- data/bagit.gemspec +9 -16
- data/lib/bagit.rb +1 -1
- data/lib/bagit/bag.rb +20 -12
- data/lib/bagit/valid.rb +2 -3
- metadata +8 -24
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2009 Francesco Lazzarino
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
BagIt (for ruby)
|
2
|
+
================
|
3
|
+
|
4
|
+
Based on the [BagItspec v0.96](https://confluence.ucop.edu/display/Curation/BagIt).
|
5
|
+
|
6
|
+
Supported Features:
|
7
|
+
-------------------
|
8
|
+
* bag compiling
|
9
|
+
* manifest & tagmanifest generation
|
10
|
+
* generation of tag files bag-info.txt and bagit.txt
|
11
|
+
* fetching remote files (fetch.txt)
|
12
|
+
* bag validation
|
13
|
+
|
14
|
+
Installation
|
15
|
+
------------
|
16
|
+
% gem install bagit validatable
|
17
|
+
The rubyforge gem is deprecated.
|
18
|
+
|
19
|
+
|
20
|
+
Example: making a bag
|
21
|
+
---------------------
|
22
|
+
require 'bagit'
|
23
|
+
|
24
|
+
# make a new bag at base_path
|
25
|
+
bag = BagIt::Bag.new base_path
|
26
|
+
|
27
|
+
# make a new file
|
28
|
+
bag.add_file("samplefile") do |io|
|
29
|
+
io.puts "Hello Bag!"
|
30
|
+
end
|
31
|
+
|
32
|
+
# generate the manifest and tagmanifest files
|
33
|
+
bag.manifest!
|
34
|
+
|
35
|
+
Example: validating an existing bag
|
36
|
+
-----------------------------------
|
37
|
+
|
38
|
+
bag = BagIt::Bag.new existing_base_path
|
39
|
+
|
40
|
+
if bag.valid?
|
41
|
+
puts "#{existing_base_path} is valid"
|
42
|
+
else
|
43
|
+
puts "#{existing_base_path} is not valid"
|
44
|
+
end
|
45
|
+
|
46
|
+
TODO
|
47
|
+
----
|
48
|
+
* command line tools for common tasks
|
49
|
+
* better holy bag (fetch.txt) generation
|
50
|
+
* better error reporting.
|
51
|
+
* poor mans' checksum
|
52
|
+
|
53
|
+
---
|
54
|
+
|
55
|
+
Copyright © 2009, [Francesco Lazzarino](mailto:flazzarino@gmail.com).
|
56
|
+
|
57
|
+
Sponsored by [Florida Center for Library Automation](http://www.fcla.edu).
|
58
|
+
|
59
|
+
See LICENSE.txt for terms.
|
data/Rakefile
CHANGED
@@ -1,14 +1,16 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
Bundler.setup(:default, :development, :test)
|
4
|
+
|
1
5
|
require 'rake'
|
2
|
-
require '
|
3
|
-
require '
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
t.
|
9
|
-
|
10
|
-
# t.rcov = true
|
11
|
-
# t.rcov_opts += ["-x /Library", "-x spec"]
|
6
|
+
require 'rdoc/task'
|
7
|
+
require 'rspec/core/rake_task'
|
8
|
+
|
9
|
+
Bundler::GemHelper.install_tasks
|
10
|
+
|
11
|
+
RSpec::Core::RakeTask.new do |t|
|
12
|
+
t.pattern = 'spec/**/*_spec.rb'
|
13
|
+
t.rspec_opts = %w(-fs --color)
|
12
14
|
end
|
13
15
|
|
14
16
|
task :default => [:spec]
|
data/bagit.gemspec
CHANGED
@@ -1,20 +1,13 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
spec.
|
5
|
-
spec.version = SemVer.find.format '%M.%m.%p'
|
6
|
-
spec.summary = "BagIt package generation and validation"
|
1
|
+
BAGIT_SPEC = Gem::Specification.new do |spec|
|
2
|
+
spec.name = "bagit"
|
3
|
+
spec.version = '0.2.0'
|
4
|
+
spec.summary = "BagIt package generation and validation"
|
7
5
|
spec.description = "Ruby Library and Command Line tools for bagit"
|
8
|
-
spec.email
|
9
|
-
spec.homepage
|
10
|
-
spec.authors
|
6
|
+
spec.email = "flazzarino@gmail.com"
|
7
|
+
spec.homepage = 'http://github.com/flazz/bagit'
|
8
|
+
spec.authors = ["Francesco Lazzarino"]
|
11
9
|
|
12
|
-
spec.
|
13
|
-
"lib/bagit/fetch.rb", "lib/bagit/file.rb",
|
14
|
-
"lib/bagit/info.rb", "lib/bagit/manifest.rb",
|
15
|
-
"lib/bagit/string.rb", "lib/bagit/valid.rb",
|
16
|
-
"lib/bagit.rb" ]
|
10
|
+
spec.add_dependency 'validatable', '~> 1.6'
|
17
11
|
|
18
|
-
spec.
|
19
|
-
spec.add_dependency 'semver', '~> 0.1.0'
|
12
|
+
spec.files = %w(Rakefile README.md LICENSE.txt bagit.gemspec) + Dir["lib/**/*.rb"]
|
20
13
|
end
|
data/lib/bagit.rb
CHANGED
data/lib/bagit/bag.rb
CHANGED
@@ -9,7 +9,6 @@ module BagIt
|
|
9
9
|
|
10
10
|
# Represents the state of a bag on a filesystem
|
11
11
|
class Bag
|
12
|
-
|
13
12
|
attr_reader :bag_dir
|
14
13
|
|
15
14
|
include Validity # Validity functionality
|
@@ -24,7 +23,7 @@ module BagIt
|
|
24
23
|
# make the dir structure if it doesn't exist
|
25
24
|
FileUtils::mkdir bag_dir unless File.directory? bag_dir
|
26
25
|
FileUtils::mkdir data_dir unless File.directory? data_dir
|
27
|
-
|
26
|
+
|
28
27
|
# write some tag info if its not there
|
29
28
|
unless File.exist? bagit_txt_file
|
30
29
|
write_bagit("BagIt-Version" => SPEC_VERSION, "Tag-File-Character-Encoding" => "UTF-8")
|
@@ -33,7 +32,6 @@ module BagIt
|
|
33
32
|
unless File.exist? bag_info_txt_file
|
34
33
|
write_bag_info('Bag-Software-Agent' => "BagIt Ruby Gem (http://bagit.rubyforge.org)")
|
35
34
|
end
|
36
|
-
|
37
35
|
end
|
38
36
|
|
39
37
|
# Return the path to the data directory
|
@@ -62,30 +60,40 @@ module BagIt
|
|
62
60
|
else
|
63
61
|
FileUtils::cp src_path, path
|
64
62
|
end
|
65
|
-
|
66
63
|
end
|
67
|
-
|
64
|
+
|
68
65
|
# Remove a bag file
|
69
66
|
def remove_file(base_path)
|
70
67
|
path = File.join(data_dir, base_path)
|
71
68
|
raise "Bag file does not exist: #{base_path}" unless File.exist? path
|
72
69
|
FileUtils::rm path
|
73
70
|
end
|
74
|
-
|
71
|
+
|
72
|
+
# Retrieve the IO handle for a file in the bag
|
73
|
+
def get(base_path)
|
74
|
+
path = File.join(data_dir, base_path)
|
75
|
+
return nil unless File.exist?(path)
|
76
|
+
File.open(path)
|
77
|
+
end
|
78
|
+
|
79
|
+
# Test if this bag is empty (no files)
|
80
|
+
def empty?
|
81
|
+
self.bag_files.empty?
|
82
|
+
end
|
83
|
+
|
84
|
+
# Get all bag file paths relative to the data dir
|
85
|
+
def paths
|
86
|
+
self.bag_files.collect { |f| f.sub(data_dir + '/', '') }
|
87
|
+
end
|
88
|
+
|
75
89
|
# Remove all empty directory trees from the bag
|
76
90
|
def gc!
|
77
|
-
|
78
91
|
Dir.entries(data_dir).each do |f|
|
79
|
-
|
80
92
|
unless %w{.. .}.include? f
|
81
93
|
abs_path = File.join data_dir, f
|
82
94
|
File.clean abs_path
|
83
95
|
end
|
84
|
-
|
85
96
|
end
|
86
|
-
|
87
97
|
end
|
88
|
-
|
89
98
|
end
|
90
|
-
|
91
99
|
end
|
data/lib/bagit/valid.rb
CHANGED
@@ -1,12 +1,11 @@
|
|
1
|
-
require 'rubygems'
|
2
1
|
require 'validatable'
|
3
2
|
|
4
3
|
module BagIt
|
5
4
|
|
6
5
|
class Bag
|
7
6
|
include Validatable
|
8
|
-
validates_true_for :consistency, :logic =>
|
9
|
-
validates_true_for :completeness, :logic =>
|
7
|
+
validates_true_for :consistency, :logic => Proc.new { complete? }
|
8
|
+
validates_true_for :completeness, :logic => Proc.new { consistent? }
|
10
9
|
end
|
11
10
|
|
12
11
|
module Validity
|
metadata
CHANGED
@@ -1,13 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bagit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
- 0
|
10
|
-
version: 0.1.0
|
4
|
+
prerelease:
|
5
|
+
version: 0.2.0
|
11
6
|
platform: ruby
|
12
7
|
authors:
|
13
8
|
- Francesco Lazzarino
|
@@ -15,23 +10,17 @@ autorequire:
|
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
12
|
|
18
|
-
date:
|
19
|
-
default_executable:
|
13
|
+
date: 2011-06-08 00:00:00 Z
|
20
14
|
dependencies:
|
21
15
|
- !ruby/object:Gem::Dependency
|
22
|
-
name:
|
16
|
+
name: validatable
|
23
17
|
prerelease: false
|
24
18
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
19
|
none: false
|
26
20
|
requirements:
|
27
21
|
- - ~>
|
28
22
|
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
segments:
|
31
|
-
- 0
|
32
|
-
- 1
|
33
|
-
- 0
|
34
|
-
version: 0.1.0
|
23
|
+
version: "1.6"
|
35
24
|
type: :runtime
|
36
25
|
version_requirements: *id001
|
37
26
|
description: Ruby Library and Command Line tools for bagit
|
@@ -44,6 +33,8 @@ extra_rdoc_files: []
|
|
44
33
|
|
45
34
|
files:
|
46
35
|
- Rakefile
|
36
|
+
- README.md
|
37
|
+
- LICENSE.txt
|
47
38
|
- bagit.gemspec
|
48
39
|
- lib/bagit/bag.rb
|
49
40
|
- lib/bagit/fetch.rb
|
@@ -53,7 +44,6 @@ files:
|
|
53
44
|
- lib/bagit/string.rb
|
54
45
|
- lib/bagit/valid.rb
|
55
46
|
- lib/bagit.rb
|
56
|
-
has_rdoc: true
|
57
47
|
homepage: http://github.com/flazz/bagit
|
58
48
|
licenses: []
|
59
49
|
|
@@ -67,23 +57,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
67
57
|
requirements:
|
68
58
|
- - ">="
|
69
59
|
- !ruby/object:Gem::Version
|
70
|
-
hash: 3
|
71
|
-
segments:
|
72
|
-
- 0
|
73
60
|
version: "0"
|
74
61
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
62
|
none: false
|
76
63
|
requirements:
|
77
64
|
- - ">="
|
78
65
|
- !ruby/object:Gem::Version
|
79
|
-
hash: 3
|
80
|
-
segments:
|
81
|
-
- 0
|
82
66
|
version: "0"
|
83
67
|
requirements: []
|
84
68
|
|
85
69
|
rubyforge_project:
|
86
|
-
rubygems_version: 1.3
|
70
|
+
rubygems_version: 1.8.3
|
87
71
|
signing_key:
|
88
72
|
specification_version: 3
|
89
73
|
summary: BagIt package generation and validation
|