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

Commit 019cbcb

Browse files
committed
Add a new example script "dir2ro".
1 parent 0966a18 commit 019cbcb

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

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

0 commit comments

Comments
 (0)