yggdrasil 0.0.18 → 0.1.0
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.
- checksums.yaml +7 -0
- data/lib/yggdrasil.rb +46 -32
- data/lib/yggdrasil/add.rb +3 -1
- data/lib/yggdrasil/check.rb +4 -2
- data/lib/yggdrasil/commit.rb +2 -2
- data/lib/yggdrasil/help.rb +0 -13
- data/lib/yggdrasil/init.rb +19 -20
- data/lib/yggdrasil/version.rb +2 -1
- data/lib/yggdrasil_common.rb +32 -4
- data/lib/yggdrasil_server.rb +2 -0
- data/lib/yggdrasil_server/get_configs.rb +11 -0
- data/lib/yggdrasil_server/help.rb +1 -1
- data/lib/yggdrasil_server/init.rb +10 -4
- data/lib/yggdrasil_server/results.rb +35 -3
- data/spec/add_spec.rb +13 -3
- data/spec/check_spec.rb +16 -1
- data/spec/commit_spec.rb +37 -0
- data/spec/help_spec.rb +4 -37
- data/spec/init_spec.rb +9 -0
- data/spec/server_help_spec.rb +1 -1
- data/spec/server_results_spec.rb +53 -15
- data/spec/spec_helper.rb +1 -2
- metadata +12 -28
- data/lib/yggdrasil/update.rb +0 -52
- data/spec/revert_spec.rb +0 -152
- data/spec/update_spec.rb +0 -88
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d0a852b76b256c47b03cb8831f46f042455143ff
|
4
|
+
data.tar.gz: 2e7a725be79c156d187a5a691c17bdbcc6eafd8c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7b1b14ec6ca4298b9d9abe9cc6983b0be6fd5f012dc233c9ee76f8a1dcedad91956676a91af60e82323cf5fbf3db308545fc43e5772e977e6d3cbba7fe6d7fae
|
7
|
+
data.tar.gz: 06a39e94184bd6d53513e6897ae45ab05b2111c3c97057d244ebdeac27e18d3d3088c7d9230903f73217618e56f07cc3ad500448afa1776b939cfbef1acb1a9e
|
data/lib/yggdrasil.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'fileutils'
|
2
|
+
require 'socket'
|
2
3
|
|
3
4
|
require 'yggdrasil_common'
|
4
5
|
|
@@ -11,7 +12,6 @@ require 'yggdrasil/cleanup'
|
|
11
12
|
require 'yggdrasil/diff'
|
12
13
|
require 'yggdrasil/list'
|
13
14
|
require 'yggdrasil/log'
|
14
|
-
require 'yggdrasil/update'
|
15
15
|
require 'yggdrasil/check'
|
16
16
|
|
17
17
|
class Yggdrasil
|
@@ -43,8 +43,6 @@ class Yggdrasil
|
|
43
43
|
new.list(args[1..-1])
|
44
44
|
when 'log'
|
45
45
|
new.log(args[1..-1])
|
46
|
-
when 'update', 'up', 'revert'
|
47
|
-
new.update(args[1..-1])
|
48
46
|
when 'version', '--version', '-v'
|
49
47
|
new(false).version
|
50
48
|
else
|
@@ -68,8 +66,11 @@ class Yggdrasil
|
|
68
66
|
error 'need "svn" in config file' unless (@svn = configs[:svn])
|
69
67
|
error 'need "repo" in config file' unless (@repo = configs[:repo])
|
70
68
|
@anon_access = (configs[:anon_access] == 'read')
|
71
|
-
|
72
|
-
|
69
|
+
|
70
|
+
if configs.has_key?(:server)
|
71
|
+
@server = configs[:server]
|
72
|
+
get_server_configs(@server)
|
73
|
+
end
|
73
74
|
end
|
74
75
|
|
75
76
|
protected
|
@@ -188,49 +189,62 @@ class Yggdrasil
|
|
188
189
|
end
|
189
190
|
|
190
191
|
def username_password_options_to_read_repo
|
191
|
-
if
|
192
|
-
" --username #{@
|
192
|
+
if defined?(@ro_password)
|
193
|
+
" --username #{@ro_username} --password #{@ro_password}"
|
193
194
|
else
|
194
195
|
''
|
195
196
|
end
|
196
197
|
end
|
197
198
|
|
198
199
|
def get_user_pass_if_need_to_read_repo
|
200
|
+
@username = @options[:username] if @options.has_key?(:username)
|
201
|
+
@password = @options[:password] if @options.has_key?(:password)
|
199
202
|
unless @anon_access
|
200
|
-
|
201
|
-
input_user_pass unless @options.has_key?(:ro_password)
|
203
|
+
input_user_pass unless defined?(@ro_password)
|
202
204
|
end
|
203
|
-
@
|
204
|
-
@
|
205
|
+
@ro_username = @username if @username
|
206
|
+
@ro_password = @password if @password
|
205
207
|
end
|
206
208
|
|
207
|
-
def
|
208
|
-
if /^(.+):(\d+)$/ =~
|
209
|
+
def get_server_configs(host_port)
|
210
|
+
if /^(.+):(\d+)$/ =~ host_port
|
209
211
|
host = $1
|
210
212
|
port = $2
|
211
213
|
|
212
|
-
|
213
|
-
# get repo
|
214
|
-
sock = TCPSocket.open(host, port)
|
215
|
-
error "can not connect to server: #{host}:#{port}" if sock.nil?
|
216
|
-
sock.puts 'get_repo'
|
217
|
-
rcv = sock.gets
|
218
|
-
error 'can not get repo from server' if rcv.nil?
|
219
|
-
@options[:repo] = rcv.chomp
|
220
|
-
sock.close
|
221
|
-
end
|
222
|
-
|
223
|
-
#get read-only username/password
|
214
|
+
# connect
|
224
215
|
sock = TCPSocket.open(host, port)
|
225
216
|
error "can not connect to server: #{host}:#{port}" if sock.nil?
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
217
|
+
|
218
|
+
# send GET with key string
|
219
|
+
key_str = Time.now.strftime('%H:%M:%S')
|
220
|
+
sock.puts "get_configs #{key_str}"
|
221
|
+
rcv = sock.read
|
222
|
+
error 'can not get configs from server' if rcv.nil?
|
223
|
+
msg = obfuscate(rcv, key_str).split("\n")
|
224
|
+
|
225
|
+
# repo
|
226
|
+
error 'can not get repo from server' if msg.size < 1
|
227
|
+
config_repo = @repo
|
228
|
+
server_repo = msg[0]
|
229
|
+
if server_repo =~ /\{HOST\}/
|
230
|
+
@hostname = Socket.gethostname
|
231
|
+
server_repo.gsub!(/\{HOST\}/, @hostname)
|
232
|
+
end
|
233
|
+
if server_repo =~ /\{host\}/
|
234
|
+
@hostname = Socket.gethostname.split('.')[0]
|
235
|
+
server_repo.gsub!(/\{host\}/, @hostname)
|
233
236
|
end
|
237
|
+
if config_repo && config_repo != server_repo
|
238
|
+
error "mismatch repo config with server setting.\n" +
|
239
|
+
"config: #{config_repo}\n" +
|
240
|
+
"server: #{server_repo}"
|
241
|
+
end
|
242
|
+
@repo = server_repo
|
243
|
+
# username
|
244
|
+
@ro_username = msg[1] if msg.size >= 2
|
245
|
+
# password
|
246
|
+
@ro_password = msg[2] if msg.size >= 3
|
247
|
+
|
234
248
|
sock.close
|
235
249
|
else
|
236
250
|
error "invalid host:port '#{@options[:server]}'"
|
data/lib/yggdrasil/add.rb
CHANGED
data/lib/yggdrasil/check.rb
CHANGED
@@ -58,13 +58,15 @@ class Yggdrasil
|
|
58
58
|
end
|
59
59
|
|
60
60
|
if @arg_paths.size == 1 && @arg_paths[0] == '/'
|
61
|
-
if /^(.+):(\d+)$/ =~ @
|
61
|
+
if /^(.+):(\d+)$/ =~ @server
|
62
62
|
host = $1
|
63
63
|
port = $2
|
64
|
+
error 'no hostname' unless defined?(@hostname)
|
65
|
+
|
64
66
|
# put check_result to server
|
65
67
|
sock = TCPSocket.open(host, port)
|
66
68
|
error "can not connect to server: #{host}:#{port}" if sock.nil?
|
67
|
-
sock.puts "put_result #{
|
69
|
+
sock.puts "put_result #{@hostname}"
|
68
70
|
sock.puts check_result
|
69
71
|
sock.close
|
70
72
|
end
|
data/lib/yggdrasil/commit.rb
CHANGED
@@ -45,9 +45,9 @@ class Yggdrasil
|
|
45
45
|
|
46
46
|
input_user_pass
|
47
47
|
FileUtils.cd @mirror_dir do
|
48
|
-
cmd = "#{@svn} commit -m
|
48
|
+
cmd = "#{@svn} commit -m \"#{@options[:message].gsub('"', '\"')}\""\
|
49
49
|
' --no-auth-cache --non-interactive'\
|
50
|
-
" --username '#{@
|
50
|
+
" --username '#{@username}' --password '#{@password}'"\
|
51
51
|
" #{confirmed_updates.join(' ')}"
|
52
52
|
puts system3(cmd)
|
53
53
|
end
|
data/lib/yggdrasil/help.rb
CHANGED
@@ -18,7 +18,6 @@ Available subcommands:
|
|
18
18
|
init
|
19
19
|
list (ls)
|
20
20
|
log
|
21
|
-
update (up, revert)
|
22
21
|
version
|
23
22
|
|
24
23
|
Yggdrasil is a subversion wrapper to manage server configurations and conditions.
|
@@ -161,18 +160,6 @@ Valid options:
|
|
161
160
|
-q [--quiet] : print nothing, or only summary information
|
162
161
|
-v [--verbose] : print extra information
|
163
162
|
|
164
|
-
EOS
|
165
|
-
when 'update', 'up', 'revert' ##################### update (up, revert)
|
166
|
-
puts <<"EOS"
|
167
|
-
update (up, revert): Set the files to the contents of the newest repository.
|
168
|
-
usage: #{@base_cmd} update [OPTIONS...] [PATH...]
|
169
|
-
|
170
|
-
Valid options:
|
171
|
-
--username ARG : specify a username ARG
|
172
|
-
--password ARG : specify a password ARG
|
173
|
-
--non-interactive : do no interactive prompting
|
174
|
-
-r [--revision] ARG : revision number
|
175
|
-
|
176
163
|
EOS
|
177
164
|
|
178
165
|
when 'version', '--version', '-v' ######################## version (-v)
|
data/lib/yggdrasil/init.rb
CHANGED
@@ -10,8 +10,8 @@ class Yggdrasil
|
|
10
10
|
'--repo'=>:repo, '--parents'=>:parents?,
|
11
11
|
'--non-interactive'=>:non_interactive?,
|
12
12
|
'--force'=>:force?, '--server'=>:server })
|
13
|
-
@
|
14
|
-
@
|
13
|
+
@ro_username = @username = @options[:username] if @options.has_key?(:username)
|
14
|
+
@ro_password = @password = @options[:password] if @options.has_key?(:password)
|
15
15
|
|
16
16
|
if @arg_options.size+@arg_paths.size != 0
|
17
17
|
error "invalid arguments: #{(@arg_options+@arg_paths).join(', ')}"
|
@@ -43,28 +43,26 @@ class Yggdrasil
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
-
|
46
|
+
@repo = @options[:repo] if @options.has_key?(:repo)
|
47
|
+
get_server_configs(@options[:server]) if @options.has_key?(:server)
|
48
|
+
init_get_repo_interactive unless defined?(@repo)
|
47
49
|
|
48
|
-
|
49
|
-
|
50
|
-
@
|
51
|
-
@options[:repo].chomp!('/')
|
52
|
-
@options[:repo].gsub!(/\{HOST\}/, Socket.gethostname)
|
53
|
-
@options[:repo].gsub!(/\{host\}/, Socket.gethostname.split('.')[0])
|
54
|
-
if @options[:repo] == 'private'
|
50
|
+
@repo.chomp!
|
51
|
+
@repo.chomp!('/')
|
52
|
+
if @repo == 'private'
|
55
53
|
Dir.mkdir @config_dir, 0755 unless File.exist?(@config_dir)
|
56
54
|
repo_dir = "#{@config_dir}/private_repo"
|
57
55
|
system3 "svnadmin create #{repo_dir}"
|
58
|
-
@
|
56
|
+
@repo = "file://#{repo_dir}"
|
59
57
|
end
|
60
58
|
|
61
59
|
puts 'check SVN access...'
|
62
|
-
if
|
60
|
+
if defined?(@ro_username)
|
63
61
|
anon_access = false
|
64
62
|
else
|
65
63
|
anon_access = true
|
66
64
|
end
|
67
|
-
url_parts = @
|
65
|
+
url_parts = @repo.split('/')
|
68
66
|
url_parts_num = url_parts.size
|
69
67
|
url = ''
|
70
68
|
loop do
|
@@ -74,7 +72,7 @@ class Yggdrasil
|
|
74
72
|
url_parts_num = url_parts.size
|
75
73
|
get_user_pass_if_need_to_read_repo
|
76
74
|
else
|
77
|
-
error "can not access to '#{@
|
75
|
+
error "can not access to '#{@repo}'."
|
78
76
|
end
|
79
77
|
end
|
80
78
|
puts "url_parts_num=#{url_parts_num}" if @options[:debug?]
|
@@ -111,7 +109,7 @@ class Yggdrasil
|
|
111
109
|
input_user_pass
|
112
110
|
`rm -rf #{@mirror_dir}`
|
113
111
|
system3 "#{svn} checkout -N --no-auth-cache --non-interactive" +
|
114
|
-
" --username '#{@
|
112
|
+
" --username '#{@ro_username}' --password '#{@ro_password}'" +
|
115
113
|
" #{url_parts[0...url_parts_num].join('/')} #{@mirror_dir}"
|
116
114
|
add_paths = Array.new
|
117
115
|
path = @mirror_dir
|
@@ -125,7 +123,7 @@ class Yggdrasil
|
|
125
123
|
url_parts_num += 1
|
126
124
|
end
|
127
125
|
system3 "#{svn} commit -m 'yggdrasil init' --no-auth-cache --non-interactive" +
|
128
|
-
" --username '#{@
|
126
|
+
" --username '#{@username}' --password '#{@password}'" +
|
129
127
|
' ' + add_paths.join(' ')
|
130
128
|
system3 "rm -rf #{@mirror_dir}"
|
131
129
|
end
|
@@ -135,15 +133,16 @@ class Yggdrasil
|
|
135
133
|
f.puts "path=#{ENV['PATH']}\n"\
|
136
134
|
"svn=#{svn}\n"\
|
137
135
|
"svn_version=#{svn_version}\n"\
|
138
|
-
"repo=#{@
|
136
|
+
"repo=#{@repo}\n"\
|
139
137
|
"anon-access=#{anon_access ? 'read' : 'none'}\n"
|
138
|
+
|
140
139
|
f.puts "server=#{@options[:server]}\n" if @options.has_key?(:server)
|
141
140
|
end
|
142
141
|
|
143
142
|
# make mirror dir
|
144
143
|
`rm -rf #{@mirror_dir}`
|
145
|
-
cmd = "#{svn} checkout --no-auth-cache --non-interactive #{@
|
146
|
-
cmd += " --username '#{@
|
144
|
+
cmd = "#{svn} checkout --no-auth-cache --non-interactive #{@repo} #{@mirror_dir}"
|
145
|
+
cmd += " --username '#{@ro_username}' --password '#{@ro_password}'" unless anon_access
|
147
146
|
system3 cmd
|
148
147
|
|
149
148
|
# make checker directory
|
@@ -159,7 +158,7 @@ class Yggdrasil
|
|
159
158
|
error 'can not input svn repo URL' unless input
|
160
159
|
puts
|
161
160
|
if %r{^(http://|https://|file://|svn://|private)} =~ input
|
162
|
-
@
|
161
|
+
@repo = input
|
163
162
|
break
|
164
163
|
end
|
165
164
|
|
data/lib/yggdrasil/version.rb
CHANGED
data/lib/yggdrasil_common.rb
CHANGED
@@ -64,16 +64,16 @@ module YggdrasilCommon
|
|
64
64
|
end
|
65
65
|
|
66
66
|
def input_user_pass
|
67
|
-
until
|
67
|
+
until defined?(@username)
|
68
68
|
error 'Can\'t get username or password' if @options.has_key?(:non_interactive?)
|
69
69
|
print 'Input svn username: '
|
70
70
|
input = $stdin.gets
|
71
71
|
error 'can not input username' unless input
|
72
72
|
input.chomp!
|
73
73
|
return if input.size == 0
|
74
|
-
@
|
74
|
+
@username = @ro_username = input
|
75
75
|
end
|
76
|
-
until
|
76
|
+
until defined?(@password)
|
77
77
|
error 'Can\'t get username or password' if @options.has_key?(:non_interactive?)
|
78
78
|
print 'Input svn password: '
|
79
79
|
#input = `sh -c 'read -s hoge;echo $hoge'`
|
@@ -83,7 +83,7 @@ module YggdrasilCommon
|
|
83
83
|
puts
|
84
84
|
error 'can not input password' unless input
|
85
85
|
input.chomp!
|
86
|
-
@
|
86
|
+
@password = @ro_password = input
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
@@ -113,4 +113,32 @@ module YggdrasilCommon
|
|
113
113
|
$stderr.puts
|
114
114
|
exit 1
|
115
115
|
end
|
116
|
+
|
117
|
+
def obfuscate(src_str, key_str)
|
118
|
+
seed = [0,0,0,0]
|
119
|
+
# make seed
|
120
|
+
(0...key_str.size).each do |i|
|
121
|
+
seed[3] = (seed[3]^key_str[i].ord)
|
122
|
+
seed = my_rand(seed)
|
123
|
+
end
|
124
|
+
|
125
|
+
# puts "seed = #{seed.inspect}"
|
126
|
+
res = String.new
|
127
|
+
(0...src_str.size).each do |i|
|
128
|
+
seed = my_rand(seed)
|
129
|
+
res += (src_str[i].ord ^ (seed[3] & 0xFF)).chr
|
130
|
+
# printf "c[%03d]:0x%02X->0x%02X (0x%02X)\n",i,src_str[i].ord,res[i].ord, seed[3] & 0xFF
|
131
|
+
end
|
132
|
+
|
133
|
+
res
|
134
|
+
end
|
135
|
+
|
136
|
+
def my_rand(seed)
|
137
|
+
t = (seed[0]^(seed[0]<<11))
|
138
|
+
seed[0] = seed[1]
|
139
|
+
seed[1] = seed[2]
|
140
|
+
seed[2] = seed[3]
|
141
|
+
seed[3] = (seed[3]^(seed[3]>>19))^(t^(t>>8))
|
142
|
+
seed
|
143
|
+
end
|
116
144
|
end
|
data/lib/yggdrasil_server.rb
CHANGED
@@ -8,6 +8,7 @@ require 'yggdrasil_server/init'
|
|
8
8
|
require 'yggdrasil_server/server'
|
9
9
|
require 'yggdrasil_server/results'
|
10
10
|
|
11
|
+
require 'yggdrasil_server/get_configs'
|
11
12
|
require 'yggdrasil_server/get_repo'
|
12
13
|
require 'yggdrasil_server/get_ro_id_pw'
|
13
14
|
require 'yggdrasil_server/put_result'
|
@@ -15,6 +16,7 @@ require 'yggdrasil_server/put_result'
|
|
15
16
|
class YggdrasilServer
|
16
17
|
MESSAGE_QUIT = 'quit'
|
17
18
|
MESSAGES = {
|
19
|
+
:get_configs => [:key_str],
|
18
20
|
:get_repo => [],
|
19
21
|
:get_ro_id_pw => [],
|
20
22
|
:put_result => [:hostname],
|
@@ -54,7 +54,7 @@ usage: #{@base_cmd} init [OPTIONS...]
|
|
54
54
|
Valid options:
|
55
55
|
--port ARG : specify a TCP port number ARG
|
56
56
|
--repo ARG : URL of subversion repository
|
57
|
-
ARG
|
57
|
+
ARG must contain {HOST} or {host}
|
58
58
|
{HOST} is replaced by client hostname with domain
|
59
59
|
{host} is replaced by client hostname without domain
|
60
60
|
e.g. svn://192.168.3.5/servers/{host}/ygg
|
@@ -13,6 +13,8 @@ class YggdrasilServer
|
|
13
13
|
if !@options.has_key?(:ro_username) && @options.has_key?(:ro_password)
|
14
14
|
error '--ro-password option need --ro-username, too.'
|
15
15
|
end
|
16
|
+
@ro_username = @options[:ro_username] if @options.has_key?(:ro_username)
|
17
|
+
@ro_password = @options[:ro_password] if @options.has_key?(:ro_password)
|
16
18
|
|
17
19
|
until @options.has_key?(:port)
|
18
20
|
print 'Input tcp port number: '
|
@@ -40,8 +42,12 @@ class YggdrasilServer
|
|
40
42
|
end
|
41
43
|
@options[:repo].chomp!
|
42
44
|
@options[:repo].chomp!('/')
|
45
|
+
unless @options[:repo] =~ /\{HOST\}/ || @options[:repo] =~ /\{host\}/
|
46
|
+
error 'REPO must contain {HOST} or {host}'
|
47
|
+
end
|
48
|
+
|
43
49
|
|
44
|
-
unless
|
50
|
+
unless defined?(@ro_password)
|
45
51
|
puts 'Input read-only username/password (clients use this to read repo).'
|
46
52
|
puts 'ATTENTION! username/password are stored to disk unencrypted!'
|
47
53
|
input_user_pass
|
@@ -52,9 +58,9 @@ class YggdrasilServer
|
|
52
58
|
File.open(@server_config_file, 'w') do |f|
|
53
59
|
f.write "port=#{@options[:port]}\n"\
|
54
60
|
"repo=#{@options[:repo]}\n"
|
55
|
-
if
|
56
|
-
f.write "ro_username=#{@
|
57
|
-
"ro_password=#{@
|
61
|
+
if defined?(@ro_password)
|
62
|
+
f.write "ro_username=#{@ro_username}\n"\
|
63
|
+
"ro_password=#{@ro_password}\n"
|
58
64
|
end
|
59
65
|
end
|
60
66
|
end
|
@@ -10,17 +10,41 @@ class YggdrasilServer
|
|
10
10
|
error "invalid arguments: #{(@arg_options+@arg_paths).join(', ')}"
|
11
11
|
end
|
12
12
|
|
13
|
-
|
13
|
+
error 'NO results directory' unless File.exist?(@results_dir)
|
14
|
+
|
15
|
+
repo_base = @repo
|
16
|
+
repo_base.gsub!(/\{HOST\}.*$/,'') if @repo =~ /\{HOST\}/
|
17
|
+
repo_base.gsub!(/\{host\}.*$/,'') if @repo =~ /\{host\}/
|
18
|
+
|
19
|
+
cmd = "svn ls #{repo_base} --no-auth-cache --non-interactive"
|
20
|
+
cmd += " --username #{@ro_username} --password #{@ro_password}" if @ro_username
|
21
|
+
out = system3(cmd)
|
22
|
+
repo_hosts = Hash.new
|
23
|
+
out.split(/\n/).each do |host|
|
24
|
+
next if host =~ /^[_\.]/
|
25
|
+
repo_hosts[host.gsub(/\/$/, '')] = true
|
26
|
+
end
|
27
|
+
|
14
28
|
files = Dir.entries(@results_dir)
|
15
29
|
alert = false
|
16
30
|
files.each do |file|
|
17
31
|
next if /^\./ =~ file
|
18
32
|
absolute = "#{@results_dir}/#{file}"
|
33
|
+
host = file.gsub(/_[^_]+$/,'')
|
34
|
+
if repo_hosts.has_key?(host)
|
35
|
+
repo_hosts.delete host
|
36
|
+
else
|
37
|
+
# There is no host in the REPO
|
38
|
+
puts "Notice: delete result file (#{file})"
|
39
|
+
puts
|
40
|
+
File.unlink absolute # delete result file
|
41
|
+
next
|
42
|
+
end
|
19
43
|
if @options.has_key?(:expire)
|
20
44
|
stat = File.stat(absolute)
|
21
45
|
if stat.mtime < (Time.now - @options[:expire].to_i * 60)
|
22
46
|
alert = true
|
23
|
-
puts "######## #{file}
|
47
|
+
puts "######## Expired: #{file} (#{stat.mtime.to_s})"
|
24
48
|
puts
|
25
49
|
next
|
26
50
|
end
|
@@ -29,10 +53,18 @@ class YggdrasilServer
|
|
29
53
|
buf = NKF::nkf('-wm0', buf)
|
30
54
|
if buf.gsub(/\s*\n/m, '') != ''
|
31
55
|
alert = true
|
32
|
-
puts "######## #{file}
|
56
|
+
puts "######## Difference: #{file}"
|
33
57
|
puts buf
|
34
58
|
end
|
35
59
|
end
|
60
|
+
|
61
|
+
repo_hosts.each do |k,v|
|
62
|
+
if v
|
63
|
+
alert = true
|
64
|
+
puts "######## No check result: #{k}"
|
65
|
+
puts
|
66
|
+
end
|
67
|
+
end
|
36
68
|
exit 1 if alert
|
37
69
|
end
|
38
70
|
end
|
data/spec/add_spec.rb
CHANGED
@@ -18,10 +18,20 @@ describe Yggdrasil, 'add' do
|
|
18
18
|
|
19
19
|
it 'should success: add exist files (relative)' do
|
20
20
|
puts '---- should success: add exist files'
|
21
|
-
|
21
|
+
out = catch_out do
|
22
|
+
Yggdrasil.command %w{add Gemfile /etc/fstab}
|
23
|
+
end
|
24
|
+
out.should == <<"EOS"
|
25
|
+
A /home
|
26
|
+
A /home/kusu
|
27
|
+
A /home/kusu/work
|
28
|
+
A /home/kusu/work/yggdrasil
|
29
|
+
A /home/kusu/work/yggdrasil/Gemfile
|
30
|
+
A /etc
|
31
|
+
A /etc/fstab
|
32
|
+
EOS
|
33
|
+
|
22
34
|
File.exist?("/tmp/yggdrasil-test/.yggdrasil/mirror#{`readlink -f Gemfile`.chomp}").should be_true
|
23
|
-
end
|
24
|
-
it 'should success: add exist files (absolute)' do
|
25
35
|
File.exist?("/tmp/yggdrasil-test/.yggdrasil/mirror#{`readlink -f /etc/fstab`.chomp}").should be_true
|
26
36
|
end
|
27
37
|
end
|
data/spec/check_spec.rb
CHANGED
@@ -96,7 +96,6 @@ EOS
|
|
96
96
|
|
97
97
|
it 'should execute checker and svn add the result' do
|
98
98
|
puts "\n---- should execute checker and svn add the result"
|
99
|
-
`rm -f /tmp/yggdrasil-test/.yggdrasil/checker/gem_list`
|
100
99
|
`echo 'echo hoge' > /tmp/yggdrasil-test/.yggdrasil/checker/hoge`
|
101
100
|
`chmod +x /tmp/yggdrasil-test/.yggdrasil/checker/hoge`
|
102
101
|
|
@@ -285,6 +284,22 @@ EOS
|
|
285
284
|
`cat /tmp/yggdrasil-test/.yggdrasil/results/#{result_files[0]}`.should == "\n"
|
286
285
|
end
|
287
286
|
|
287
|
+
it 'should ERROR if repo config mismatch' do
|
288
|
+
puts "\n---- should ERROR if repo config mismatch"
|
289
|
+
|
290
|
+
`echo repo=hoge.hoge.com >> /tmp/yggdrasil-test/.yggdrasil/config`
|
291
|
+
|
292
|
+
err = catch_err do
|
293
|
+
lambda{Yggdrasil.command(%w{check --non-interactive})}.should raise_error(SystemExit)
|
294
|
+
end
|
295
|
+
err.should == <<"EOS"
|
296
|
+
rspec error: mismatch repo config with server setting.
|
297
|
+
config: hoge.hoge.com
|
298
|
+
server: svn://localhost/tmp/yggdrasil-test/svn-repo/servers/yggdrasil-dev.kusu.myhome.cx
|
299
|
+
|
300
|
+
EOS
|
301
|
+
end
|
302
|
+
|
288
303
|
it 'should recover delete flag' do
|
289
304
|
pending 'under construction...'
|
290
305
|
puts "\n---- should recover delete flag"
|
data/spec/commit_spec.rb
CHANGED
@@ -288,4 +288,41 @@ Committed revision 14.
|
|
288
288
|
EOS
|
289
289
|
end
|
290
290
|
|
291
|
+
it 'should commit with quote character comment' do
|
292
|
+
puts '---- should commit with quote character comment'
|
293
|
+
`echo A >> /tmp/yggdrasil-test/A`
|
294
|
+
|
295
|
+
out = catch_out do
|
296
|
+
Yggdrasil.command %w{commit --debug} +
|
297
|
+
%w{--username hoge --password foo} +
|
298
|
+
%w{-m} + ["with quote<'>"],
|
299
|
+
"Y\n"
|
300
|
+
end
|
301
|
+
out.should == <<EOS
|
302
|
+
|
303
|
+
0:M tmp/yggdrasil-test/A
|
304
|
+
1:M tmp/yggdrasil-test/B
|
305
|
+
2:M tmp/yggdrasil-test/c/A
|
306
|
+
OK? [Y|n|<num to diff>]:#{' '}
|
307
|
+
Sending tmp/yggdrasil-test/A
|
308
|
+
Sending tmp/yggdrasil-test/B
|
309
|
+
Sending tmp/yggdrasil-test/c/A
|
310
|
+
Transmitting file data ...
|
311
|
+
Committed revision 15.
|
312
|
+
EOS
|
313
|
+
|
314
|
+
out = catch_out do
|
315
|
+
Yggdrasil.command %w{log -r HEAD --username hoge --password foo}
|
316
|
+
end
|
317
|
+
out.gsub!(%r{20..-..-.. .*20..\)}, '')
|
318
|
+
out.should == <<EOS
|
319
|
+
------------------------------------------------------------------------
|
320
|
+
r15 | hoge | | 1 line
|
321
|
+
|
322
|
+
with quote<'>
|
323
|
+
------------------------------------------------------------------------
|
324
|
+
EOS
|
325
|
+
|
326
|
+
end
|
327
|
+
|
291
328
|
end
|
data/spec/help_spec.rb
CHANGED
@@ -18,7 +18,6 @@ Available subcommands:
|
|
18
18
|
init
|
19
19
|
list (ls)
|
20
20
|
log
|
21
|
-
update (up, revert)
|
22
21
|
version
|
23
22
|
|
24
23
|
Yggdrasil is a subversion wrapper to manage server configurations and conditions.
|
@@ -50,12 +49,12 @@ EOS
|
|
50
49
|
out.should == show_subcommands
|
51
50
|
end
|
52
51
|
|
53
|
-
it 'should be unknown subcommand on "
|
54
|
-
puts '---- should be unknown subcommand on "
|
52
|
+
it 'should be unknown subcommand on "revert"' do
|
53
|
+
puts '---- should be unknown subcommand on "revert"'
|
55
54
|
err = catch_err do
|
56
|
-
lambda{Yggdrasil.command(%w{
|
55
|
+
lambda{Yggdrasil.command(%w{revert})}.should raise_error(SystemExit)
|
57
56
|
end
|
58
|
-
err.should == "Unknown subcommand: '
|
57
|
+
err.should == "Unknown subcommand: 'revert'\n"
|
59
58
|
end
|
60
59
|
|
61
60
|
help_help = <<"EOS"
|
@@ -218,38 +217,6 @@ Valid options:
|
|
218
217
|
-q [--quiet] : print nothing, or only summary information
|
219
218
|
-v [--verbose] : print extra information
|
220
219
|
|
221
|
-
EOS
|
222
|
-
end
|
223
|
-
|
224
|
-
it 'should show help of update' do
|
225
|
-
puts '---- should show help of update'
|
226
|
-
out = catch_out{Yggdrasil.command %w{help update}}
|
227
|
-
out.should == <<"EOS"
|
228
|
-
update (up, revert): Set the files to the contents of the newest repository.
|
229
|
-
usage: #{File.basename($0)} update [OPTIONS...] [PATH...]
|
230
|
-
|
231
|
-
Valid options:
|
232
|
-
--username ARG : specify a username ARG
|
233
|
-
--password ARG : specify a password ARG
|
234
|
-
--non-interactive : do no interactive prompting
|
235
|
-
-r [--revision] ARG : revision number
|
236
|
-
|
237
|
-
EOS
|
238
|
-
end
|
239
|
-
|
240
|
-
it 'should show help of revert' do
|
241
|
-
puts '---- should show help of revert'
|
242
|
-
out = catch_out{Yggdrasil.command %w{help revert}}
|
243
|
-
out.should == <<"EOS"
|
244
|
-
update (up, revert): Set the files to the contents of the newest repository.
|
245
|
-
usage: #{File.basename($0)} update [OPTIONS...] [PATH...]
|
246
|
-
|
247
|
-
Valid options:
|
248
|
-
--username ARG : specify a username ARG
|
249
|
-
--password ARG : specify a password ARG
|
250
|
-
--non-interactive : do no interactive prompting
|
251
|
-
-r [--revision] ARG : revision number
|
252
|
-
|
253
220
|
EOS
|
254
221
|
end
|
255
222
|
|
data/spec/init_spec.rb
CHANGED
@@ -158,6 +158,14 @@ EOS
|
|
158
158
|
"Y\nhoge\nfoo\n"
|
159
159
|
|
160
160
|
File.exist?('/tmp/yggdrasil-test/.yggdrasil/config').should be_true
|
161
|
+
|
162
|
+
config = `cat /tmp/yggdrasil-test/.yggdrasil/config`
|
163
|
+
config.should =~ /^path=/
|
164
|
+
config.should =~ /^svn=/
|
165
|
+
config.should =~ /^svn_version=/
|
166
|
+
config.should =~ /^repo=/
|
167
|
+
config.should =~ /^anon-access=/
|
168
|
+
config.should =~ /^server=/
|
161
169
|
end
|
162
170
|
|
163
171
|
it 'should success init subcommand with server option AGAIN' do
|
@@ -238,6 +246,7 @@ EOS
|
|
238
246
|
sock = TCPSocket.open('localhost', 4000)
|
239
247
|
sock.puts('quit')
|
240
248
|
sock.close
|
249
|
+
`pkill svnserve`
|
241
250
|
Process.waitall
|
242
251
|
end
|
243
252
|
end
|
data/spec/server_help_spec.rb
CHANGED
@@ -97,7 +97,7 @@ usage: #{File.basename($0)} init [OPTIONS...]
|
|
97
97
|
Valid options:
|
98
98
|
--port ARG : specify a TCP port number ARG
|
99
99
|
--repo ARG : URL of subversion repository
|
100
|
-
ARG
|
100
|
+
ARG must contain {HOST} or {host}
|
101
101
|
{HOST} is replaced by client hostname with domain
|
102
102
|
{host} is replaced by client hostname without domain
|
103
103
|
e.g. svn://192.168.3.5/servers/{host}/ygg
|
data/spec/server_results_spec.rb
CHANGED
@@ -33,7 +33,6 @@ describe YggdrasilServer, 'results' do
|
|
33
33
|
Yggdrasil.command %w{init --debug --server localhost:4000} +
|
34
34
|
%w{--username hoge --password foo},
|
35
35
|
"Y\nhoge\nfoo\n"
|
36
|
-
`rm -f /tmp/yggdrasil-test/.yggdrasil/checker/gem_list`
|
37
36
|
|
38
37
|
`echo hoge > /tmp/yggdrasil-test/A`
|
39
38
|
Yggdrasil.command %w{add /tmp/yggdrasil-test/A}
|
@@ -44,31 +43,52 @@ describe YggdrasilServer, 'results' do
|
|
44
43
|
Yggdrasil.command %w{check}
|
45
44
|
sleep 1
|
46
45
|
out = catch_out do
|
47
|
-
YggdrasilServer.command %w{results --expire 30}
|
46
|
+
YggdrasilServer.command %w{results --expire 30 --debug}
|
48
47
|
end
|
49
48
|
out.should == ''
|
50
49
|
end
|
51
50
|
|
52
|
-
it 'should show
|
53
|
-
puts '---- should show
|
51
|
+
it 'should not show alert (there is result file, but there is no host in the repo)' do
|
52
|
+
puts '---- should not show alert (there is result file, but there is no host in the repo)'
|
53
|
+
|
54
|
+
`echo hoge > /tmp/yggdrasil-test/.yggdrasil/results/removed-host_192.168.1.30`
|
55
|
+
sleep 1
|
56
|
+
|
57
|
+
out = catch_out do
|
58
|
+
YggdrasilServer.command %w{results --expire 30 --debug}
|
59
|
+
end
|
60
|
+
out.should == "Notice: delete result file (removed-host_192.168.1.30)\n\n"
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should show alert (there is no result, but it exist in the repo)' do
|
64
|
+
puts '---- should show alert (there is no result, but it exist in the repo)'
|
65
|
+
|
66
|
+
`rm -f /tmp/yggdrasil-test/.yggdrasil/results/*`
|
67
|
+
|
68
|
+
out = catch_out do
|
69
|
+
lambda{YggdrasilServer.command(%w{results --expire 30 --debug})}.should raise_error(SystemExit)
|
70
|
+
end
|
71
|
+
out.should == <<"EOS"
|
72
|
+
######## No check result: #{Socket.gethostname}
|
73
|
+
|
74
|
+
EOS
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'should show alert (difference)' do
|
79
|
+
puts '---- should show alert (difference)'
|
54
80
|
|
55
81
|
`echo foo >> /tmp/yggdrasil-test/A`
|
56
82
|
Yggdrasil.command %w{check --non-interactive}
|
57
83
|
|
58
|
-
`echo hoge > /tmp/yggdrasil-test/.yggdrasil/results/hoge-old`
|
59
|
-
File.utime Time.local(2001, 5, 22, 23, 59, 59),
|
60
|
-
Time.local(2001, 5, 1, 0, 0, 0),
|
61
|
-
'/tmp/yggdrasil-test/.yggdrasil/results/hoge-old'
|
62
84
|
sleep 1
|
63
85
|
|
64
86
|
out = catch_out do
|
65
|
-
lambda{YggdrasilServer.command(%w{results --expire 30})}.should raise_error(SystemExit)
|
87
|
+
lambda{YggdrasilServer.command(%w{results --expire 30 --debug})}.should raise_error(SystemExit)
|
66
88
|
end
|
67
89
|
out.gsub! /[ ]+/, ' '
|
68
90
|
out.should == <<"EOS"
|
69
|
-
########
|
70
|
-
|
71
|
-
######## #{Socket.gethostname}_127.0.0.1 Mismatch:
|
91
|
+
######## Difference: #{Socket.gethostname}_127.0.0.1
|
72
92
|
M 2 tmp/yggdrasil-test/A
|
73
93
|
|
74
94
|
Index: tmp/yggdrasil-test/A
|
@@ -79,6 +99,24 @@ Index: tmp/yggdrasil-test/A
|
|
79
99
|
hoge
|
80
100
|
+foo
|
81
101
|
|
102
|
+
EOS
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'should show alert (expired)' do
|
106
|
+
puts '---- should show results'
|
107
|
+
|
108
|
+
File.utime Time.local(2001, 5, 22, 23, 59, 59),
|
109
|
+
Time.local(2001, 5, 1, 0, 0, 0),
|
110
|
+
"/tmp/yggdrasil-test/.yggdrasil/results/#{Socket.gethostname}_127.0.0.1"
|
111
|
+
sleep 1
|
112
|
+
|
113
|
+
out = catch_out do
|
114
|
+
lambda{YggdrasilServer.command(%w{results --expire 30 --debug})}.should raise_error(SystemExit)
|
115
|
+
end
|
116
|
+
out.gsub! /[ ]+/, ' '
|
117
|
+
out.should == <<"EOS"
|
118
|
+
######## Expired: #{Socket.gethostname}_127.0.0.1 (2001-05-01 00:00:00 +0900)
|
119
|
+
|
82
120
|
EOS
|
83
121
|
end
|
84
122
|
|
@@ -86,13 +124,13 @@ EOS
|
|
86
124
|
puts '---- should show s-jis results'
|
87
125
|
|
88
126
|
`rm /tmp/yggdrasil-test/.yggdrasil/results/*`
|
89
|
-
`echo 'あいうえお' | nkf -s > /tmp/yggdrasil-test/.yggdrasil/results
|
127
|
+
`echo 'あいうえお' | nkf -s > /tmp/yggdrasil-test/.yggdrasil/results/#{Socket.gethostname}_127.0.0.1`
|
90
128
|
|
91
129
|
out = catch_out do
|
92
|
-
lambda{YggdrasilServer.command(%w{results})}.should raise_error(SystemExit)
|
130
|
+
lambda{YggdrasilServer.command(%w{results --debug})}.should raise_error(SystemExit)
|
93
131
|
end
|
94
132
|
out.should == <<"EOS"
|
95
|
-
########
|
133
|
+
######## Difference: #{Socket.gethostname}_127.0.0.1
|
96
134
|
あいうえお
|
97
135
|
EOS
|
98
136
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -33,7 +33,6 @@ def init_yggdrasil
|
|
33
33
|
Yggdrasil.command %w{init} +
|
34
34
|
%w{--repo svn://localhost/tmp/yggdrasil-test/svn-repo/mng-repo/host-name/} +
|
35
35
|
%w{--username hoge --password foo --parents}
|
36
|
-
`rm /tmp/yggdrasil-test/.yggdrasil/checker/gem_list`
|
37
36
|
puts '-- add'
|
38
37
|
`echo hoge > /tmp/yggdrasil-test/A`
|
39
38
|
`echo foo > /tmp/yggdrasil-test/B`
|
@@ -61,7 +60,7 @@ end
|
|
61
60
|
|
62
61
|
def catch_err
|
63
62
|
exit 1 unless block_given?
|
64
|
-
tmp_err = $
|
63
|
+
tmp_err = $stderr
|
65
64
|
$stderr = StringIO.new
|
66
65
|
yield
|
67
66
|
$stderr, tmp_err = tmp_err, $stderr
|
metadata
CHANGED
@@ -1,46 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yggdrasil
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Tomohisa Kusukawa
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-12-07 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rspec
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: simplecov
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - '>='
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - '>='
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
description: Yggdrasil is a subversion wrapper to manage configuration files.
|
@@ -71,10 +66,10 @@ files:
|
|
71
66
|
- lib/yggdrasil/init.rb
|
72
67
|
- lib/yggdrasil/list.rb
|
73
68
|
- lib/yggdrasil/log.rb
|
74
|
-
- lib/yggdrasil/update.rb
|
75
69
|
- lib/yggdrasil/version.rb
|
76
70
|
- lib/yggdrasil_common.rb
|
77
71
|
- lib/yggdrasil_server.rb
|
72
|
+
- lib/yggdrasil_server/get_configs.rb
|
78
73
|
- lib/yggdrasil_server/get_repo.rb
|
79
74
|
- lib/yggdrasil_server/get_ro_id_pw.rb
|
80
75
|
- lib/yggdrasil_server/help.rb
|
@@ -92,45 +87,36 @@ files:
|
|
92
87
|
- spec/init_spec.rb
|
93
88
|
- spec/list_spec.rb
|
94
89
|
- spec/log_spec.rb
|
95
|
-
- spec/revert_spec.rb
|
96
90
|
- spec/server_help_spec.rb
|
97
91
|
- spec/server_init_spec.rb
|
98
92
|
- spec/server_results_spec.rb
|
99
93
|
- spec/server_spec.rb
|
100
94
|
- spec/server_version_spec.rb
|
101
95
|
- spec/spec_helper.rb
|
102
|
-
- spec/update_spec.rb
|
103
96
|
- spec/version_spec.rb
|
104
97
|
- yggdrasil.gemspec
|
105
98
|
homepage: https://github.com/tkusukawa/yggdrasil
|
106
99
|
licenses: []
|
100
|
+
metadata: {}
|
107
101
|
post_install_message:
|
108
102
|
rdoc_options: []
|
109
103
|
require_paths:
|
110
104
|
- lib
|
111
105
|
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
-
none: false
|
113
106
|
requirements:
|
114
|
-
- -
|
107
|
+
- - '>='
|
115
108
|
- !ruby/object:Gem::Version
|
116
109
|
version: '0'
|
117
|
-
segments:
|
118
|
-
- 0
|
119
|
-
hash: 1911977696976218263
|
120
110
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
|
-
none: false
|
122
111
|
requirements:
|
123
|
-
- -
|
112
|
+
- - '>='
|
124
113
|
- !ruby/object:Gem::Version
|
125
114
|
version: '0'
|
126
|
-
segments:
|
127
|
-
- 0
|
128
|
-
hash: 1911977696976218263
|
129
115
|
requirements: []
|
130
116
|
rubyforge_project:
|
131
|
-
rubygems_version: 1.
|
117
|
+
rubygems_version: 2.1.11
|
132
118
|
signing_key:
|
133
|
-
specification_version:
|
119
|
+
specification_version: 4
|
134
120
|
summary: Type "ygg help" for usage.
|
135
121
|
test_files:
|
136
122
|
- spec/add_spec.rb
|
@@ -142,12 +128,10 @@ test_files:
|
|
142
128
|
- spec/init_spec.rb
|
143
129
|
- spec/list_spec.rb
|
144
130
|
- spec/log_spec.rb
|
145
|
-
- spec/revert_spec.rb
|
146
131
|
- spec/server_help_spec.rb
|
147
132
|
- spec/server_init_spec.rb
|
148
133
|
- spec/server_results_spec.rb
|
149
134
|
- spec/server_spec.rb
|
150
135
|
- spec/server_version_spec.rb
|
151
136
|
- spec/spec_helper.rb
|
152
|
-
- spec/update_spec.rb
|
153
137
|
- spec/version_spec.rb
|
data/lib/yggdrasil/update.rb
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
class Yggdrasil
|
2
|
-
|
3
|
-
# @param [Array] args
|
4
|
-
def update(args)
|
5
|
-
parse_options(args,
|
6
|
-
{'--username'=>:username, '--password'=>:password,
|
7
|
-
'-r'=>:revision, '--revision'=>:revision,
|
8
|
-
'--non-interactive'=>:non_interactive?})
|
9
|
-
@arg_paths << '/' if @arg_paths.size == 0
|
10
|
-
get_user_pass_if_need_to_read_repo
|
11
|
-
|
12
|
-
matched_updates = sync_mirror(@arg_paths)
|
13
|
-
if matched_updates.size == 0
|
14
|
-
puts 'no files.'
|
15
|
-
return
|
16
|
-
end
|
17
|
-
|
18
|
-
confirmed_updates = confirm_updates(matched_updates) do |relative_path|
|
19
|
-
FileUtils.cd @mirror_dir do
|
20
|
-
cmd = "#{@svn} diff --no-auth-cache --non-interactive #{relative_path}"
|
21
|
-
cmd += username_password_options_to_read_repo
|
22
|
-
puts system3(cmd)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
return unless confirmed_updates
|
26
|
-
return if confirmed_updates.size == 0
|
27
|
-
|
28
|
-
FileUtils.cd @mirror_dir do
|
29
|
-
cmd = "#{@svn} revert #{confirmed_updates.reverse.join(' ')}"
|
30
|
-
system3 cmd
|
31
|
-
|
32
|
-
# make ls hash
|
33
|
-
cmd = "#{@svn} ls -R #{@repo} --no-auth-cache --non-interactive"
|
34
|
-
cmd += username_password_options_to_read_repo
|
35
|
-
out = system3(cmd)
|
36
|
-
|
37
|
-
ls_hash = Hash.new
|
38
|
-
out.split(/\n/).each {|relative| ls_hash[relative]=true}
|
39
|
-
|
40
|
-
# reflect mirror to real file
|
41
|
-
confirmed_updates.each do |file|
|
42
|
-
if ls_hash.has_key?(file)
|
43
|
-
if File.file?("#{@mirror_dir}/#{file}")
|
44
|
-
FileUtils.copy_file "#{@mirror_dir}/#{file}", "/#{file}"
|
45
|
-
end
|
46
|
-
else
|
47
|
-
system3 "rm -rf #{@mirror_dir + '/' + file}"
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
data/spec/revert_spec.rb
DELETED
@@ -1,152 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
-
|
3
|
-
describe Yggdrasil, 'revert' do
|
4
|
-
it '-------- revert' do
|
5
|
-
puts '-------- revert'
|
6
|
-
prepare_environment
|
7
|
-
init_yggdrasil
|
8
|
-
end
|
9
|
-
|
10
|
-
|
11
|
-
it 'should revert added files' do
|
12
|
-
puts '---- should commit added files'
|
13
|
-
`echo hoge > /tmp/yggdrasil-test/AA`
|
14
|
-
`echo foo > /tmp/yggdrasil-test/BB`
|
15
|
-
FileUtils.cd '/tmp/yggdrasil-test' do
|
16
|
-
puts '-- add'
|
17
|
-
Yggdrasil.command %w{add AA /tmp/yggdrasil-test/BB}
|
18
|
-
|
19
|
-
puts '-- revert'
|
20
|
-
Yggdrasil.command %w{revert --username hoge --password foo},
|
21
|
-
"0\nY\n"
|
22
|
-
end
|
23
|
-
|
24
|
-
puts "\n-- check revert file (add)"
|
25
|
-
out = catch_out do
|
26
|
-
Yggdrasil.command %w{check /tmp/yggdrasil-test --non-interactive} +
|
27
|
-
%w{--username hoge --password foo}
|
28
|
-
end
|
29
|
-
puts out
|
30
|
-
out.should == "3 files checked.\nYggdrasil check: OK.\n"
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'should revert modified file' do
|
34
|
-
puts '---- should revert modified file'
|
35
|
-
puts '-- modify'
|
36
|
-
`echo hoge >> /tmp/yggdrasil-test/A`
|
37
|
-
|
38
|
-
puts '-- revert'
|
39
|
-
Yggdrasil.command %w{revert / --username hoge --password foo},
|
40
|
-
"0\nY\n"
|
41
|
-
|
42
|
-
puts "\n-- check revert file (modify)"
|
43
|
-
out = catch_out do
|
44
|
-
Yggdrasil.command %w{check /tmp/yggdrasil-test --non-interactive} +
|
45
|
-
%w{--username hoge --password foo}
|
46
|
-
end
|
47
|
-
puts out
|
48
|
-
out.should == "3 files checked.\nYggdrasil check: OK.\n"
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'should accept password interactive' do
|
52
|
-
puts '---- should accept password interactive'
|
53
|
-
`echo A >> /tmp/yggdrasil-test/A`
|
54
|
-
|
55
|
-
Yggdrasil.command %w{revert /tmp/yggdrasil-test/A --username hoge},
|
56
|
-
"foo\nY\n" # interactive input: password, Y/n
|
57
|
-
|
58
|
-
puts "\n-- check revert file"
|
59
|
-
out = catch_out do
|
60
|
-
Yggdrasil.command %w{check /tmp/yggdrasil-test --non-interactive} +
|
61
|
-
%w{--username hoge --password foo}
|
62
|
-
end
|
63
|
-
puts out
|
64
|
-
out.should == "3 files checked.\nYggdrasil check: OK.\n"
|
65
|
-
end
|
66
|
-
|
67
|
-
it 'should revert specified file only' do
|
68
|
-
puts '---- should revert specified file only'
|
69
|
-
`echo A >> /tmp/yggdrasil-test/A`
|
70
|
-
`echo B >> /tmp/yggdrasil-test/B`
|
71
|
-
|
72
|
-
Yggdrasil.command %w{revert /tmp/yggdrasil-test/B} +
|
73
|
-
%w{--username hoge --password foo},
|
74
|
-
"0\nY\n"
|
75
|
-
|
76
|
-
puts "\n-- check revert file"
|
77
|
-
out = catch_out do
|
78
|
-
Yggdrasil.command %w{check /tmp/yggdrasil-test --non-interactive} +
|
79
|
-
%w{--username hoge --password foo}
|
80
|
-
end
|
81
|
-
puts out
|
82
|
-
out.gsub!(%r{ +}, ' ')
|
83
|
-
out.should == <<"EOS"
|
84
|
-
3 files checked.
|
85
|
-
M 3 tmp/yggdrasil-test/A
|
86
|
-
|
87
|
-
Index: tmp/yggdrasil-test/A
|
88
|
-
===================================================================
|
89
|
-
--- tmp/yggdrasil-test/A (revision 3)
|
90
|
-
+++ tmp/yggdrasil-test/A (working copy)
|
91
|
-
@@ -1,2 +1,3 @@
|
92
|
-
hoge
|
93
|
-
hoge
|
94
|
-
+A
|
95
|
-
|
96
|
-
Yggdrasil check: NG!!!
|
97
|
-
EOS
|
98
|
-
end
|
99
|
-
|
100
|
-
it 'should not revert deleted file' do
|
101
|
-
puts '---- should not revert deleted file'
|
102
|
-
`rm -f /tmp/yggdrasil-test/A`
|
103
|
-
|
104
|
-
Yggdrasil.command %w{revert /} +
|
105
|
-
%w{--username hoge --password foo},
|
106
|
-
"0\nn\n"
|
107
|
-
|
108
|
-
puts "\n-- check status"
|
109
|
-
out = catch_out do
|
110
|
-
Yggdrasil.command %w{check /tmp/yggdrasil-test --non-interactive} +
|
111
|
-
%w{--username hoge --password foo}
|
112
|
-
end
|
113
|
-
puts out
|
114
|
-
out.gsub!(%r{ +},' ')
|
115
|
-
out.should == <<"EOS"
|
116
|
-
3 files checked.
|
117
|
-
D 3 tmp/yggdrasil-test/A
|
118
|
-
|
119
|
-
Index: tmp/yggdrasil-test/A
|
120
|
-
===================================================================
|
121
|
-
--- tmp/yggdrasil-test/A (revision 3)
|
122
|
-
+++ tmp/yggdrasil-test/A (working copy)
|
123
|
-
@@ -1,2 +0,0 @@
|
124
|
-
-hoge
|
125
|
-
-hoge
|
126
|
-
|
127
|
-
Yggdrasil check: NG!!!
|
128
|
-
EOS
|
129
|
-
end
|
130
|
-
|
131
|
-
it 'should revert all files at once' do
|
132
|
-
puts '---- should revert all files at once'
|
133
|
-
|
134
|
-
`echo HOGE >> /tmp/yggdrasil-test/A`
|
135
|
-
`rm -f /tmp/yggdrasil-test/B`
|
136
|
-
`mkdir /tmp/yggdrasil-test/c`
|
137
|
-
`echo bar > /tmp/yggdrasil-test/c/C`
|
138
|
-
Yggdrasil.command %w{add /tmp/yggdrasil-test/c/C}
|
139
|
-
|
140
|
-
Yggdrasil.command %w{revert /} +
|
141
|
-
%w{--username hoge --password foo},
|
142
|
-
"0\nY\n"
|
143
|
-
|
144
|
-
puts "\n-- check status"
|
145
|
-
out = catch_out do
|
146
|
-
Yggdrasil.command %w{check /tmp/yggdrasil-test --non-interactive} +
|
147
|
-
%w{--username hoge --password foo}
|
148
|
-
end
|
149
|
-
puts out
|
150
|
-
out.should == "3 files checked.\nYggdrasil check: OK.\n"
|
151
|
-
end
|
152
|
-
end
|
data/spec/update_spec.rb
DELETED
@@ -1,88 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
-
|
3
|
-
describe Yggdrasil, 'update' do
|
4
|
-
it '-------- update' do
|
5
|
-
puts '-------- update'
|
6
|
-
prepare_environment
|
7
|
-
init_yggdrasil
|
8
|
-
|
9
|
-
puts '-- make another working copy'
|
10
|
-
puts `svn co file:///tmp/yggdrasil-test/svn-repo/mng-repo/host-name /tmp/yggdrasil-test/svn-work`
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'should success update (related/absolute path)' do
|
14
|
-
puts '---- should success update (related/absolute path)'
|
15
|
-
puts '-- commit on another working copy'
|
16
|
-
`echo A:related/absolute path > /tmp/yggdrasil-test/svn-work/tmp/yggdrasil-test/A`
|
17
|
-
`echo B:related/absolute path > /tmp/yggdrasil-test/svn-work/tmp/yggdrasil-test/B`
|
18
|
-
`svn commit -m 'another commit' /tmp/yggdrasil-test/svn-work/`
|
19
|
-
|
20
|
-
FileUtils.cd '/tmp/yggdrasil-test' do
|
21
|
-
Yggdrasil.command %w{update A /tmp/yggdrasil-test/B} +
|
22
|
-
%w{--username hoge --password foo},
|
23
|
-
"0\nY\n"
|
24
|
-
end
|
25
|
-
`cat /tmp/yggdrasil-test/A`.should == "A:related/absolute path\n"
|
26
|
-
`cat /tmp/yggdrasil-test/B`.should == "B:related/absolute path\n"
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'should success update (only one file)' do
|
30
|
-
puts '---- should success update (only one file)'
|
31
|
-
|
32
|
-
puts '-- commit on another working copy'
|
33
|
-
`echo A:only one file > /tmp/yggdrasil-test/svn-work/tmp/yggdrasil-test/A`
|
34
|
-
`echo B:only one file > /tmp/yggdrasil-test/svn-work/tmp/yggdrasil-test/B`
|
35
|
-
`svn commit -m 'another commit' /tmp/yggdrasil-test/svn-work/tmp/yggdrasil-test`
|
36
|
-
|
37
|
-
Yggdrasil.command %w{update /tmp/yggdrasil-test/A} +
|
38
|
-
%w{--username hoge --password foo --non-interactive}
|
39
|
-
|
40
|
-
`cat /tmp/yggdrasil-test/A`.should == "A:only one file\n"
|
41
|
-
`cat /tmp/yggdrasil-test/B`.should == "B:related/absolute path\n"
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'should success update (parent path)' do
|
45
|
-
puts '---- should success update (parent path)'
|
46
|
-
puts '-- commit on another working copy'
|
47
|
-
`echo A:parent path > /tmp/yggdrasil-test/svn-work/tmp/yggdrasil-test/A`
|
48
|
-
`echo B:parent path > /tmp/yggdrasil-test/svn-work/tmp/yggdrasil-test/B`
|
49
|
-
`svn commit -m 'another commit' /tmp/yggdrasil-test/svn-work/tmp/yggdrasil-test`
|
50
|
-
|
51
|
-
Yggdrasil.command %w{update /tmp} +
|
52
|
-
%w{--username hoge --password foo},
|
53
|
-
"1\nY\n"
|
54
|
-
`cat /tmp/yggdrasil-test/A`.should == "A:parent path\n"
|
55
|
-
`cat /tmp/yggdrasil-test/B`.should == "B:parent path\n"
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'should success update (no path)' do
|
59
|
-
puts '---- should success update (no path)'
|
60
|
-
puts '-- commit on another working copy'
|
61
|
-
`echo A:no path > /tmp/yggdrasil-test/svn-work/tmp/yggdrasil-test/A`
|
62
|
-
`echo B:no path > /tmp/yggdrasil-test/svn-work/tmp/yggdrasil-test/B`
|
63
|
-
`svn commit -m 'another commit' /tmp/yggdrasil-test/svn-work/tmp/yggdrasil-test`
|
64
|
-
|
65
|
-
FileUtils.cd '/tmp' do
|
66
|
-
Yggdrasil.command %w{update} +
|
67
|
-
%w{--username hoge --password foo --non-interactive}
|
68
|
-
end
|
69
|
-
`cat /tmp/yggdrasil-test/A`.should == "A:no path\n"
|
70
|
-
`cat /tmp/yggdrasil-test/B`.should == "B:no path\n"
|
71
|
-
end
|
72
|
-
|
73
|
-
it 'should success update with revision' do
|
74
|
-
puts '---- should success update with revision'
|
75
|
-
`echo A:hoge > /tmp/yggdrasil-test/A`
|
76
|
-
`echo B:hoge > /tmp/yggdrasil-test/B`
|
77
|
-
Yggdrasil.command %w{commit} +
|
78
|
-
%w{-m hoge} +
|
79
|
-
%w{--username hoge --password foo --non-interactive}
|
80
|
-
|
81
|
-
FileUtils.cd '/tmp' do
|
82
|
-
Yggdrasil.command %w{update} +
|
83
|
-
%w{-r 4 --username hoge --password foo --non-interactive}
|
84
|
-
end
|
85
|
-
`cat /tmp/yggdrasil-test/A`.should == "A:related/absolute path\n"
|
86
|
-
`cat /tmp/yggdrasil-test/B`.should == "B:related/absolute path\n"
|
87
|
-
end
|
88
|
-
end
|