dflat 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
data/dflat.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{dflat}
8
- s.version = "0.0.2"
8
+ s.version = "0.0.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Chris Beer"]
12
- s.date = %q{2010-11-26}
12
+ s.date = %q{2010-11-27}
13
13
  s.email = %q{chris@cbeer.info}
14
14
  s.extra_rdoc_files = [
15
15
  "LICENSE.txt",
@@ -28,6 +28,7 @@ Gem::Specification.new do |s|
28
28
  "lib/dflat/home.rb",
29
29
  "lib/dflat/version.rb",
30
30
  "lib/dnatural.rb",
31
+ "lib/redd.rb",
31
32
  "test/helper.rb",
32
33
  "test/test_dflat.rb"
33
34
  ]
data/lib/dflat.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'dflat/home'
2
2
  require 'dflat/version'
3
3
  require 'dnatural'
4
+ require 'redd'
4
5
  module Dflat
5
6
  VERSION = 'Dflat/0.19'
6
7
  end
data/lib/dflat/home.rb CHANGED
@@ -19,8 +19,8 @@ module Dflat
19
19
  ::Dir.mkdir path, integer
20
20
  d = Home.new path
21
21
  d.type = Dflat::VERSION
22
- v = d.version! 'v001', nil
23
22
  d.info = args[:info] || DEFAULT_PROPERTIES
23
+ d.init
24
24
  d
25
25
  end
26
26
 
@@ -53,33 +53,63 @@ module Dflat
53
53
  version(v)
54
54
  end
55
55
 
56
+ def next
57
+ v = next_version
58
+ version(v) if File.exists? File.join(path, v)
59
+ end
60
+
56
61
  def version version
57
62
  # xxx use namaste 'type' to load the right dir..
58
63
  Dflat::Version::Dir.load File.join(path, version)
59
64
  end
60
65
 
61
- def version! dest = nil, src = nil
66
+ def init
67
+ new_version('v001')
68
+ self.current = 'v001'
69
+ end
70
+
71
+ def checkout
62
72
  lock
63
- dest ||= next_version
64
- if src
65
- FileUtils.cp_r File.join(path, src), File.join(path, dest)
66
- else
67
- if current_version
68
- FileUtils.cp_r current.path, File.join(path, dest)
69
- else
70
- new_version(dest)
71
- self.current = dest
72
- end
73
+ if current_version and not File.exists? File.join(path, next_version)
74
+ FileUtils.cp_r current.path, File.join(path, next_version)
73
75
  end
76
+ unlock
77
+ return version(next_version)
78
+ end
74
79
 
80
+ def commit args = {}
81
+ lock
82
+ v = self.current = version(next_version)
75
83
  unlock
76
- return version(dest)
84
+ v
85
+ end
86
+
87
+ def commit!
88
+ lock
89
+ # xxx full -> redd?
90
+ previous = current
91
+ v = self.current = version(next_version)
92
+
93
+ previous.to_delta(current)
94
+
95
+ unlock
96
+ v
97
+ end
98
+
99
+ def export version
100
+ v = version(version)
101
+ return v if v.instance_of? Dflat::Version::Full
102
+ end
103
+
104
+ def [] version
105
+ export(version)
77
106
  end
78
107
 
79
108
  def current= version
80
109
  version = version.version if version.respond_to? :version
81
110
  return false unless File.directory? File.join(path, version)
82
111
  File.open(File.join(path, 'current.txt'), 'w') { |f| f.write(version) }
112
+
83
113
  @current = version
84
114
  end
85
115
 
@@ -91,6 +121,7 @@ module Dflat
91
121
  d = Dflat::Version::Dir.new path
92
122
  d.select &block
93
123
  end
124
+
94
125
  private
95
126
  def new_version version
96
127
  d = Dflat::Version::Full.mkdir File.join(path, version)
@@ -101,7 +132,11 @@ module Dflat
101
132
  end
102
133
 
103
134
  def next_version
104
- "v%03d" % (self.versions.map { |x| File.basename(x).sub(/^v/, '').to_i }.max + 1)
135
+ "v%03d" % (current_version.sub(/^v/, '').to_i + 1)
136
+ end
137
+
138
+ def update_directory_delta from, to = current
139
+
105
140
  end
106
141
  end
107
142
  end
data/lib/dflat/version.rb CHANGED
@@ -8,7 +8,10 @@ module Dflat
8
8
  include LockIt::Mixin
9
9
 
10
10
  def self.load path
11
- Full.new path
11
+ d = Dir.new path
12
+ return Full.new path if d.entries.any? { |f| f =~ /full/ }
13
+ return Delta.new path if types.any? { |t| t[:name] =~ /redd/i }
14
+ return Empty.new path
12
15
  end
13
16
 
14
17
  def version
@@ -41,15 +44,12 @@ module Dflat
41
44
  end
42
45
 
43
46
  class Full < Dir
44
- include Namaste::Mixin
45
- include LockIt::Mixin
46
-
47
47
  DATA_DIR = 'full'
48
48
 
49
49
  def self.mkdir path, integer = 0777, args = {}
50
50
  super path, integer
51
51
  d = Full.new path
52
- Dnatural::Dir.mkdir File.join(d.path, 'full')
52
+ Dnatural::Dir.mkdir File.join(d.path, DATA_DIR)
53
53
  d
54
54
  end
55
55
 
@@ -87,6 +87,35 @@ module Dflat
87
87
  unlock
88
88
  end
89
89
 
90
+ def to_delta version
91
+ redd = ReDD::Dir.mkdir File.join(self.path, Delta::DATA_DIR)
92
+ delta = Delta.new self.path
93
+
94
+ old = self.manifest.to_hash
95
+ new = version.manifest.to_hash
96
+
97
+ changeset = {:delete => [], :add => []}
98
+
99
+ new.select do |filename, entry|
100
+ changeset[:delete] << filename unless old[filename] and old[filename] == entry[filename]
101
+ end
102
+
103
+ old.select do |filename, entry|
104
+ changeset[:add] << filename unless new[filename] and old[filename] == entry[filename]
105
+ end
106
+
107
+ changeset[:delete].each do |filename|
108
+ delta.remove filename
109
+ end
110
+
111
+ changeset[:add].each do |filename|
112
+ delta.add File.join(data_path, filename), filename
113
+ end
114
+
115
+ FileUtils.rm_rf data_path
116
+ return delta
117
+ end
118
+
90
119
  private
91
120
  def data_path
92
121
  File.join(self.path, DATA_DIR)
@@ -94,7 +123,56 @@ module Dflat
94
123
  def manifest_path
95
124
  File.join(path, 'manifest.txt')
96
125
  end
126
+ end
127
+ class Delta < Dir
128
+ DATA_DIR = 'delta'
129
+
130
+ def self.mkdir path, integer = 0777, args = {}
131
+ super path, integer
132
+ d = Delta.new path
133
+ @redd = ReDD::Dir.mkdir File.join(d.path, DATA_DIR)
134
+ d
135
+ end
136
+
137
+ def initialize path
138
+ super path
139
+ @redd = ReDD::Dir.new File.join(path, DATA_DIR)
140
+ end
141
+
142
+ def add source, dest, options = {}
143
+ manifest!
144
+ f = @redd.add source, dest, options
145
+ m = manifest.add dest, :base => File.join(data_path, 'add')
146
+ File.open(File.join(path, 'manifest.txt'), 'w') do |f|
147
+ f.write(m.to_s)
148
+ end
149
+
150
+ f
151
+ end
97
152
 
153
+ def remove list, options = {}
154
+ list = [list] if list.instance_of? String
155
+ @redd.remove list.map { |x| x }, options
156
+ m = manifest!
157
+ list.each do |l|
158
+ m = m.remove l
159
+ end
160
+
161
+ File.open(File.join(path, 'manifest.txt'), 'w') do |f|
162
+ f.write(m.to_s)
163
+ end
164
+ end
165
+
166
+ private
167
+ def data_path
168
+ File.join(self.path, DATA_DIR)
169
+ end
170
+ def dmanifest_path
171
+ File.join(path, 'd-manifest.txt')
172
+ end
173
+ def manifest_path
174
+ File.join(path, 'manifest.txt')
175
+ end
98
176
  end
99
177
  end
100
178
  end
data/lib/redd.rb ADDED
@@ -0,0 +1,39 @@
1
+ require 'checkm'
2
+ require 'namaste'
3
+ require 'fileutils'
4
+
5
+ module ReDD
6
+ VERSION = 'ReDD/0.1'
7
+ class Dir < ::Dir
8
+ include Namaste::Mixin
9
+
10
+ def self.mkdir path, integer=0777, args = {}
11
+ super path, integer
12
+ d = Dir.new path
13
+ d.type = Dnatural::VERSION
14
+
15
+ ::Dir.chdir(d.path) do
16
+ ::Dir.mkdir 'add'
17
+ FileUtils.touch 'delete.txt'
18
+ end
19
+ d
20
+ end
21
+
22
+ def list
23
+ NoMethodError
24
+ end
25
+
26
+ def add src, dest, options = {}
27
+ FileUtils.mkdir_p File.dirname(File.join(path, 'add', dest))
28
+ file = FileUtils.cp src, File.join(path, 'add', dest), options
29
+ File.new File.join(path, 'add', dest)
30
+ end
31
+
32
+ def remove list, options = {}
33
+ list = [list] if list.instance_of? String
34
+ File.open(File.join(path, 'delete.txt'), 'w') do |f|
35
+ f.write list.join("\n")
36
+ end
37
+ end
38
+ end
39
+ end
data/test/test_dflat.rb CHANGED
@@ -59,15 +59,57 @@ class TestDflat < Test::Unit::TestCase
59
59
  end
60
60
 
61
61
  should "do basic dnatural versioning" do
62
- version = @dflat.version!
62
+ version = @dflat.checkout
63
63
 
64
64
  assert_equal(@dflat.current.version, 'v001')
65
65
  assert_equal(open(File.join(@dflat.path, 'current.txt')).read, 'v001')
66
+
67
+ @dflat.commit
66
68
 
67
- @dflat.current = version
68
-
69
- assert_equal(File.basename(version.path), 'v002')
69
+ assert_equal(version.version, 'v002')
70
70
  assert_equal(open(File.join(@dflat.path, 'current.txt')).read, 'v002')
71
71
  end
72
+
73
+ should "handle ReDD versioning" do
74
+
75
+ previous = @dflat.current
76
+ version = @dflat.checkout
77
+ @dflat.commit!
78
+
79
+ assert(File.exists? File.join(previous.path, 'delta'))
80
+ end
81
+
82
+ should "handle ReDD adds" do
83
+
84
+ previous = @dflat.current
85
+ version = @dflat.checkout
86
+ version.add 'LICENSE.txt', 'producer/abcdef'
87
+ @dflat.commit!
88
+
89
+ assert(File.exists? File.join(previous.path, 'delta'))
90
+ assert_equal(open(File.join(previous.path, 'delta', 'delete.txt')).read, 'producer/abcdef')
91
+ end
92
+
93
+ should "handle ReDD removes" do
94
+ previous = @dflat.current
95
+ previous.add 'LICENSE.txt', 'producer/abcdef'
96
+ version = @dflat.checkout
97
+ version.remove 'producer/abcdef'
98
+ @dflat.commit!
99
+
100
+ assert(File.exists? File.join(previous.path, 'delta', 'add', 'producer', 'abcdef'))
101
+ end
102
+
103
+ should "handle ReDD modifies" do
104
+ previous = @dflat.current
105
+ previous.add 'LICENSE.txt', 'producer/abcdef'
106
+ version = @dflat.checkout
107
+ version.add 'README.rdoc', 'producer/abcdef'
108
+ @dflat.commit!
109
+
110
+ assert(File.exists? File.join(previous.path, 'delta', 'add', 'producer', 'abcdef'))
111
+ assert_equal(open(File.join(previous.path, 'delta', 'delete.txt')).read, 'producer/abcdef')
112
+ end
113
+
72
114
  end
73
115
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dflat
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Chris Beer
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-26 00:00:00 -05:00
18
+ date: 2010-11-27 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -170,6 +170,7 @@ files:
170
170
  - lib/dflat/home.rb
171
171
  - lib/dflat/version.rb
172
172
  - lib/dnatural.rb
173
+ - lib/redd.rb
173
174
  - test/helper.rb
174
175
  - test/test_dflat.rb
175
176
  has_rdoc: true