Skip to content
This repository was archived by the owner on Apr 28, 2026. It is now read-only.

Commit b63976d

Browse files
committed
Merge branch 'next'
* next: (125 commits) Add example and limitations detail to the ReadMe. Add "internal use only" warnings to the documentation. Add a new example script "dir2ro". Add a new example script "zip2ro". Add File#remove_aggregate. Add Aggregate#file_entry for convenience. Add Util.strip_leading_slash. Cleanup annotation content stored in .ro/annotations. Override File#remove to ensure manifest is kept up to date. Allow annotations to be removed by their content field. Refactor Manifest#remove_annotation. Add Provenance#remove_author. Add provenance information to annotations. Factor out the provenance information from aggregates. Factor out the provenance information from the manifest. Tests on a bundle with an invalid manifest. Tests on an invalid manifest. Tests on an empty manifest ({}). Generalize the fake manifest test class. Consolidate all require directives into one place. ...
2 parents 4fe4fc6 + 8096013 commit b63976d

39 files changed

Lines changed: 3103 additions & 86 deletions

.ruby-env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
RUBYLIB=./lib:../lib

.travis.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,9 @@ rvm:
33
- 1.9.3
44
- 2.0.0
55
- 2.1.2
6+
- ruby-head
7+
- rbx-2
8+
matrix:
9+
allow_failures:
10+
- rvm: ruby-head
11+
- rvm: rbx-2

Gemfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
#------------------------------------------------------------------------------
2+
# Copyright (c) 2014 The University of Manchester, UK.
3+
#
4+
# BSD Licenced. See LICENCE.rdoc for details.
5+
#
6+
# Author: Robert Haines
7+
#------------------------------------------------------------------------------
8+
19
source 'https://rubygems.org'
210

311
gemspec

Rakefile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ end
2020

2121
RDoc::Task.new do |r|
2222
r.main = "ReadMe.rdoc"
23-
lib = Dir.glob("lib/**/*.rb").delete_if do |item|
24-
item.include?("ro-dir.rb")
25-
end
23+
lib = Dir.glob("lib/**/*.rb")
2624
r.rdoc_files.include("ReadMe.rdoc", "Licence.rdoc", "Changes.rdoc", lib)
2725
r.options << "-t Research Object Bundle Ruby Library version " +
2826
"#{ROBundle::VERSION}"

ReadMe.rdoc

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,24 @@ their documentation in addition to this:
3434
{documentation}[http://mygrid.github.io/ruby-ucf]
3535

3636
There are some examples of how to use the library provided in the bin
37-
directory. See the contents of the tests directory for even more.
37+
directory:
38+
39+
* <tt>ro-bundle-info</tt>: Print out simple metrics about this RO Bundle. This
40+
is analogous to the standard <tt>zipinfo</tt> command.
41+
* <tt>verify-ro-bundle</tt>: Verify that the specified RO Bundle is valid.
42+
* <tt>dir2ro</tt>: Recursively package up a directory into a RO Bundle. All
43+
files in the directory are added as aggregates.
44+
* <tt>zip2ro</tt>: Copy all files from a normal zip file into a RO Bundle. All
45+
files in the zip file are added as aggregates.
46+
47+
See the contents of the tests directory for even more example usage.
48+
49+
== What this library cannot do yet
50+
51+
The {RO Bundle specification}[http://wf4ever.github.io/ro/bundle/] is largely
52+
implemented but there are notable gaps at present, including:
53+
54+
* Aggregates do not support ORE proxies yet.
55+
* Extra provenance information cannot yet be added using the <tt>pav:</tt>
56+
namespace.
57+
* The <tt>@graph</tt> member is not supported in the top-level manifest.

bin/dir2ro

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env ruby
2+
#------------------------------------------------------------------------------
3+
# Copyright (c) 2014 The University of Manchester, UK.
4+
#
5+
# BSD Licenced. See LICENCE.rdoc for details.
6+
#
7+
# Author: Robert Haines
8+
#------------------------------------------------------------------------------
9+
10+
require 'rubygems'
11+
require 'ro-bundle'
12+
13+
def usage
14+
puts "Usage:\n dir2ro <directory> <ro-bundle> [name]"
15+
exit 1
16+
end
17+
18+
usage unless ARGV.length >= 2
19+
20+
dir_name = ARGV[0]
21+
bundle_file = ARGV[1]
22+
creator = ARGV[2]
23+
time_now = Time.now
24+
25+
begin
26+
ROBundle::File.create(bundle_file) do |bundle|
27+
# Set provenance data.
28+
bundle.created_by = creator unless creator.nil?
29+
bundle.created_on = time_now
30+
31+
dir_path = Pathname(dir_name)
32+
Dir[File.join(dir_name, "**", "**")].each do |entry|
33+
relative_path = Pathname.new(entry).relative_path_from(dir_path).to_s
34+
35+
# If the current entry is a directory, create it;
36+
# if it's a file, add it.
37+
if ::File.directory?(entry)
38+
bundle.mkdir(relative_path)
39+
else
40+
aggregate = bundle.add(relative_path, entry)
41+
aggregate.created_on = time_now
42+
end
43+
end
44+
end
45+
rescue Errno::ENOENT, Zip::Error => err
46+
puts err.to_s
47+
exit 1
48+
end

bin/ro-bundle-info

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
# Author: Robert Haines
88
#------------------------------------------------------------------------------
99

10-
1110
require 'rubygems'
1211
require 'ro-bundle'
1312

@@ -22,7 +21,7 @@ bundle = ARGV[0]
2221

2322
begin
2423
ro = ROBundle::File.open(bundle)
25-
rescue ZipContainer::MalformedContainerError, Zip::ZipError => err
24+
rescue ZipContainer::MalformedContainerError, ZipContainer::ZipError => err
2625
puts err.to_s
2726
exit 1
2827
end

bin/verify-ro-bundle

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,11 @@
11
#!/usr/bin/env ruby
2-
# Copyright (c) 2013 The University of Manchester, UK.
2+
#------------------------------------------------------------------------------
3+
# Copyright (c) 2014 The University of Manchester, UK.
34
#
4-
# All rights reserved.
5-
#
6-
# Redistribution and use in source and binary forms, with or without
7-
# modification, are permitted provided that the following conditions are met:
8-
#
9-
# * Redistributions of source code must retain the above copyright notice,
10-
# this list of conditions and the following disclaimer.
11-
#
12-
# * Redistributions in binary form must reproduce the above copyright notice,
13-
# this list of conditions and the following disclaimer in the documentation
14-
# and/or other materials provided with the distribution.
15-
#
16-
# * Neither the names of The University of Manchester nor the names of its
17-
# contributors may be used to endorse or promote products derived from this
18-
# software without specific prior written permission.
19-
#
20-
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21-
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22-
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23-
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24-
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25-
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26-
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27-
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28-
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29-
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30-
# POSSIBILITY OF SUCH DAMAGE.
5+
# BSD Licenced. See LICENCE.rdoc for details.
316
#
327
# Author: Robert Haines
8+
#------------------------------------------------------------------------------
339

3410
require 'rubygems'
3511
require 'ro-bundle'
@@ -45,7 +21,7 @@ rofile = ARGV[0]
4521

4622
begin
4723
ROBundle::File.verify!(rofile)
48-
rescue ZipContainer::MalformedContainerError, Zip::ZipError => err
24+
rescue ZipContainer::MalformedContainerError, ZipContainer::ZipError => err
4925
puts err.to_s
5026
exit 1
5127
end

bin/zip2ro

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env ruby
2+
#------------------------------------------------------------------------------
3+
# Copyright (c) 2014 The University of Manchester, UK.
4+
#
5+
# BSD Licenced. See LICENCE.rdoc for details.
6+
#
7+
# Author: Robert Haines
8+
#------------------------------------------------------------------------------
9+
10+
require 'rubygems'
11+
require 'ro-bundle'
12+
13+
def usage
14+
puts "Usage:\n zip2ro <zip-file> <ro-bundle> [name]"
15+
exit 1
16+
end
17+
18+
usage unless ARGV.length >= 2
19+
20+
zip_file = ARGV[0]
21+
bundle_file = ARGV[1]
22+
creator = ARGV[2]
23+
time_now = Time.now
24+
25+
begin
26+
ROBundle::File.create(bundle_file) do |bundle|
27+
# Set provenance data.
28+
bundle.created_by = creator unless creator.nil?
29+
bundle.created_on = time_now
30+
31+
Zip::File.open(zip_file) do |zip|
32+
zip.each do |entry|
33+
34+
# If the current entry is a directory, create it;
35+
# if it's a file, copy it.
36+
if zip.file.directory?(entry.name)
37+
bundle.mkdir entry.name
38+
else
39+
zip.file.open(entry.name, "r") do |z_file|
40+
41+
# Copy the contents of the entry.
42+
bundle.file.open(entry.name, "w") do |b_file|
43+
b_file.write z_file.read
44+
end
45+
46+
# Register the new entry as an aggregate of the RO.
47+
aggregate = bundle.add_aggregate entry.name
48+
aggregate.created_on = time_now
49+
end
50+
end
51+
end
52+
end
53+
end
54+
rescue Errno::ENOENT, Zip::Error => err
55+
puts err.to_s
56+
exit 1
57+
end

lib/ro-bundle.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,22 @@
77
#------------------------------------------------------------------------------
88

99
require "bundler/setup"
10+
require "forwardable"
1011
require "json"
12+
require "time"
1113
require "ucf"
14+
require "uri"
15+
require "uuid"
1216

1317
require "ro-bundle/version"
14-
require "ro-bundle/ro-dir"
18+
require "ro-bundle/util"
19+
require "ro-bundle/exceptions"
20+
require "ro-bundle/ro/agent"
21+
require "ro-bundle/ro/provenance"
22+
require "ro-bundle/ro/annotation"
23+
require "ro-bundle/ro/aggregate"
24+
require "ro-bundle/ro/manifest"
25+
require "ro-bundle/ro/directory"
1526
require "ro-bundle/file"
1627

1728
# This is a ruby library to read and write Research Object Bundle files in PK

0 commit comments

Comments
 (0)