yggdrasil 0.0.17 → 0.0.18

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.
@@ -55,12 +55,12 @@ class Yggdrasil
55
55
 
56
56
  def initialize(exist_config = true)
57
57
  @base_cmd = File::basename($0)
58
- @current_dir = `readlink -f .`.chomp
58
+ @current_dir = `pwd`.chomp
59
59
  @config_dir = "#{ENV['HOME']}/.yggdrasil"
60
- @config_file = "#@config_dir/config"
61
- @mirror_dir = "#@config_dir/mirror"
62
- @checker_dir = "#@config_dir/checker"
63
- @checker_result_dir = "#@config_dir/checker_result"
60
+ @config_file = "#{@config_dir}/config"
61
+ @mirror_dir = "#{@config_dir}/mirror"
62
+ @checker_dir = "#{@config_dir}/checker"
63
+ @checker_result_dir = "#{@config_dir}/checker_result"
64
64
 
65
65
  return unless exist_config
66
66
  configs = read_config(@config_file)
@@ -95,7 +95,7 @@ class Yggdrasil
95
95
  @target_file_num = 0
96
96
  FileUtils.cd @mirror_dir do
97
97
  files = Array.new
98
- cmd = "#@svn ls #@repo -R --no-auth-cache --non-interactive"
98
+ cmd = "#{@svn} ls #{@repo} -R --no-auth-cache --non-interactive"
99
99
  cmd += username_password_options_to_read_repo
100
100
  out = system3(cmd)
101
101
  ls_files = out.split(/\n/)
@@ -103,12 +103,12 @@ class Yggdrasil
103
103
  ls_files.each do |ls_file|
104
104
  files << ls_file if ls_file.match("^#{target_relative}")
105
105
  end
106
- cmd = "#@svn update --no-auth-cache --non-interactive"
106
+ cmd = "#{@svn} update --no-auth-cache --non-interactive"
107
107
  cmd += " -r #{@options[:revision]}" if @options.has_key?(:revision)
108
108
  cmd += username_password_options_to_read_repo
109
109
  cmd += ' '+target_relative
110
110
  system3(cmd)
111
- cmd = "#@svn status -q --no-auth-cache --non-interactive"
111
+ cmd = "#{@svn} status -q --no-auth-cache --non-interactive"
112
112
  cmd += username_password_options_to_read_repo
113
113
  cmd += ' '+target_relative
114
114
  out = system3(cmd)
@@ -121,24 +121,31 @@ class Yggdrasil
121
121
  @target_file_num = files.size
122
122
  files.each do |file|
123
123
  if !File.exist?("/#{file}")
124
- system3 "#@svn delete #{file} --force" +
124
+ system3 "#{@svn} delete #{file} --force" +
125
125
  ' --no-auth-cache --non-interactive'
126
126
  elsif File.file?("/#{file}")
127
- if !File.exist?("#@mirror_dir/#{file}")
128
- cmd = "#@svn revert #{file}"
127
+ if !File.exist?("#{@mirror_dir}/#{file}")
128
+ cmd = "#{@svn} revert #{file}"
129
129
  system3 cmd
130
130
  end
131
- #FileUtils.copy_file "/#{file}", "#@mirror_dir/#{file}"
132
- `cp -fd /#{file} #@mirror_dir/#{file}`
131
+ FileUtils.copy_file "/#{file}", "#{@mirror_dir}/#{file}"
132
+ #`cp -fd /#{file} #@mirror_dir/#{file}`
133
133
  end
134
134
  end
135
- cmd = "#@svn status -qu --no-auth-cache --non-interactive"
135
+ cmd = "#{@svn} status -qu --no-auth-cache --non-interactive"
136
136
  cmd += username_password_options_to_read_repo
137
137
  out = system3(cmd)
138
138
  out.split(/\n/).each do |line|
139
139
  next if /^Status against revision/ =~ line
140
140
  if /^(.).*\s(\S+)\s*$/ =~ line
141
- updates << [$1, $2]
141
+ stat = $1
142
+ file = $2
143
+ files.each do |target|
144
+ if file =~ /^#{target}/ || target =~ /^#{file}/
145
+ updates << [stat, file]
146
+ break
147
+ end
148
+ end
142
149
  end
143
150
  end
144
151
  end
@@ -232,14 +239,14 @@ class Yggdrasil
232
239
 
233
240
  def exec_checker
234
241
  # execute checker
235
- `rm -rf #@checker_result_dir`
242
+ `rm -rf #{@checker_result_dir}`
236
243
  Dir.mkdir @checker_result_dir, 0755
237
244
  if File.exist?(@checker_dir)
238
245
  Find.find(@checker_dir) do |file|
239
246
  if File.file?(file) && File.executable?(file)
240
- if file =~ %r{^#@checker_dir(.*)$}
247
+ if file =~ %r{^#{@checker_dir}(.*)$}
241
248
  file_body = $1
242
- system3("#{file} > #@checker_result_dir#{file_body}")
249
+ system3("#{file} > #{@checker_result_dir}#{file_body}")
243
250
  end
244
251
  end
245
252
  end
@@ -3,9 +3,15 @@ class Yggdrasil
3
3
  # @param [Array] args
4
4
  def add(args)
5
5
  parse_options(args, {})
6
+ error "invalid options: #{(@arg_options).join(', ')}" if @arg_options.size != 0
7
+
6
8
  while (arg = @arg_paths.shift)
7
9
 
8
- file_path = system3("readlink -f #{arg}").chomp
10
+ if arg =~ /^\//
11
+ file_path = arg
12
+ else
13
+ file_path = `pwd`.chomp + '/' + arg
14
+ end
9
15
  unless File.exist?(file_path)
10
16
  puts "no such file: #{file_path}"
11
17
  next
@@ -16,11 +22,11 @@ class Yggdrasil
16
22
  mirror_path += "/#{part}"
17
23
  next if File.exist?(mirror_path)
18
24
  if part.equal?(file_path_parts[-1]) && File.file?(file_path)
19
- FileUtils.copy file_path, mirror_path
25
+ FileUtils.copy_file file_path, mirror_path
20
26
  else
21
27
  Dir.mkdir mirror_path
22
28
  end
23
- cmd = "#@svn add #{mirror_path}"
29
+ cmd = "#{@svn} add #{mirror_path}"
24
30
  cmd += ' ' + @arg_options.join(' ') if @arg_options.size != 0
25
31
  puts system3(cmd)
26
32
  end
@@ -20,7 +20,7 @@ class Yggdrasil
20
20
  if matched_updates.size != 0
21
21
  confirmed_updates = confirm_updates(matched_updates, %w{A q}) do |relative_path|
22
22
  FileUtils.cd @mirror_dir do
23
- cmd = "#@svn diff --no-auth-cache --non-interactive #{relative_path}"
23
+ cmd = "#{@svn} diff --no-auth-cache --non-interactive #{relative_path}"
24
24
  cmd += username_password_options_to_read_repo
25
25
  puts system3(cmd)
26
26
  end
@@ -30,7 +30,7 @@ class Yggdrasil
30
30
 
31
31
  ############## add status information to check_result
32
32
  FileUtils.cd @mirror_dir do
33
- cmd = "#@svn status -quN --no-auth-cache --non-interactive"
33
+ cmd = "#{@svn} status -quN --no-auth-cache --non-interactive"
34
34
  cmd += username_password_options_to_read_repo
35
35
  cmd += " #{confirmed_updates.join(' ')}"
36
36
  check_result = system3(cmd)
@@ -48,7 +48,7 @@ class Yggdrasil
48
48
  if result_line =~ /\s(\S+)$/
49
49
  result_path = $1
50
50
  next if File.directory?(result_path)
51
- cmd = "#@svn diff --no-auth-cache --non-interactive"
51
+ cmd = "#{@svn} diff --no-auth-cache --non-interactive"
52
52
  cmd += username_password_options_to_read_repo
53
53
  cmd += ' '+result_path
54
54
  check_result << system3(cmd) +"\n"
@@ -9,9 +9,9 @@ class Yggdrasil
9
9
 
10
10
  get_user_pass_if_need_to_read_repo
11
11
 
12
- system3 "rm -rf #@mirror_dir"
12
+ system3 "rm -rf #{@mirror_dir}"
13
13
 
14
- cmd = "#@svn checkout --no-auth-cache --non-interactive #@repo #@mirror_dir"
14
+ cmd = "#{@svn} checkout --no-auth-cache --non-interactive #{@repo} #{@mirror_dir}"
15
15
  cmd += username_password_options_to_read_repo
16
16
  system3 cmd
17
17
  end
@@ -18,7 +18,7 @@ class Yggdrasil
18
18
 
19
19
  confirmed_updates = confirm_updates(matched_updates) do |relative_path|
20
20
  FileUtils.cd @mirror_dir do
21
- cmd = "#@svn diff --no-auth-cache --non-interactive #{relative_path}"
21
+ cmd = "#{@svn} diff --no-auth-cache --non-interactive #{relative_path}"
22
22
  cmd += username_password_options_to_read_repo
23
23
  puts system3(cmd)
24
24
  end
@@ -45,7 +45,7 @@ class Yggdrasil
45
45
 
46
46
  input_user_pass
47
47
  FileUtils.cd @mirror_dir do
48
- cmd = "#@svn commit -m '#{@options[:message]}'"\
48
+ cmd = "#{@svn} commit -m '#{@options[:message]}'"\
49
49
  ' --no-auth-cache --non-interactive'\
50
50
  " --username '#{@options[:username]}' --password '#{@options[:password]}'"\
51
51
  " #{confirmed_updates.join(' ')}"
@@ -30,7 +30,7 @@ class Yggdrasil
30
30
  error "following files are not managed.\n"+err_paths.join("\n")
31
31
  end
32
32
 
33
- cmd_arg = "#@svn diff --no-auth-cache --non-interactive"
33
+ cmd_arg = "#{@svn} diff --no-auth-cache --non-interactive"
34
34
  cmd_arg += username_password_options_to_read_repo
35
35
  cmd_arg += ' ' + @arg_options.join(' ') if @arg_options.size != 0
36
36
  cmd_arg += " -r #{@options[:diff_rev]}" if @options.has_key?(:diff_rev)
@@ -4,9 +4,9 @@ class Yggdrasil
4
4
  def help(args)
5
5
  if args.size == 0
6
6
  puts <<EOS
7
- usage: #@base_cmd <subcommand> [options] [args]
7
+ usage: #{@base_cmd} <subcommand> [options] [args]
8
8
  Yggdrasil version #{VERSION}
9
- Type '#@base_cmd help <subcommand>' for help on a specific subcommand.
9
+ Type '#{@base_cmd} help <subcommand>' for help on a specific subcommand.
10
10
 
11
11
  Available subcommands:
12
12
  add
@@ -22,7 +22,7 @@ Available subcommands:
22
22
  version
23
23
 
24
24
  Yggdrasil is a subversion wrapper to manage server configurations and conditions.
25
- At first, you should type '#@base_cmd init' to create config file.
25
+ At first, you should type '#{@base_cmd} init' to create config file.
26
26
 
27
27
  EOS
28
28
  elsif args.size != 1 then
@@ -32,14 +32,14 @@ EOS
32
32
  when 'add'
33
33
  puts <<"EOS"
34
34
  add: Add files to management list (add to subversion)
35
- usage #@base_cmd add [FILES...]
35
+ usage #{@base_cmd} add [FILES...]
36
36
 
37
37
  EOS
38
38
 
39
39
  when 'check', 'c', 'status', 'stat', 'st' # check (c, status, stat, st)
40
40
  puts <<"EOS"
41
41
  check (c, status, stat, st): check updating of managed files and the execution output of a commands.
42
- usage: #@base_cmd check [OPTIONS...]
42
+ usage: #{@base_cmd} check [OPTIONS...]
43
43
 
44
44
  This subcommand execute the executable files in ~/.yggdrasil/checker/, and
45
45
  the outputs are checked difference to repository with other managed files.
@@ -60,7 +60,7 @@ EOS
60
60
  when 'cleanup' ################################################ cleanup
61
61
  puts <<"EOS"
62
62
  cleanup: clean up the working copy
63
- usage: #@base_cmd cleanup [OPTIONS...]
63
+ usage: #{@base_cmd} cleanup [OPTIONS...]
64
64
 
65
65
  Valid options:
66
66
  --username ARG : specify a username ARG
@@ -70,7 +70,7 @@ EOS
70
70
  when 'commit', 'ci' ####################################### commit (ci)
71
71
  puts <<"EOS"
72
72
  commit (ci): Send changes from your local file to the repository.
73
- usage: #@base_cmd commit [OPTIONS...] [FILES...]
73
+ usage: #{@base_cmd} commit [OPTIONS...] [FILES...]
74
74
 
75
75
  Valid options:
76
76
  --username ARG : specify a username ARG
@@ -82,7 +82,7 @@ EOS
82
82
  when 'diff', 'di' ########################################### diff (di)
83
83
  puts <<"EOS"
84
84
  diff (di): Display the differences between two revisions or paths.
85
- usage: #@base_cmd diff [OPTIONS...] [PATH...]
85
+ usage: #{@base_cmd} diff [OPTIONS...] [PATH...]
86
86
 
87
87
  Valid options:
88
88
  --username ARG : specify a username ARG
@@ -100,13 +100,13 @@ EOS
100
100
  when 'help', '--help', 'h', '-h', '?' ###################### help (?,h)
101
101
  puts <<"EOS"
102
102
  help (?,h): Describe the usage of this program or its subcommands.
103
- usage: #@base_cmd help [SUBCOMMAND]
103
+ usage: #{@base_cmd} help [SUBCOMMAND]
104
104
 
105
105
  EOS
106
106
  when 'init' ###################################################### init
107
107
  puts <<"EOS"
108
108
  init: Check environment and initialize configuration.
109
- usage: #@base_cmd init [OPTIONS...]
109
+ usage: #{@base_cmd} init [OPTIONS...]
110
110
 
111
111
  Valid options:
112
112
  --repo ARG : specify svn repository URL
@@ -126,7 +126,7 @@ EOS
126
126
  when 'list', 'ls' ########################################### list (ls)
127
127
  puts <<"EOS"
128
128
  list (ls): List directory entries in the repository.
129
- usage: #@base_cmd list [OPTIONS...] [PATH...]
129
+ usage: #{@base_cmd} list [OPTIONS...] [PATH...]
130
130
 
131
131
  Valid options:
132
132
  --username ARG : specify a username ARG
@@ -145,7 +145,7 @@ EOS
145
145
  when 'log' ######################################################## log
146
146
  puts <<"EOS"
147
147
  log: Show the log messages for a set of revision(s) and/or file(s).
148
- usage: #@base_cmd log [OPTIONS...] [PATH]
148
+ usage: #{@base_cmd} log [OPTIONS...] [PATH]
149
149
 
150
150
  Valid options:
151
151
  --username ARG : specify a username ARG
@@ -165,7 +165,7 @@ EOS
165
165
  when 'update', 'up', 'revert' ##################### update (up, revert)
166
166
  puts <<"EOS"
167
167
  update (up, revert): Set the files to the contents of the newest repository.
168
- usage: #@base_cmd update [OPTIONS...] [PATH...]
168
+ usage: #{@base_cmd} update [OPTIONS...] [PATH...]
169
169
 
170
170
  Valid options:
171
171
  --username ARG : specify a username ARG
@@ -178,7 +178,7 @@ EOS
178
178
  when 'version', '--version', '-v' ######################## version (-v)
179
179
  puts <<"EOS"
180
180
  version: See the program version
181
- usage: #@base_cmd version
181
+ usage: #{@base_cmd} version
182
182
 
183
183
  EOS
184
184
  else
@@ -26,11 +26,11 @@ class Yggdrasil
26
26
 
27
27
  while File.exist?(@config_file)
28
28
  if @options[:force?]
29
- `rm -rf #@config_file`
29
+ `rm -rf #{@config_file}`
30
30
  break
31
31
  end
32
- error "Already exist config file. use --force to ignore" if @options[:non_interactive?]
33
- puts "Already exist config file: #@config_file"
32
+ error 'Already exist config file. use --force to ignore' if @options[:non_interactive?]
33
+ puts "Already exist config file: #{@config_file}"
34
34
  print 'Overwrite? [Yn]: '
35
35
  res = $stdin.gets
36
36
  puts
@@ -38,7 +38,7 @@ class Yggdrasil
38
38
  res.chomp!
39
39
  return nil if res == 'n'
40
40
  if res == 'Y'
41
- `rm -rf #@config_file`
41
+ `rm -rf #{@config_file}`
42
42
  break
43
43
  end
44
44
  end
@@ -53,7 +53,7 @@ class Yggdrasil
53
53
  @options[:repo].gsub!(/\{host\}/, Socket.gethostname.split('.')[0])
54
54
  if @options[:repo] == 'private'
55
55
  Dir.mkdir @config_dir, 0755 unless File.exist?(@config_dir)
56
- repo_dir = "#@config_dir/private_repo"
56
+ repo_dir = "#{@config_dir}/private_repo"
57
57
  system3 "svnadmin create #{repo_dir}"
58
58
  @options[:repo] = "file://#{repo_dir}"
59
59
  end
@@ -109,10 +109,10 @@ class Yggdrasil
109
109
  break if input == 'Y'
110
110
  end
111
111
  input_user_pass
112
- `rm -rf #@mirror_dir`
112
+ `rm -rf #{@mirror_dir}`
113
113
  system3 "#{svn} checkout -N --no-auth-cache --non-interactive" +
114
114
  " --username '#{@options[:ro_username]}' --password '#{@options[:ro_password]}'" +
115
- " #{url_parts[0...url_parts_num].join('/')} #@mirror_dir"
115
+ " #{url_parts[0...url_parts_num].join('/')} #{@mirror_dir}"
116
116
  add_paths = Array.new
117
117
  path = @mirror_dir
118
118
  while url_parts_num < url_parts.size
@@ -127,7 +127,7 @@ class Yggdrasil
127
127
  system3 "#{svn} commit -m 'yggdrasil init' --no-auth-cache --non-interactive" +
128
128
  " --username '#{@options[:username]}' --password '#{@options[:password]}'" +
129
129
  ' ' + add_paths.join(' ')
130
- system3 "rm -rf #@mirror_dir"
130
+ system3 "rm -rf #{@mirror_dir}"
131
131
  end
132
132
 
133
133
  # make config file
@@ -141,8 +141,8 @@ class Yggdrasil
141
141
  end
142
142
 
143
143
  # make mirror dir
144
- `rm -rf #@mirror_dir`
145
- cmd = "#{svn} checkout --no-auth-cache --non-interactive #{@options[:repo]} #@mirror_dir"
144
+ `rm -rf #{@mirror_dir}`
145
+ cmd = "#{svn} checkout --no-auth-cache --non-interactive #{@options[:repo]} #{@mirror_dir}"
146
146
  cmd += " --username '#{@options[:ro_username]}' --password '#{@options[:ro_password]}'" unless anon_access
147
147
  system3 cmd
148
148
 
@@ -152,7 +152,7 @@ class Yggdrasil
152
152
 
153
153
 
154
154
  def init_get_repo_interactive
155
- error "need --repo or --server" if @options[:non_interactive?]
155
+ error 'need --repo or --server' if @options[:non_interactive?]
156
156
  loop do
157
157
  print 'Input svn repo URL: '
158
158
  input = $stdin.gets
@@ -14,11 +14,11 @@ class Yggdrasil
14
14
 
15
15
  repos = Array.new
16
16
  @arg_paths.each do |path|
17
- path = "#@current_dir/#{path}" unless %r{^/} =~ path
17
+ path = "#{@current_dir}/#{path}" unless %r{^/} =~ path
18
18
  repos << @repo+path
19
19
  end
20
20
 
21
- cmd_arg = "#@svn list --no-auth-cache --non-interactive"
21
+ cmd_arg = "#{@svn} list --no-auth-cache --non-interactive"
22
22
  cmd_arg += username_password_options_to_read_repo
23
23
  cmd_arg += " -r #{@options[:revision]}" if @options.has_key?(:revision)
24
24
  cmd_arg += ' -R' if @options.has_key?(:recursive?)
@@ -28,7 +28,7 @@ class Yggdrasil
28
28
  error "following files are not managed.\n"+err_paths.join("\n")
29
29
  end
30
30
 
31
- cmd_arg = "#@svn log --no-auth-cache --non-interactive"
31
+ cmd_arg = "#{@svn} log --no-auth-cache --non-interactive"
32
32
  cmd_arg += username_password_options_to_read_repo
33
33
  cmd_arg += ' ' + @arg_options.join(' ') if @arg_options.size != 0
34
34
  if @options.has_key?(:revision)
@@ -17,7 +17,7 @@ class Yggdrasil
17
17
 
18
18
  confirmed_updates = confirm_updates(matched_updates) do |relative_path|
19
19
  FileUtils.cd @mirror_dir do
20
- cmd = "#@svn diff --no-auth-cache --non-interactive #{relative_path}"
20
+ cmd = "#{@svn} diff --no-auth-cache --non-interactive #{relative_path}"
21
21
  cmd += username_password_options_to_read_repo
22
22
  puts system3(cmd)
23
23
  end
@@ -26,11 +26,11 @@ class Yggdrasil
26
26
  return if confirmed_updates.size == 0
27
27
 
28
28
  FileUtils.cd @mirror_dir do
29
- cmd = "#@svn revert #{confirmed_updates.reverse.join(' ')}"
29
+ cmd = "#{@svn} revert #{confirmed_updates.reverse.join(' ')}"
30
30
  system3 cmd
31
31
 
32
32
  # make ls hash
33
- cmd = "#@svn ls -R #@repo --no-auth-cache --non-interactive"
33
+ cmd = "#{@svn} ls -R #{@repo} --no-auth-cache --non-interactive"
34
34
  cmd += username_password_options_to_read_repo
35
35
  out = system3(cmd)
36
36
 
@@ -40,8 +40,8 @@ class Yggdrasil
40
40
  # reflect mirror to real file
41
41
  confirmed_updates.each do |file|
42
42
  if ls_hash.has_key?(file)
43
- if File.file?("#@mirror_dir/#{file}")
44
- FileUtils.copy_file "#@mirror_dir/#{file}", "/#{file}"
43
+ if File.file?("#{@mirror_dir}/#{file}")
44
+ FileUtils.copy_file "#{@mirror_dir}/#{file}", "/#{file}"
45
45
  end
46
46
  else
47
47
  system3 "rm -rf #{@mirror_dir + '/' + file}"
@@ -1,9 +1,9 @@
1
1
  class Yggdrasil
2
- VERSION = '0.0.17'
2
+ VERSION = '0.0.18'
3
3
 
4
4
  def version
5
5
  puts <<"EOS"
6
- #@base_cmd, version #{VERSION}
6
+ #{@base_cmd}, version #{VERSION}
7
7
 
8
8
  Copyright (C) 2012-2013 Tomohisa Kusukawa.
9
9
  Yggdrasil is open source software, see https://github.com/tkusukawa/yggdrasil/
@@ -69,7 +69,6 @@ module YggdrasilCommon
69
69
  print 'Input svn username: '
70
70
  input = $stdin.gets
71
71
  error 'can not input username' unless input
72
- puts
73
72
  input.chomp!
74
73
  return if input.size == 0
75
74
  @options[:username] = @options[:ro_username] = input
@@ -100,7 +99,7 @@ module YggdrasilCommon
100
99
  else
101
100
  cmd_display = (cmd.split)[0]+' ...'
102
101
  end
103
- $stderr.puts "#@base_cmd error: command failure: #{cmd_display}"
102
+ $stderr.puts "#{@base_cmd} error: command failure: #{cmd_display}"
104
103
  $stderr.puts 'command output:'
105
104
  $stderr.puts out
106
105
  exit stat.exitstatus
@@ -110,7 +109,7 @@ module YggdrasilCommon
110
109
 
111
110
  # @param [String] msg
112
111
  def error(msg)
113
- $stderr.puts "#@base_cmd error: #{msg}"
112
+ $stderr.puts "#{@base_cmd} error: #{msg}"
114
113
  $stderr.puts
115
114
  exit 1
116
115
  end
@@ -51,10 +51,10 @@ class YggdrasilServer
51
51
 
52
52
  def initialize(exist_config = true)
53
53
  @base_cmd = File::basename($0)
54
- @current_dir = `readlink -f .`.chomp
54
+ @current_dir = `pwd`.chomp
55
55
  @config_dir = "#{ENV['HOME']}/.yggdrasil"
56
- @server_config_file = "#@config_dir/server_config"
57
- @results_dir = "#@config_dir/results"
56
+ @server_config_file = "#{@config_dir}/server_config"
57
+ @results_dir = "#{@config_dir}/results"
58
58
 
59
59
  return unless exist_config
60
60
  configs = read_config(@server_config_file)
@@ -6,9 +6,9 @@ class YggdrasilServer
6
6
  def help(args)
7
7
  if args.size == 0
8
8
  puts <<EOS
9
- usage: #@base_cmd <subcommand> [options] [args]
9
+ usage: #{@base_cmd} <subcommand> [options] [args]
10
10
  Yggdrasil version #{Yggdrasil::VERSION}
11
- Type '#@base_cmd help <subcommand>' for help on a specific subcommand.
11
+ Type '#{@base_cmd} help <subcommand>' for help on a specific subcommand.
12
12
 
13
13
  Available subcommands:
14
14
  daemon
@@ -21,7 +21,7 @@ Available subcommands:
21
21
  Yggdrasil server is a TCP server
22
22
  to receive/record the yggdrasil check result of all managed servers.
23
23
 
24
- At first, you should type '#@base_cmd init' to create config file.
24
+ At first, you should type '#{@base_cmd} init' to create config file.
25
25
 
26
26
  EOS
27
27
  elsif args.size != 1 then
@@ -43,13 +43,13 @@ EOS
43
43
  when 'help', '--help', 'h', '-h', '?' ###################### help (h,?)
44
44
  puts <<"EOS"
45
45
  help (?,h): Describe the usage of this program or its subcommands.
46
- usage: #@base_cmd help [SUBCOMMAND]
46
+ usage: #{@base_cmd} help [SUBCOMMAND]
47
47
 
48
48
  EOS
49
49
  when 'init' ###################################################### init
50
50
  puts <<"EOS"
51
51
  init: setup yggdrasil server configuration.
52
- usage: #@base_cmd init [OPTIONS...]
52
+ usage: #{@base_cmd} init [OPTIONS...]
53
53
 
54
54
  Valid options:
55
55
  --port ARG : specify a TCP port number ARG
@@ -65,7 +65,7 @@ EOS
65
65
  when 'results', 'res' ################################### results (res)
66
66
  puts <<"EOS"
67
67
  results: display the result of yggdrasil check command.
68
- usage: #@base_cmd results [OPTIONS...]
68
+ usage: #{@base_cmd} results [OPTIONS...]
69
69
 
70
70
  Valid options:
71
71
  --expire ARG : minutes from the final report, to judge the host not be alive
@@ -74,7 +74,7 @@ EOS
74
74
  when 'version', '--version', '-v' ######################## version (-v)
75
75
  puts <<"EOS"
76
76
  version: See the program version
77
- usage: #@base_cmd version
77
+ usage: #{@base_cmd} version
78
78
 
79
79
  EOS
80
80
  else
@@ -6,7 +6,7 @@ class YggdrasilServer
6
6
  end
7
7
  # make result file
8
8
  Dir.mkdir @results_dir, 0755 unless File.exist?(@results_dir)
9
- result_file = "#@results_dir/#{arg_hash[:hostname]}_#{sock.peeraddr[3]}"
9
+ result_file = "#{@results_dir}/#{arg_hash[:hostname]}_#{sock.peeraddr[3]}"
10
10
  File.delete result_file if File.exist?(result_file)
11
11
  File.open(result_file, 'w') do |f|
12
12
  f.write result_string
@@ -1,3 +1,5 @@
1
+ require 'nkf'
2
+
1
3
  class YggdrasilServer
2
4
 
3
5
  # @param [Array] args
@@ -13,7 +15,7 @@ class YggdrasilServer
13
15
  alert = false
14
16
  files.each do |file|
15
17
  next if /^\./ =~ file
16
- absolute = "#@results_dir/#{file}"
18
+ absolute = "#{@results_dir}/#{file}"
17
19
  if @options.has_key?(:expire)
18
20
  stat = File.stat(absolute)
19
21
  if stat.mtime < (Time.now - @options[:expire].to_i * 60)
@@ -23,7 +25,8 @@ class YggdrasilServer
23
25
  next
24
26
  end
25
27
  end
26
- buf = File.read("#@results_dir/#{file}")
28
+ buf = File.read("#{@results_dir}/#{file}")
29
+ buf = NKF::nkf('-wm0', buf)
27
30
  if buf.gsub(/\s*\n/m, '') != ''
28
31
  alert = true
29
32
  puts "######## #{file} Mismatch:"
@@ -7,7 +7,7 @@ class YggdrasilServer
7
7
  end
8
8
 
9
9
  ctime = Time.now
10
- $stdout.printf "Start: yggdrasil server (port:#@port)[%04d-%02d-%02d %02d:%02d:%02d.%03d]\n",
10
+ $stdout.printf "Start: yggdrasil server (port:#{@port})[%04d-%02d-%02d %02d:%02d:%02d.%03d]\n",
11
11
  ctime.year, ctime.month, ctime.day, ctime.hour, ctime.min, ctime.sec, (ctime.usec/1000).round
12
12
  $stdout.flush
13
13
  TCPServer.do_not_reverse_lookup = true
@@ -43,7 +43,7 @@ class YggdrasilServer
43
43
  sock.close
44
44
  if @options.has_key?(:debug?) && msg == MESSAGE_QUIT
45
45
  ctime = Time.now
46
- $stdout.printf "Quit: yggdrasil server (port:#@port)[%04d-%02d-%02d %02d:%02d:%02d.%03d]\n",
46
+ $stdout.printf "Quit: yggdrasil server (port:#{@port})[%04d-%02d-%02d %02d:%02d:%02d.%03d]\n",
47
47
  ctime.year, ctime.month, ctime.day, ctime.hour, ctime.min, ctime.sec, (ctime.usec/1000).round
48
48
  $stdout.flush
49
49
  break
@@ -4,7 +4,7 @@ class YggdrasilServer
4
4
 
5
5
  def version
6
6
  puts <<"EOS"
7
- #@base_cmd, version #{Yggdrasil::VERSION}
7
+ #{@base_cmd}, version #{Yggdrasil::VERSION}
8
8
 
9
9
  Copyright (C) 2012-2013 Tomohisa Kusukawa.
10
10
  Yggdrasil is open source software, see https://github.com/tkusukawa/yggdrasil/
@@ -286,7 +286,7 @@ EOS
286
286
  end
287
287
 
288
288
  it 'should recover delete flag' do
289
- pending "under construction..."
289
+ pending 'under construction...'
290
290
  puts "\n---- should recover delete flag"
291
291
 
292
292
  `mkdir /tmp/yggdrasil-test/c`
@@ -155,4 +155,137 @@ describe Yggdrasil, 'commit' do
155
155
  puts res
156
156
  res.should == "A\n"
157
157
  end
158
+
159
+ it 'should commit symbolic link files' do
160
+ puts '---- should commit symbolic link files'
161
+ `ln -s /tmp/yggdrasil-test/A /tmp/yggdrasil-test/B`
162
+ `ln -s /tmp/yggdrasil-test /tmp/yggdrasil-test/c`
163
+
164
+ puts '1'
165
+ Yggdrasil.command %w{add /tmp/yggdrasil-test/B /tmp/yggdrasil-test/c/A}
166
+ puts '2'
167
+
168
+ out = catch_out {Yggdrasil.command %w{c --username hoge --password foo}}
169
+ out.should == <<"EOS"
170
+
171
+ 0:A tmp/yggdrasil-test/B
172
+ 1:A tmp/yggdrasil-test/c
173
+ 2:A tmp/yggdrasil-test/c/A
174
+ OK? [A|q|<num to diff>]:#{' '}
175
+ EOS
176
+ puts '3'
177
+
178
+ Yggdrasil.command %w{commit -m addSymbolicLinks --debug} +
179
+ %w{--username hoge --password foo},
180
+ "Y\n"
181
+ puts '4'
182
+
183
+ res = `svn ls file:///tmp/yggdrasil-test/svn-repo/mng-repo/host-name/tmp/yggdrasil-test`
184
+ puts res
185
+ res.should == "A\nB\nc/\n"
186
+ puts '5'
187
+
188
+ out = catch_out {Yggdrasil.command %w{c --username hoge --password foo}}
189
+ out.should == <<"EOS"
190
+ 6 files checked.
191
+ Yggdrasil check: OK.
192
+ EOS
193
+
194
+ `echo hoge >> /tmp/yggdrasil-test/A`
195
+
196
+ out = catch_out {Yggdrasil.command %w{c --username hoge --password foo}}
197
+ out.should == <<"EOS"
198
+
199
+ 0:M tmp/yggdrasil-test/A
200
+ 1:M tmp/yggdrasil-test/B
201
+ 2:M tmp/yggdrasil-test/c/A
202
+ OK? [A|q|<num to diff>]:#{' '}
203
+ EOS
204
+
205
+ Yggdrasil.command %w{commit -m addSymbolicLinks --debug} +
206
+ %w{--username hoge --password foo},
207
+ "Y\n"
208
+
209
+ out = catch_out {Yggdrasil.command %w{c --username hoge --password foo}}
210
+ out.should == <<"EOS"
211
+ 6 files checked.
212
+ Yggdrasil check: OK.
213
+ EOS
214
+
215
+ end
216
+
217
+ it 'should commit only specified files' do
218
+ puts '---- should commit only specified files'
219
+
220
+ `echo hoge >> /tmp/yggdrasil-test/A`
221
+
222
+ out = catch_out {Yggdrasil.command %w{c --username hoge --password foo}}
223
+ out.should == <<"EOS"
224
+
225
+ 0:M tmp/yggdrasil-test/A
226
+ 1:M tmp/yggdrasil-test/B
227
+ 2:M tmp/yggdrasil-test/c/A
228
+ OK? [A|q|<num to diff>]:#{' '}
229
+ EOS
230
+
231
+ out = catch_out do
232
+ Yggdrasil.command %w{commit -m absolutePath --debug /tmp/yggdrasil-test/A} +
233
+ %w{--username hoge --password foo},
234
+ "Y\n"
235
+ end
236
+ out.should == <<"EOS"
237
+
238
+ 0:M tmp/yggdrasil-test/A
239
+ OK? [Y|n|<num to diff>]:#{' '}
240
+ Sending tmp/yggdrasil-test/A
241
+ Transmitting file data .
242
+ Committed revision 12.
243
+ EOS
244
+
245
+ out = catch_out {Yggdrasil.command %w{c --username hoge --password foo}}
246
+ out.should == <<"EOS"
247
+
248
+ 0:M tmp/yggdrasil-test/B
249
+ 1:M tmp/yggdrasil-test/c/A
250
+ OK? [A|q|<num to diff>]:#{' '}
251
+ EOS
252
+
253
+ out = catch_out do
254
+ FileUtils.cd '/tmp/yggdrasil-test' do
255
+ Yggdrasil.command %w{commit -m absolutePath --debug c} +
256
+ %w{--username hoge --password foo},
257
+ "Y\n"
258
+ end
259
+ end
260
+ out.should == <<"EOS"
261
+
262
+ 0:M tmp/yggdrasil-test/c/A
263
+ OK? [Y|n|<num to diff>]:#{' '}
264
+ Sending tmp/yggdrasil-test/c/A
265
+ Transmitting file data .
266
+ Committed revision 13.
267
+ EOS
268
+
269
+ out = catch_out {Yggdrasil.command %w{c --username hoge --password foo}}
270
+ out.should == <<"EOS"
271
+
272
+ 0:M tmp/yggdrasil-test/B
273
+ OK? [A|q|<num to diff>]:#{' '}
274
+ EOS
275
+
276
+ out = catch_out do
277
+ Yggdrasil.command %w{commit -m absolutePath --debug} +
278
+ %w{--username hoge --password foo},
279
+ "Y\n"
280
+ end
281
+ out.should == <<"EOS"
282
+
283
+ 0:M tmp/yggdrasil-test/B
284
+ OK? [Y|n|<num to diff>]:#{' '}
285
+ Sending tmp/yggdrasil-test/B
286
+ Transmitting file data .
287
+ Committed revision 14.
288
+ EOS
289
+ end
290
+
158
291
  end
@@ -125,8 +125,7 @@ EOS
125
125
  out.should == <<"EOS"
126
126
  Input svn repo URL:#{' '}
127
127
  check SVN access...
128
- Input svn username:#{' '}
129
- Input svn password:#{' '}
128
+ Input svn username:#{' '}Input svn password:#{' '}
130
129
  SVN access OK: svn://localhost/tmp/yggdrasil-test/svn-repo
131
130
  not exist directory(s) in repository: mng-repo/host-name
132
131
  make directory(s)? [Yn]:#{' '}
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  require File.dirname(__FILE__) + '/spec_helper'
2
3
  require 'yggdrasil_server'
3
4
 
@@ -81,6 +82,22 @@ Index: tmp/yggdrasil-test/A
81
82
  EOS
82
83
  end
83
84
 
85
+ it 'should show s-jis results' do
86
+ puts '---- should show s-jis results'
87
+
88
+ `rm /tmp/yggdrasil-test/.yggdrasil/results/*`
89
+ `echo 'あいうえお' | nkf -s > /tmp/yggdrasil-test/.yggdrasil/results/hoge`
90
+
91
+ out = catch_out do
92
+ lambda{YggdrasilServer.command(%w{results})}.should raise_error(SystemExit)
93
+ end
94
+ out.should == <<"EOS"
95
+ ######## hoge Mismatch:
96
+ あいうえお
97
+ EOS
98
+ end
99
+
100
+
84
101
  after(:all) do
85
102
  sleep 1
86
103
  sock = TCPSocket.open('localhost', 4000)
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.17
4
+ version: 0.0.18
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-11 00:00:00.000000000 Z
12
+ date: 2013-08-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -116,7 +116,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
116
116
  version: '0'
117
117
  segments:
118
118
  - 0
119
- hash: 522662544395152176
119
+ hash: 1911977696976218263
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: 522662544395152176
128
+ hash: 1911977696976218263
129
129
  requirements: []
130
130
  rubyforge_project:
131
131
  rubygems_version: 1.8.25