yggdrasil 0.0.12 → 0.0.13

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.
@@ -14,56 +14,65 @@ class Yggdrasil
14
14
 
15
15
  updates = sync_mirror
16
16
  matched_updates = select_updates(updates, @arg_paths)
17
- if matched_updates.size == 0
18
- puts 'no files.'
19
- return
20
- end
21
17
 
22
- confirmed_updates = confirm_updates(matched_updates) do |relative_path|
18
+ check_result = String.new
19
+ if matched_updates.size != 0
20
+ confirmed_updates = confirm_updates(matched_updates) do |relative_path|
21
+ FileUtils.cd @mirror_dir do
22
+ cmd = "#@svn diff --no-auth-cache --non-interactive #{relative_path}"
23
+ cmd += username_password_options_to_read_repo
24
+ puts system3(cmd)
25
+ end
26
+ end
27
+ return unless confirmed_updates
28
+ return if confirmed_updates.size == 0
29
+
30
+ ############## add status information to check_result
23
31
  FileUtils.cd @mirror_dir do
24
- cmd = "#@svn diff --no-auth-cache --non-interactive #{relative_path}"
32
+ cmd = "#@svn status -quN --no-auth-cache --non-interactive"
25
33
  cmd += username_password_options_to_read_repo
26
- puts system3(cmd)
34
+ cmd += " #{confirmed_updates.join(' ')}"
35
+ check_result = system3(cmd)
27
36
  end
28
- end
29
- return unless confirmed_updates
30
- return if confirmed_updates.size == 0
31
-
32
- check_result = String.new
33
- FileUtils.cd @mirror_dir do
34
- cmd = "#@svn status -quN --no-auth-cache --non-interactive"
35
- cmd += username_password_options_to_read_repo
36
- cmd += " #{confirmed_updates.join(' ')}"
37
- check_result = system3(cmd)
38
- end
39
- check_result.gsub!(/^Status against revision:.*\n/, '')
40
- check_result.chomp!
41
- result_array = check_result.split("\n")
42
- result_array.sort!.uniq!
43
- check_result = result_array.join("\n")
44
-
45
- if check_result == ''
46
- puts 'yggdrasil check: OK!'
47
- else
37
+ check_result.gsub!(/^Status against revision:.*\n/, '')
38
+ check_result.chomp!
39
+ result_array = check_result.split("\n")
40
+ result_array.sort!.uniq!
41
+ check_result = result_array.join("\n")
48
42
  check_result << "\n\n"
43
+
44
+ ############## add diff information to check_result
49
45
  cmd = "#@svn diff --no-auth-cache --non-interactive"
50
46
  cmd += username_password_options_to_read_repo
51
47
  cmd += " #{confirmed_updates.join(' ')}"
52
48
  FileUtils.cd @mirror_dir do
53
49
  check_result << system3(cmd)
54
50
  end
55
- puts check_result
56
51
  end
57
52
 
58
- if /^(.+):(\d+)$/ =~ @options[:server]
59
- host = $1
60
- port = $2
61
- # put check_result to server
62
- sock = TCPSocket.open(host, port)
63
- error "can not connect to server: #{host}:#{port}" if sock.nil?
64
- sock.puts "put_result #{Socket.gethostname}"
65
- sock.puts check_result
66
- sock.close
53
+ if @arg_paths.size == 1 && @arg_paths[0] == '/'
54
+ if /^(.+):(\d+)$/ =~ @options[:server]
55
+ host = $1
56
+ port = $2
57
+ # put check_result to server
58
+ sock = TCPSocket.open(host, port)
59
+ error "can not connect to server: #{host}:#{port}" if sock.nil?
60
+ sock.puts "put_result #{Socket.gethostname}"
61
+ sock.puts check_result
62
+ sock.close
63
+ end
64
+ if check_result == ''
65
+ puts 'Yggdrasil check: OK.'
66
+ else
67
+ puts check_result
68
+ puts "\nYggdrasil check: NG!!!"
69
+ end
70
+ else
71
+ if check_result == ''
72
+ puts 'no files.'
73
+ else
74
+ puts check_result
75
+ end
67
76
  end
68
77
  end
69
78
  end
@@ -119,6 +119,7 @@ Valid options:
119
119
  --password ARG : specify a password ARG
120
120
  --server ARG : specify a server address and port
121
121
  e.g. 192.168.1.35:4000
122
+ see also 'yggserve help'
122
123
 
123
124
  EOS
124
125
  when 'list', 'ls' ########################################### list (ls)
@@ -1,5 +1,5 @@
1
1
  class Yggdrasil
2
- VERSION = '0.0.12'
2
+ VERSION = '0.0.13'
3
3
 
4
4
  def version
5
5
  puts <<"EOS"
@@ -6,7 +6,10 @@ class YggdrasilServer
6
6
  error "invalid arguments: #{(@arg_options+@arg_paths).join(', ')}"
7
7
  end
8
8
 
9
- puts "Start: yggdrasil server (port:#@port)"
9
+ ctime = Time.now
10
+ $stdout.printf "Start: yggdrasil server (port:#@port)[%04d-%02d-%02d %02d:%02d:%02d.%03d]\n",
11
+ ctime.year, ctime.month, ctime.day, ctime.hour, ctime.min, ctime.sec, (ctime.usec/1000).round
12
+ $stdout.flush
10
13
  TCPServer.do_not_reverse_lookup = true
11
14
  s0 = TCPServer.open(@port.to_i)
12
15
  loop do
@@ -15,8 +18,9 @@ class YggdrasilServer
15
18
  ctime = Time.now
16
19
  if msg && msg.chomp! != MESSAGE_QUIT
17
20
  msg.chomp!
18
- printf "RCV[%04d-%02d-%02d %02d:%02d:%02d.%03d](#{sock.peeraddr[3]}): #{msg}\n",
21
+ $stdout.printf "RCV[%04d-%02d-%02d %02d:%02d:%02d.%03d](#{sock.peeraddr[3]}): #{msg}\n",
19
22
  ctime.year, ctime.month, ctime.day, ctime.hour, ctime.min, ctime.sec, (ctime.usec/1000).round
23
+ $stdout.flush
20
24
  msg_parts = msg.split
21
25
  if msg_parts.size != 0
22
26
  msg_cmd = msg_parts[0]
@@ -32,11 +36,18 @@ class YggdrasilServer
32
36
  send msg_cmd, sock, msg_arg_hash
33
37
  else
34
38
  puts "fail: number of arguments is mismatch: #{msg}"
39
+ $stdout.flush
35
40
  end
36
41
  end
37
42
  end
38
43
  sock.close
39
- break if @options.has_key?(:debug?) && msg == MESSAGE_QUIT
44
+ if @options.has_key?(:debug?) && msg == MESSAGE_QUIT
45
+ ctime = Time.now
46
+ $stdout.printf "Quit: yggdrasil server (port:#@port)[%04d-%02d-%02d %02d:%02d:%02d.%03d]\n",
47
+ ctime.year, ctime.month, ctime.day, ctime.hour, ctime.min, ctime.sec, (ctime.usec/1000).round
48
+ $stdout.flush
49
+ break
50
+ end
40
51
  end
41
52
  s0.close # MESSAGE_QUIT
42
53
  end
data/spec/check_spec.rb CHANGED
@@ -95,6 +95,8 @@ Index: tmp/yggdrasil-test/.yggdrasil/checker_result/hoge
95
95
  +++ tmp/yggdrasil-test/.yggdrasil/checker_result/hoge (revision 0)
96
96
  @@ -0,0 +1 @@
97
97
  +hoge
98
+
99
+ Yggdrasil check: NG!!!
98
100
  EOS
99
101
  end
100
102
 
@@ -127,6 +129,8 @@ Index: tmp/yggdrasil-test/.yggdrasil/checker_result/hoge
127
129
  +++ tmp/yggdrasil-test/.yggdrasil/checker_result/hoge (working copy)
128
130
  @@ -1 +0,0 @@
129
131
  -hoge
132
+
133
+ Yggdrasil check: NG!!!
130
134
  EOS
131
135
  end
132
136
 
@@ -142,8 +146,8 @@ Committed revision 5.
142
146
  EOS
143
147
  end
144
148
 
145
- it 'should record check result by yggdrasil server' do
146
- puts "\n---- should record check result by yggdrasil server"
149
+ it 'should record check result by yggdrasil server (add)' do
150
+ puts "\n---- should record check result by yggdrasil server (add)"
147
151
 
148
152
  prepare_environment
149
153
 
@@ -186,6 +190,10 @@ A 0 tmp/yggdrasil-test/.yggdrasil
186
190
  A 0 tmp/yggdrasil-test/.yggdrasil/checker_result
187
191
 
188
192
  EOS
193
+ end
194
+
195
+ it 'should record check result by yggdrasil server (modify)' do
196
+ puts "\n---- should record check result by yggdrasil server (modify)"
189
197
 
190
198
  `echo hoge > /tmp/yggdrasil-test/A`
191
199
  Yggdrasil.command %w{add /tmp/yggdrasil-test/A}
@@ -195,6 +203,8 @@ EOS
195
203
  `echo foo >> /tmp/yggdrasil-test/A`
196
204
  Yggdrasil.command %w{check}, "Y\n"
197
205
 
206
+ files = Dir.entries('/tmp/yggdrasil-test/.yggdrasil/results')
207
+ result_files = files.select{|file| %r{^#{Socket.gethostname}} =~ file}
198
208
  `cat /tmp/yggdrasil-test/.yggdrasil/results/#{result_files[0]}`.should == <<"EOS"
199
209
  M 2 tmp/yggdrasil-test/A
200
210
 
@@ -206,7 +216,22 @@ Index: tmp/yggdrasil-test/A
206
216
  hoge
207
217
  +foo
208
218
  EOS
219
+ end
220
+
221
+ it 'should record check result by yggdrasil server (OK)' do
222
+ puts "\n---- should record check result by yggdrasil server (OK)"
223
+
224
+ Yggdrasil.command %w{commit --username hoge --password foo} +
225
+ %w{-m HOGE --non-interactive}
226
+
227
+ Yggdrasil.command %w{check --non-interactive}
228
+
229
+ files = Dir.entries('/tmp/yggdrasil-test/.yggdrasil/results')
230
+ result_files = files.select{|file| %r{^#{Socket.gethostname}} =~ file}
231
+ `cat /tmp/yggdrasil-test/.yggdrasil/results/#{result_files[0]}`.should == "\n"
232
+ end
209
233
 
234
+ after(:all) do
210
235
  sock = TCPSocket.open('localhost', 4000)
211
236
  sock.puts('quit')
212
237
  sock.close
data/spec/help_spec.rb CHANGED
@@ -106,6 +106,7 @@ Valid options:
106
106
  --password ARG : specify a password ARG
107
107
  --server ARG : specify a server address and port
108
108
  e.g. 192.168.1.35:4000
109
+ see also 'yggserve help'
109
110
 
110
111
  EOS
111
112
  end
data/spec/server_spec.rb CHANGED
@@ -8,6 +8,19 @@ describe YggdrasilServer, 'server' do
8
8
  before(:all) do
9
9
  puts '-------- server'
10
10
  prepare_environment
11
+
12
+ sock = 0
13
+ begin
14
+ sock = TCPSocket.open('localhost', 4000)
15
+ rescue
16
+ puts 'OK. no server'
17
+ else
18
+ puts 'NG. zombie server. try quit'
19
+ sock.puts('quit')
20
+ sock.close
21
+ sleep 1
22
+ end
23
+
11
24
  YggdrasilServer.command %w{init} +
12
25
  %w{--port 4000} +
13
26
  %w{--repo svn://localhost/tmp/yggdrasil-test/svn-repo/servers/{HOST}/} +
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yggdrasil
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.13
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -116,7 +116,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
116
116
  version: '0'
117
117
  segments:
118
118
  - 0
119
- hash: 2992744534865834849
119
+ hash: -2008035553517272387
120
120
  required_rubygems_version: !ruby/object:Gem::Requirement
121
121
  none: false
122
122
  requirements:
@@ -125,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
125
  version: '0'
126
126
  segments:
127
127
  - 0
128
- hash: 2992744534865834849
128
+ hash: -2008035553517272387
129
129
  requirements: []
130
130
  rubyforge_project:
131
131
  rubygems_version: 1.8.25