checkm 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/VERSION +1 -1
  2. data/checkm.gemspec +64 -0
  3. data/lib/checkm.rb +55 -23
  4. data/test/test_checkm.rb +27 -0
  5. metadata +4 -3
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 0.0.1
@@ -0,0 +1,64 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{checkm}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Chris Beer"]
12
+ s.date = %q{2010-11-26}
13
+ s.email = %q{chris@cbeer.info}
14
+ s.extra_rdoc_files = [
15
+ "LICENSE.txt",
16
+ "README.rdoc"
17
+ ]
18
+ s.files = [
19
+ ".document",
20
+ "Gemfile",
21
+ "Gemfile.lock",
22
+ "LICENSE.txt",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "checkm.gemspec",
27
+ "lib/checkm.rb",
28
+ "test/helper.rb",
29
+ "test/test_1/1",
30
+ "test/test_checkm.rb"
31
+ ]
32
+ s.homepage = %q{http://github.com/cbeer/checkm}
33
+ s.licenses = ["MIT"]
34
+ s.require_paths = ["lib"]
35
+ s.rubygems_version = %q{1.3.7}
36
+ s.summary = %q{Checkm is a general-purpose text-based file manifest format}
37
+ s.test_files = [
38
+ "test/helper.rb",
39
+ "test/test_checkm.rb"
40
+ ]
41
+
42
+ if s.respond_to? :specification_version then
43
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
44
+ s.specification_version = 3
45
+
46
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
47
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
48
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
49
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
50
+ s.add_development_dependency(%q<rcov>, [">= 0"])
51
+ else
52
+ s.add_dependency(%q<shoulda>, [">= 0"])
53
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
54
+ s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
55
+ s.add_dependency(%q<rcov>, [">= 0"])
56
+ end
57
+ else
58
+ s.add_dependency(%q<shoulda>, [">= 0"])
59
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
60
+ s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
61
+ s.add_dependency(%q<rcov>, [">= 0"])
62
+ end
63
+ end
64
+
@@ -1,4 +1,27 @@
1
+ require 'time'
2
+
1
3
  module Checkm
4
+ CHUNK_SIZE = 8*1024*1024
5
+ def self.checksum file, alg
6
+ digest_alg = case alg
7
+ when nil
8
+ return true
9
+ when /md5/
10
+ Digest::MD5.new if alg == 'md5'
11
+ when /sha1/
12
+ when /sha256/
13
+ when /dir/
14
+ return File.directory? file
15
+ else
16
+ return false
17
+ end
18
+
19
+ while not file.eof? and chunk = file.readpartial(CHUNK_SIZE)
20
+ digest_alg << chunk
21
+ end
22
+ digest_alg.hexdigest
23
+ end
24
+
2
25
  class Manifest
3
26
  def self.parse str, args = {}
4
27
  Manifest.new str, args
@@ -10,6 +33,7 @@ module Checkm
10
33
  attr_reader :path
11
34
 
12
35
  def initialize checkm, args = {}
36
+ @args = args
13
37
  @version = nil
14
38
  @checkm = checkm
15
39
  @lines = checkm.split "\n"
@@ -20,6 +44,26 @@ module Checkm
20
44
  @path ||= Dir.pwd
21
45
  parse_lines
22
46
  # xxx error on empty entries?
47
+ @lines.unshift('#%checkm_0.7') and @version = '0.7' if @version.nil?
48
+
49
+ end
50
+
51
+ def valid?
52
+ @entries.map { |e| e.valid? }.any? { |b| b == false }
53
+ end
54
+
55
+ def add path, args = {}
56
+ line = Checkm::Entry.create path, args
57
+
58
+ Checkm::Manifest.new [@lines, line].flatten.join("\n"), args
59
+ end
60
+
61
+ def remove path
62
+ Checkm::Manifest.new @lines.reject { |x| x =~ /^@?#{path}/ }.join("\n"), args
63
+ end
64
+
65
+ def to_s
66
+ @lines.join("\n")
23
67
  end
24
68
 
25
69
  private
@@ -67,17 +111,20 @@ module Checkm
67
111
  @entries << Entry.new(line, self)
68
112
  end
69
113
 
70
- def valid?
71
- @entries.map { |e| e.valid? }.any? { |b| b == false }
72
- end
73
-
74
114
  end
75
115
 
76
116
  class Entry
77
- CHUNK_SIZE = 8*1024*1024
78
117
  BASE_FIELDS = ['sourcefileorurl', 'alg', 'digest', 'length', 'modtime', 'targetfileorurl']
79
118
  attr_reader :values
80
119
 
120
+ def self.create path, args = {}
121
+ base = args[:base] || Dir.pwd
122
+ alg = args[:alg] || 'md5'
123
+ file = File.new File.join(base, path)
124
+
125
+ "%s | %s | %s | %s | %s | %s" % [path, alg, Checkm.checksum(file, alg), File.size(file.path), file.mtime.utc.xmlschema, nil]
126
+ end
127
+
81
128
  def initialize line, manifest = nil
82
129
  @line = line.strip
83
130
  @include = false
@@ -109,26 +156,11 @@ module Checkm
109
156
 
110
157
  def valid_checksum?
111
158
  file = File.new source
112
- digest_alg = case alg
113
- when nil
114
- return true
115
- when /md5/
116
- Digest::MD5.new if alg == 'md5'
117
- when /sha1/
118
- when /sha256/
119
- when /dir/
120
- return File.directory? file
121
- else
122
- return false
123
- end
124
-
125
- while not file.eof? and chunk = file.readpartial(CHUNK_SIZE)
126
- digest_alg << chunk
127
- end
128
-
129
- return digest_alg.hexdigest == digest
159
+ checksum = Checkm.checksum(file, alg)
160
+ checksum === true or checksum == digest
130
161
  end
131
162
 
163
+
132
164
  def valid_length?
133
165
  throw NotImplementedError
134
166
  end
@@ -80,4 +80,31 @@ class TestCheckm < Test::Unit::TestCase
80
80
  assert_equal(res.entries.length, 1)
81
81
  assert_equal(res.entries.first.valid?, false)
82
82
  end
83
+
84
+ def test_create_entry
85
+ res = Checkm::Entry.create('LICENSE.txt')
86
+ assert_match( /LICENSE\.txt | md5 | 927368f89ca84dbec878a8d017f06443 | 1054 | \d{4}/, res)
87
+ end
88
+
89
+ def test_manifest_add
90
+ m = Checkm::Manifest.parse('')
91
+ n = m.add('LICENSE.txt')
92
+ assert_equal(n.entries.length, 1)
93
+ assert_equal(n.entries.first.valid?, true)
94
+ end
95
+
96
+ def test_manifest_add
97
+ m = Checkm::Manifest.parse('')
98
+ n = m.add('LICENSE.txt')
99
+ assert_equal(n.entries.length, 1)
100
+ assert_equal(n.entries.first.valid?, true)
101
+ end
102
+
103
+ def test_manifest_to_s
104
+ m = Checkm::Manifest.parse('')
105
+ n = m.add('LICENSE.txt')
106
+ lines = n.to_s.split "\n"
107
+ assert_equal(lines[0], '#%checkm_0.7')
108
+ assert_match(/^LICENSE\.txt/, lines[1])
109
+ end
83
110
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: checkm
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 0
10
- version: 0.0.0
9
+ - 1
10
+ version: 0.0.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Chris Beer
@@ -95,6 +95,7 @@ files:
95
95
  - README.rdoc
96
96
  - Rakefile
97
97
  - VERSION
98
+ - checkm.gemspec
98
99
  - lib/checkm.rb
99
100
  - test/helper.rb
100
101
  - test/test_1/1