This repository was archived by the owner on Apr 28, 2026. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments