rally_workspace_utils 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -14,4 +14,6 @@ lib/translate/copy/test_case_result_copy.rb
14
14
  lib/translate/copy/defect_copy.rb
15
15
  lib/translate/copy/object_copy.rb
16
16
  lib/translate/copy/test_case_copy.rb
17
+ lib/translate/translation_store.rb
18
+ test/translation_store_spec.rb
17
19
  lib/rally_workspace_utils.rb
@@ -40,6 +40,7 @@ args = {:base_url => "https://rally1.rallydev.com/slm"}
40
40
  debug = false
41
41
  audit = false
42
42
  logfile = STDOUT
43
+ $VERBOSE = nil
43
44
 
44
45
  opts.each do |opt, arg|
45
46
  case opt
@@ -4,6 +4,7 @@ class ObjectCopy
4
4
  end
5
5
 
6
6
  def copy(new_workspace, additional_values = {})
7
+ @object.rally_rest.logger.info "Copying #{@object.type} -- #{@object.name}"
7
8
  values = shallow_copy(@object, new_workspace)
8
9
  values.merge! additional_values
9
10
 
@@ -18,8 +19,7 @@ class ObjectCopy
18
19
  end
19
20
 
20
21
  def remember old, new
21
- $TRANSLATED ||= {}
22
- $TRANSLATED[old.oid] = new.oid
22
+ TranslationStore[old.oid] = new.oid
23
23
  end
24
24
 
25
25
  def create_object(rally_rest, values)
@@ -85,7 +85,7 @@ class ObjectCopy
85
85
 
86
86
  def fetch_object(type, oid, workspace)
87
87
  @@cached_objects ||= {}
88
- new_oid = $TRANSLATED[oid]
88
+ new_oid = TranslationStore[oid]
89
89
  return @@cached_objects[new_oid] if @@cached_objects.key? oid
90
90
 
91
91
  object = @object.rally_rest.find(type, :workspace => workspace) { equal :object_i_d, new_oid }.first
@@ -1,5 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/copy'
2
2
  require File.dirname(__FILE__) + '/translation_audit'
3
+ require File.dirname(__FILE__) + '/translation_store'
3
4
 
4
5
  class Translate
5
6
  include TranslationAudit
@@ -13,7 +14,6 @@ class Translate
13
14
  @from_workspace_name = args[:from_workspace]
14
15
  @to_workspace_name = args[:to_workspace]
15
16
  @logger = args[:logger] if args[:logger]
16
- $TRANSLATED ||= {}
17
17
  end
18
18
 
19
19
  def run
@@ -25,41 +25,30 @@ class Translate
25
25
  raise "No such workspace #{@from_workspace_name}" unless @from_workspace
26
26
  raise "No such workspace #{@to_workspace_name}" unless @to_workspace
27
27
 
28
-
29
- if File::exists? "TRANSLATED"
30
- File.open("TRANSLATED", "r") do |f|
31
- $TRANSLATED = Marshal.load(f)
32
- end
33
-
34
- if $TRANSLATED[:from] != @from_workspace.oid || $TRANSLATED[:to] != @to_workspace.oid
35
- $TRANSLATED = {}
36
- $TRANSLATED[:from] = @from_workspace.oid
37
- $TRANSLATED[:to] = @to_workspace.oid
38
- end
28
+ store = TranslationStore.instance(@from_workspace, @to_workspace)
29
+
30
+ begin
31
+ # now do the copy
32
+ [:iteration, :release, :story, :defect, :test_case].each do |type|
33
+ # @slm.find_all(type, :workspace => @from_workspace, :order => [:creation_date, :desc]).each do |o|
34
+ @slm.find_all(type, :workspace => @from_workspace).each do |o|
35
+ o.copy(@to_workspace) unless TranslationStore[o.oid]
36
+ end
37
+ end unless store.copy_finished?
38
+ store.copy_finished!
39
+
40
+ # Now tangle the objects
41
+ [:test_case, :defect].each do |type|
42
+ @slm.find_all(type, :workspace => @from_workspace).each do |o|
43
+ o.tangle(@to_workspace)
44
+ end
45
+ end unless store.tangle_finished?
46
+ store.tangle_finished!
47
+ rescue Exception => e
48
+ @logger.info "Caught an exception #{e}. Remembering where we were."
49
+ # Remember where we were if there was a failure
50
+ store.dump
39
51
  end
40
-
41
- # now do the copy
42
- [:iteration, :release, :story, :defect, :test_case].each do |type|
43
- @slm.find_all(type, :workspace => @from_workspace).each do |o|
44
- @logger.info "Copying #{o.type} -- #{o.name}"
45
- o.copy(@to_workspace)
46
- end
47
- end unless $TRANSLATED[:copy]
48
- # mark these workspaces as copied
49
- $TRANSLATED[:copy] = true
50
- # dump the oids to disk
51
- dump_oids
52
-
53
- # Now tangle the objects
54
- [:test_case, :defect].each do |type|
55
- @slm.find_all(type, :workspace => @from_workspace).each do |o|
56
- @logger.info "Tangle #{o.type} -- #{o.name}"
57
- o.tangle(@to_workspace)
58
- end
59
- end unless $TRANSLATED[:tangle]
60
-
61
- $TRANSLATED[:tangle] = true
62
- dump_oids
63
52
  end
64
53
 
65
54
  def dump_oids
@@ -55,7 +55,7 @@ module TranslationAudit
55
55
 
56
56
  def compare_each(type)
57
57
  @slm.find_all(type, :workspace => @from_workspace).each do |old_object|
58
- new_object = @slm.find(type, :workspace => @to_workspace) { equal :object_i_d, $TRANSLATED[old_object.oid] }.first
58
+ new_object = @slm.find(type, :workspace => @to_workspace) { equal :object_i_d, TranslationStore[old_object.oid] }.first
59
59
  if new_object.nil?
60
60
  self.logger.info "Cound not find a copy for object #{old_object.type} -- #{old_object.name} -- #{old_object.oid}"
61
61
  next
@@ -0,0 +1,76 @@
1
+
2
+ class TranslationStore
3
+ private_class_method :new
4
+
5
+ def TranslationStore.instance(from_workspace = nil, to_workspace = nil)
6
+ unless defined? @@instance
7
+ raise "TranslationStory needs to be initialized with two workspaces" unless from_workspace && to_workspace
8
+ @@instance = new(from_workspace, to_workspace)
9
+ end
10
+ @@instance
11
+ end
12
+
13
+ def TranslationStore.[](key)
14
+ instance[key]
15
+ end
16
+
17
+ def TranslationStore.[]=(key, value)
18
+ instance[key] = value
19
+ end
20
+
21
+ def initialize(w1, w2)
22
+ @w1 = w1.oid
23
+ @w2 = w2.oid
24
+ @store = {}
25
+ @store[:copy] = false
26
+ @store[:tangle] = false
27
+ load
28
+ end
29
+
30
+ def [](key)
31
+ @store[key]
32
+ end
33
+
34
+ def []=(key, value)
35
+ @store[key] = value
36
+ end
37
+
38
+ def copy_finished!
39
+ @store[:copy] = true
40
+ dump
41
+ end
42
+
43
+ def copy_finished?
44
+ @store[:copy] == true
45
+ end
46
+
47
+ def tangle_finished!
48
+ @store[:tangle] = true
49
+ dump
50
+ end
51
+
52
+ def tangle_finished?
53
+ @store[:tangle] == true
54
+ end
55
+
56
+ def dump
57
+ File.open(filename, "w+") do |f|
58
+ Marshal.dump(@store, f)
59
+ end
60
+ end
61
+
62
+ def load
63
+ File.open(filename, "r") do |f|
64
+ @store = Marshal.load(f)
65
+ end if File.exists? filename
66
+ end
67
+
68
+ def filename
69
+ "translate-#{@w1}-#{@w2}"
70
+ end
71
+
72
+ def cleanup
73
+ File.delete(filename) if File.exists? filename
74
+ end
75
+
76
+ end
@@ -2,7 +2,7 @@ module Translate #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- TINY = 2
5
+ TINY = 3
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -0,0 +1,123 @@
1
+
2
+ require 'rubygems'
3
+ require 'spec'
4
+
5
+ require File.dirname(__FILE__) + '/../lib/translate/translation_store'
6
+
7
+ context "A TranslationStore singleton" do
8
+
9
+ setup do
10
+ @workspace1 = Object.new
11
+ @workspace1.stub!(:oid).and_return(12345)
12
+ @workspace2 = Object.new
13
+ @workspace2.stub!(:oid).and_return(54321)
14
+ end
15
+
16
+ teardown do
17
+ TranslationStore.send(:remove_class_variable, :@@instance) rescue ""
18
+ end
19
+
20
+ specify "should only have a single instance" do
21
+ lambda { TranslationStore.new }.should_raise Exception
22
+ TranslationStore.should_respond_to :instance
23
+ end
24
+
25
+ specify "singleton should be initialized with two workspaces" do
26
+
27
+ lambda { TranslationStore.instance }.should_raise Exception
28
+ lambda { TranslationStore.instance(nil, nil) }.should_raise Exception
29
+ lambda { TranslationStore.instance(nil, @workspace1) }.should_raise Exception
30
+ lambda { TranslationStore.instance(@workspace1, nil) }.should_raise Exception
31
+ lambda { TranslationStore[1] = 2 }.should_raise Exception
32
+ lambda { TranslationStore.instance(@workspace1, @workspace2) }.should_not_raise Exception
33
+ end
34
+
35
+ specify "singleton should return an instance of TranslationStory when initialized with two workspaces" do
36
+ TranslationStore.instance(@workspace1, @workspace2).should_be_instance_of TranslationStore
37
+ end
38
+ end
39
+
40
+ context "A TranslationStore" do
41
+ setup do
42
+ @workspace1 = Object.new
43
+ @workspace1.stub!(:oid).and_return(12345)
44
+ @workspace2 = Object.new
45
+ @workspace2.stub!(:oid).and_return(54321)
46
+ @store = TranslationStore.instance(@workspace1, @workspace2)
47
+ end
48
+
49
+ teardown do
50
+ @store.cleanup
51
+ TranslationStore.send(:remove_class_variable, :@@instance) rescue ""
52
+ end
53
+
54
+ specify "should store mappings of old oids to new oids" do
55
+ @store[12345] = 54321
56
+ @store[12345].should_be 54321
57
+
58
+ TranslationStore[1] = 2
59
+ TranslationStore[1].should_be 2
60
+ end
61
+
62
+ specify "should write all contents to a file" do
63
+ @store[1] = 2
64
+ @store.dump
65
+ File.exists?("translate-12345-54321").should_be true
66
+ end
67
+
68
+ specify "should cleanup file" do
69
+ @store[1] = 2
70
+ @store.dump
71
+ File.exists?("translate-12345-54321").should_be true
72
+ @store.cleanup
73
+ File.exists?("translate-12345-54321").should_be false
74
+ end
75
+
76
+ specify "should read contents from a file" do
77
+ @store[1] = 2
78
+ @store.dump
79
+ File.exists?("translate-12345-54321").should_be true
80
+ TranslationStore.send(:remove_class_variable, :@@instance) rescue ""
81
+ @store = TranslationStore.instance(@workspace1, @workspace2)
82
+ @store[1].should_be 2
83
+ end
84
+
85
+ specify "should read from a file, only when the workspace oids match" do
86
+ @store[1] = 2
87
+ @store.dump
88
+ TranslationStore.send(:remove_class_variable, :@@instance) rescue ""
89
+
90
+ @workspace2 = Object.new
91
+ @workspace2.stub!(:oid).and_return(11111)
92
+ @store = TranslationStore.instance(@workspace1, @workspace2)
93
+ @store.load
94
+ @store[1].should_be nil
95
+ end
96
+
97
+ specify "should remember when the copy is finished" do
98
+ @store.copy_finished?.should_be false
99
+ @store.copy_finished!
100
+ @store.copy_finished?.should_be true
101
+
102
+ @store.dump
103
+ TranslationStore.send(:remove_class_variable, :@@instance) rescue ""
104
+ @store = TranslationStore.instance(@workspace1, @workspace2)
105
+ @store.load
106
+
107
+ @store.copy_finished?.should_be true
108
+ end
109
+
110
+ specify "should remember when the tangle is finished" do
111
+ @store.tangle_finished?.should_be false
112
+ @store.tangle_finished!
113
+ @store.tangle_finished?.should_be true
114
+
115
+ @store.dump
116
+ TranslationStore.send(:remove_class_variable, :@@instance) rescue ""
117
+ @store = TranslationStore.instance(@workspace1, @workspace2)
118
+ @store.load
119
+
120
+ @store.tangle_finished?.should_be true
121
+ end
122
+
123
+ end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: rally_workspace_utils
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.2
7
- date: 2006-12-19 00:00:00 -07:00
6
+ version: 0.0.3
7
+ date: 2006-12-20 00:00:00 -07:00
8
8
  summary: A utility to translate a UseCase workspace to a UserStory workspace
9
9
  require_paths:
10
10
  - lib
@@ -45,6 +45,8 @@ files:
45
45
  - lib/translate/copy/defect_copy.rb
46
46
  - lib/translate/copy/object_copy.rb
47
47
  - lib/translate/copy/test_case_copy.rb
48
+ - lib/translate/translation_store.rb
49
+ - test/translation_store_spec.rb
48
50
  - lib/rally_workspace_utils.rb
49
51
  test_files:
50
52
  - test/rally_workspace_utils_test.rb