bagit 0.3.0.pre → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. data/README.md +12 -3
  2. data/bagit.gemspec +2 -1
  3. data/bin/bagit +123 -0
  4. data/lib/bagit/manifest.rb +1 -2
  5. metadata +16 -11
  6. checksums.yaml +0 -15
data/README.md CHANGED
@@ -45,9 +45,18 @@ Example: validating an existing bag
45
45
  puts "#{existing_base_path} is not valid"
46
46
  end
47
47
 
48
+ Console Tool
49
+ ------------
50
+ # create a new bag/add files to existing bag
51
+ bagit add -f file1 file2 -t tagfile1 tagfile2 ./path/to/bag
52
+ # validate
53
+ bagit validate ./path/to/bag
54
+ # for other commands
55
+ bagit --help
56
+
48
57
  TODO
49
58
  ----
50
- * command line tools for common tasks
59
+ * deep directory add/delete for bag and tag files in console tools
51
60
  * better holy bag (fetch.txt) generation
52
61
  * better error reporting.
53
62
 
@@ -55,8 +64,8 @@ TODO
55
64
 
56
65
  Copyright © 2009, [Francesco Lazzarino](mailto:flazzarino@gmail.com).
57
66
 
58
- Current Maintainer: [Tom Johnson](mailto:thomas.johnson@oregonstate.edu).
67
+ Current maintainer: [Tom Johnson](mailto:thomas.johnson@oregonstate.edu).
59
68
 
60
- Sponsored by [Florida Center for Library Automation](http://www.fcla.edu).
69
+ Initial development sponsored by [Florida Center for Library Automation](http://www.fcla.edu).
61
70
 
62
71
  See LICENSE.txt for terms.
@@ -1,7 +1,7 @@
1
1
 
2
2
  BAGIT_SPEC = Gem::Specification.new do |spec|
3
3
  spec.name = "bagit"
4
- spec.version = '0.3.0.pre'
4
+ spec.version = '0.3.0'
5
5
  spec.summary = "BagIt package generation and validation"
6
6
  spec.description = "Ruby Library and Command Line tools for bagit"
7
7
  spec.email = "johnson.tom@gmail.com"
@@ -11,4 +11,5 @@ BAGIT_SPEC = Gem::Specification.new do |spec|
11
11
  spec.add_dependency 'validatable', '~> 1.6'
12
12
 
13
13
  spec.files = %w(Rakefile README.md LICENSE.txt bagit.gemspec) + Dir["lib/**/*.rb"]
14
+ spec.executables << 'bagit'
14
15
  end
@@ -0,0 +1,123 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bagit'
4
+ require 'docopt'
5
+
6
+ doc = <<DOCOPT
7
+ BagIt.
8
+
9
+ Usage:
10
+ #{__FILE__} add [-f <file>...] [-t <tagfile>...] BAGPATH
11
+ #{__FILE__} delete [-f <file>...] [-t <tagfile>...] BAGPATH
12
+ #{__FILE__} remove [-t <tagfile>...] BAGPATH
13
+ #{__FILE__} validate [-o] BAGPATH
14
+ #{__FILE__} manifest [-T] BAGPATH
15
+ #{__FILE__} list [--tags | --all] BAGPATH
16
+ #{__FILE__} -h | --version
17
+
18
+ Options:
19
+ -h --help Show this help screen.
20
+ --version Show version.
21
+ -f <file> File to add to/delete from bag. Repeatable.
22
+ -t <tag_file> Tag (metadata) file to add to/delete/remove from bag. Repeatable.
23
+ -T Force regeneration of tag manifest files.
24
+ -o --oxum Validate against oxum only (quick validate).
25
+ --tags List tag files.
26
+ --all List all data and tag files.
27
+
28
+ DOCOPT
29
+
30
+ # Possible commands for bag-info write
31
+ #
32
+ # #{__FILE__} new [--source-organization <org>] [--organization-address <org-addr>] [--contact-name <contact>]
33
+ # [--contact-phone <phone>] [--contact-email <email>] [--external-description <ext-desc>]
34
+ # [--external-identifier <ext-id>] [--group-identifier <group-id>] [--count <count>]
35
+ # [--internal-sender-identifier <sender-id>] [--internal-sender-description <sender-desc>]
36
+ # [--bag-info-entry <label> <value>] [-f <file>...] [-t <tagfile>...] BAGPATH
37
+
38
+ begin
39
+ opts = Docopt::docopt(doc, version: 'BagIt 0.3.0')
40
+
41
+ bag = BagIt::Bag.new(opts['BAGPATH'])
42
+
43
+ #####################################
44
+ # commands that don't alter the bag #
45
+ #####################################
46
+ if opts['validate']
47
+ if opts['--oxum']
48
+ puts bag.valid_oxum?.to_s
49
+ else
50
+ puts bag.valid?.to_s
51
+ end
52
+ # validation commands MUST NOT change manifest or bag-info files
53
+ exit
54
+ end
55
+
56
+ if opts['list']
57
+ files = bag.bag_files
58
+ if opts['--tags']
59
+ files = bag.tag_files
60
+ elsif opts['--all']
61
+ files = bag.bag_files + bag.tag_files
62
+ end
63
+ files.each { |f| puts f }
64
+ # quit here, too
65
+ exit
66
+ end
67
+
68
+
69
+ ######################################
70
+ # commands that may cause data loss! #
71
+ ######################################
72
+
73
+ #TODO: implement delete for data and tag files; remove for tag files.
74
+
75
+ # handle add/delete bag data files
76
+ unless opts['-f'].nil?
77
+ #TODO: add files in nested directories
78
+ opts['-f'].each { |datafile|
79
+ begin
80
+ if opts['add'] or opts['new']
81
+ bag.add_file(File.basename(datafile), datafile)
82
+ elsif opts['delete']
83
+ bag.remove_file(File.basename(datafile))
84
+ end
85
+ rescue Exception => e
86
+ puts "Failed operation on bag file: #{e.message}"
87
+ end
88
+ }
89
+ end
90
+
91
+ # handle adding tag files
92
+ unless opts['-t'].nil?
93
+ #TODO: add files in nested directories
94
+ opts['-t'].each { |tagfile|
95
+ begin
96
+ if opts['add'] or opts['new']
97
+ # if it does, try to manifest it
98
+ if File.exist?(File.join(bag.bag_dir, File.basename(tagfile)))
99
+ bag.add_tag_file(tagfile)
100
+ # otherwise, add it
101
+ else
102
+ bag.add_tag_file(File.basename(tagfile), tagfile)
103
+ end
104
+ elsif opts['delete']
105
+ bag.delete_tag_file(File.basename(tagfile))
106
+ elsif opts['remove']
107
+ bag.remove_tag_file(File.basename(tagfile))
108
+ end
109
+ rescue Exception => e
110
+ puts "Failed operation on tag file: #{e.message}"
111
+ end
112
+ }
113
+ end
114
+
115
+ # if we haven't quit yet, we need to re-manifest
116
+ # only do tags if tag files have been explictly added/removed or it is explictly called
117
+ bag.tagmanifest! if opts['-T'] or not opts['-t'].nil?
118
+ bag.manifest!
119
+
120
+ rescue Docopt::Exit => e
121
+ puts e.message
122
+ end
123
+
@@ -124,8 +124,7 @@ module BagIt
124
124
  def delete_tag_file(path)
125
125
  filepath = File.join(@bag_dir, path)
126
126
  raise "Tag file does not exist: #{path}" unless File.exist? filepath
127
- #TODO: delete tags even when they are not in the manifest
128
- remove_tag_file(path)
127
+ remove_tag_file(path) if tag_files.include?(path)
129
128
  FileUtils::rm filepath
130
129
  end
131
130
 
metadata CHANGED
@@ -1,18 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bagit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0.pre
4
+ version: 0.3.0
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Tom Johnson, Francesco Lazzarino
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-04-19 00:00:00.000000000 Z
12
+ date: 2013-04-28 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: validatable
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
19
  - - ~>
18
20
  - !ruby/object:Gem::Version
@@ -20,13 +22,15 @@ dependencies:
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
27
  - - ~>
25
28
  - !ruby/object:Gem::Version
26
29
  version: '1.6'
27
30
  description: Ruby Library and Command Line tools for bagit
28
31
  email: johnson.tom@gmail.com
29
- executables: []
32
+ executables:
33
+ - bagit
30
34
  extensions: []
31
35
  extra_rdoc_files: []
32
36
  files:
@@ -35,35 +39,36 @@ files:
35
39
  - LICENSE.txt
36
40
  - bagit.gemspec
37
41
  - lib/bagit.rb
38
- - lib/bagit/bag.rb
39
42
  - lib/bagit/string.rb
43
+ - lib/bagit/fetch.rb
40
44
  - lib/bagit/manifest.rb
41
45
  - lib/bagit/info.rb
42
46
  - lib/bagit/file.rb
43
47
  - lib/bagit/valid.rb
44
- - lib/bagit/fetch.rb
48
+ - lib/bagit/bag.rb
49
+ - bin/bagit
45
50
  homepage: http://github.com/tipr/bagit
46
51
  licenses: []
47
- metadata: {}
48
52
  post_install_message:
49
53
  rdoc_options: []
50
54
  require_paths:
51
55
  - lib
52
56
  required_ruby_version: !ruby/object:Gem::Requirement
57
+ none: false
53
58
  requirements:
54
59
  - - ! '>='
55
60
  - !ruby/object:Gem::Version
56
61
  version: '0'
57
62
  required_rubygems_version: !ruby/object:Gem::Requirement
63
+ none: false
58
64
  requirements:
59
- - - ! '>'
65
+ - - ! '>='
60
66
  - !ruby/object:Gem::Version
61
- version: 1.3.1
67
+ version: '0'
62
68
  requirements: []
63
69
  rubyforge_project:
64
- rubygems_version: 2.0.0
70
+ rubygems_version: 1.8.25
65
71
  signing_key:
66
- specification_version: 4
72
+ specification_version: 3
67
73
  summary: BagIt package generation and validation
68
74
  test_files: []
69
- has_rdoc:
checksums.yaml DELETED
@@ -1,15 +0,0 @@
1
- ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- NjFkNDZjYTUzYmMyOGZlMWZiOGM5YTJiMGU3ODM1ODRkNzYzZTY1OA==
5
- data.tar.gz: !binary |-
6
- NzU1ODcwNmZhZTI4NmE1YWJmMjNhN2FiNmYwNTFlMzhmMDFjZjY5OA==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- ZWJjMjYyYjk5NTMzNDgzMmYyNDE3NjM2YWRjNWUxMzk2NzM4NzAwMWVkY2Qy
10
- ODRiODllOGRkZmE5YTYxN2Q5NGZjNjdjZTMwZDdjNGJlMTY5NTFkOWVhMGMy
11
- MGJhYjFlNzAwNWQ2NmI5ZDk5ZDUxN2VkNDQxNjY0YTNmYjI1YTc=
12
- data.tar.gz: !binary |-
13
- YWFhNTcwZWU3OGU4Y2NiNzQ0NjYzM2ZjZmZjMmVlZDRiNTk2YjBlOWE4ZTkx
14
- NTM0Y2MxMmI1ZDhkMzYxOWY2OTNkOTQ1NGJmYWIwY2YwNzYwZjNiNmE3YWM4
15
- YmYwODE4Yzc5MWVmMjhmZDM4YzY4OWZlZmQ3Y2RiODdhYjA4Mjc=