yggdrasil 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,8 +5,7 @@ class Yggdrasil
5
5
  args = parse_options(args,
6
6
  {'--username'=>:username, '--password'=>:password, '-r'=>:revision, '--revision'=>:revision})
7
7
 
8
- input_user_pass unless @anon_access
9
-
8
+ get_user_pass_if_need_to_read_repo
10
9
  sync_mirror
11
10
 
12
11
  paths = Array.new
@@ -20,7 +19,7 @@ class Yggdrasil
20
19
  end
21
20
 
22
21
  cmd_arg = "#@svn diff --no-auth-cache --non-interactive"
23
- cmd_arg += " --username #{@options[:username]} --password #{@options[:password]}" unless @anon_access
22
+ cmd_arg += username_password_options_to_read_repo
24
23
  cmd_arg += " -r #{@options[:revision]}" if @options.has_key?(:revision)
25
24
  cmd_arg += ' '+paths.join(' ')
26
25
  FileUtils.cd @mirror_dir do
@@ -1,33 +1,36 @@
1
1
  class Yggdrasil
2
2
 
3
- HELP_SUBCOMMANDS = <<EOS
4
- usage: #{CMD} <subcommand> [options] [args]
3
+
4
+ # @param [Array] args
5
+ def help(args)
6
+ if args.size == 0
7
+ puts <<EOS
8
+ usage: #@base_cmd <subcommand> [options] [args]
5
9
  Yggdrasil version #{VERSION}
6
- Type '#{CMD} help <subcommand>' for help on a specific subcommand.
10
+ Type '#@base_cmd help <subcommand>' for help on a specific subcommand.
7
11
 
8
12
  Available subcommands:
9
13
  add
14
+ check (c)
10
15
  cleanup
11
16
  commit (ci)
12
17
  diff (di)
13
18
  help (?, h)
14
19
  init
20
+ init-server
15
21
  list (ls)
16
22
  log
17
- status (stat, st)
23
+ results
18
24
  revert
25
+ server
26
+ status (stat, st)
19
27
  update
20
28
  version
21
29
 
22
- Yggdrasil is a configuration management tool by Subversion.
30
+ Yggdrasil is a subversion wrapper to manage server configurations and conditions.
23
31
  You should type 'yggdrasil init' at first.
24
32
 
25
33
  EOS
26
-
27
- # @param [Array] args
28
- def Yggdrasil.help(args)
29
- if args.size == 0 then
30
- puts HELP_SUBCOMMANDS
31
34
  elsif args.size != 1 then
32
35
  error "too many arguments."
33
36
  else
@@ -35,13 +38,31 @@ EOS
35
38
  when 'add'
36
39
  puts <<"EOS"
37
40
  add: Add files to management list (add to subversion)
38
- usage #{CMD} add [FILES...]
41
+ usage #@base_cmd add [FILES...]
42
+
43
+ EOS
44
+ when 'check', 'c'
45
+ puts <<"EOS"
46
+ check (c): check updating of managed files and the execution output of a commands.
47
+ usage: #@base_cmd check [OPTIONS...]
48
+
49
+ This subcommand execute the executable files in ~/.yggdrasil/checker/, and
50
+ the outputs are checked difference to repository with other managed files.
51
+ For example, mount status, number of specific process and etc. can be checked
52
+ by setting up executable files in ~/.yggdrasil/checker/
53
+
54
+ if the server is registered, the yggdrasil server receive and record the results.
55
+
56
+ Valid options:
57
+ --username ARG : specify a username ARG
58
+ --password ARG : specify a password ARG
59
+ --non-interactive : do no interactive prompting
39
60
 
40
61
  EOS
41
62
  when 'cleanup'
42
63
  puts <<"EOS"
43
64
  cleanup: clean up the working copy
44
- usage: #{CMD} cleanup [OPTIONS...]
65
+ usage: #@base_cmd cleanup [OPTIONS...]
45
66
 
46
67
  Valid options:
47
68
  --username ARG : specify a username ARG
@@ -51,7 +72,7 @@ EOS
51
72
  when 'commit', 'ci'
52
73
  puts <<"EOS"
53
74
  commit (ci): Send changes from your local file to the repository.
54
- usage: #{CMD} commit [OPTIONS...] [FILES...]
75
+ usage: #@base_cmd commit [OPTIONS...] [FILES...]
55
76
 
56
77
  Valid options:
57
78
  --username ARG : specify a username ARG
@@ -63,7 +84,7 @@ EOS
63
84
  when 'diff', 'di'
64
85
  puts <<"EOS"
65
86
  diff (di): Display the differences between two revisions or paths.
66
- usage: #{CMD} diff [OPTIONS...] [PATH...]
87
+ usage: #@base_cmd diff [OPTIONS...] [PATH...]
67
88
 
68
89
  Valid options:
69
90
  --username ARG : specify a username ARG
@@ -81,24 +102,45 @@ EOS
81
102
  when 'help', '?', 'h'
82
103
  puts <<"EOS"
83
104
  help (?,h): Describe the usage of this program or its subcommands.
84
- usage: #{CMD} help [SUBCOMMAND]
105
+ usage: #@base_cmd help [SUBCOMMAND]
85
106
 
86
107
  EOS
87
108
  when 'init'
88
109
  puts <<"EOS"
89
110
  init: Check environment and initialize configuration.
90
- usage: #{CMD} init [OPTIONS...]
111
+ usage: #@base_cmd init [OPTIONS...]
91
112
 
92
113
  Valid options:
93
- --repo ARG : specify svn repository
114
+ --repo ARG : specify svn repository URL
115
+ ARG could be any of the following:
116
+ file:///* : local repository
117
+ svn://* : svn access repository
118
+ http(s)://* : http access repository
119
+ private : make local repository in ~/.yggdrasil
94
120
  --username ARG : specify a username ARG
95
121
  --password ARG : specify a password ARG
122
+ --server ARG : specify a server address and port
123
+ e.g. 192.168.1.35:4000
124
+
125
+ EOS
126
+ when 'init-server'
127
+ puts <<"EOS"
128
+ init-server: setup server configuration.
129
+ usage: #@base_cmd init-server [OPTIONS...]
130
+
131
+ Valid options:
132
+ --port ARG : specify a TCP port number ARG
133
+ --repo ARG : URL of subversion repository
134
+ ARG could be include {HOST} and it replace by client hostname
135
+ e.g. svn://192.168.3.5/servers/{HOST}/ygg
136
+ --ro-username ARG : specify a username ARG for read only
137
+ --ro-password ARG : specify a password ARG for read only
96
138
 
97
139
  EOS
98
140
  when 'list', 'ls'
99
141
  puts <<"EOS"
100
142
  list (ls): List directory entries in the repository.
101
- usage: #{CMD} list [OPTIONS...] [PATH...]
143
+ usage: #@base_cmd list [OPTIONS...] [PATH...]
102
144
 
103
145
  Valid options:
104
146
  --username ARG : specify a username ARG
@@ -117,7 +159,7 @@ EOS
117
159
  when 'log'
118
160
  puts <<"EOS"
119
161
  log: Show the log messages for a set of revision(s) and/or file(s).
120
- usage: #{CMD} log [OPTIONS...] [PATH]
162
+ usage: #@base_cmd log [OPTIONS...] [PATH]
121
163
 
122
164
  Valid options:
123
165
  --username ARG : specify a username ARG
@@ -132,31 +174,49 @@ Valid options:
132
174
  'PREV' revision just before COMMITTED
133
175
 
134
176
  EOS
135
- when 'status', 'stat', 'st'
177
+ when 'results'
136
178
  puts <<"EOS"
137
- status (stat, st): Print the status of managed files and directories.
138
- usage: #{CMD} status [OPTIONS...] [PATH...]
179
+ results: display the result of yggdrasil check command.
180
+ usage: #@base_cmd results [OPTIONS...]
139
181
 
140
182
  Valid options:
141
- --username ARG : specify a username ARG
142
- --password ARG : specify a password ARG
183
+ --limit ARG : minutes from the final report, to judge the host not be alive
143
184
 
144
185
  EOS
145
186
  when 'revert'
146
187
  puts <<"EOS"
147
188
  revert: Restore pristine working copy file (undo most local edits).
148
- usage: #{CMD} revert [PATH...]
189
+ usage: #@base_cmd revert [OPTIONS...] [PATH...]
149
190
 
150
191
  Valid options:
151
192
  --username ARG : specify a username ARG
152
193
  --password ARG : specify a password ARG
153
194
  --non-interactive : do no interactive prompting
154
195
 
196
+ EOS
197
+ when 'server'
198
+ puts <<"EOS"
199
+ server: receive tcp connection in order to unify the setup and to record check results.
200
+ usage: #@base_cmd server [OPTIONS...]
201
+
202
+ Valid options:
203
+ --daemon : daemon mode
204
+
205
+ EOS
206
+ when 'status', 'stat', 'st'
207
+ puts <<"EOS"
208
+ status (stat, st): Print the status of managed files and directories.
209
+ usage: #@base_cmd status [OPTIONS...] [PATH...]
210
+
211
+ Valid options:
212
+ --username ARG : specify a username ARG
213
+ --password ARG : specify a password ARG
214
+
155
215
  EOS
156
216
  when 'update'
157
217
  puts <<"EOS"
158
218
  update (up): Bring changes from the repository into the local files.
159
- usage: #{CMD} update [PATH...]
219
+ usage: #@base_cmd update [OPTIONS...] [PATH...]
160
220
 
161
221
  Valid options:
162
222
  --username ARG : specify a username ARG
@@ -175,7 +235,7 @@ EOS
175
235
  when 'version', '--version'
176
236
  puts <<"EOS"
177
237
  version: See the program version
178
- usage: #{CMD} version
238
+ usage: #@base_cmd version
179
239
 
180
240
  EOS
181
241
  else
@@ -5,7 +5,12 @@ class Yggdrasil
5
5
 
6
6
  args = parse_options(args,
7
7
  {'--username'=>:username, '--password'=>:password,
8
- '--repo'=>:repo, '--parents'=>:parents?, '--non-interactive'=>:non_interactive?})
8
+ '--repo'=>:repo, '--parents'=>:parents?,
9
+ '--non-interactive'=>:non_interactive?,
10
+ '--server'=>:server })
11
+ @options[:ro_username] = @options[:username] if @options.has_key?(:username)
12
+ @options[:ro_password] = @options[:password] if @options.has_key?(:password)
13
+
9
14
  if args.size != 0
10
15
  error "invalid arguments: #{args.join(',')}"
11
16
  end
@@ -19,29 +24,34 @@ class Yggdrasil
19
24
 
20
25
  error "already exist config file: #@config_file" if File.exist?(@config_file)
21
26
 
22
- until @options.has_key?(:repo) do
23
- print "Input svn repo URL: "
24
- input = $stdin.gets
27
+ get_server_config(true) if @options.has_key?(:server)
28
+
29
+ init_get_repo_interactive unless @options.has_key?(:repo)
25
30
 
26
- unless /^(http:|file:|svn:)/ =~ input
27
- puts "ERROR: Invalid URL."
28
- redo
29
- end
30
- @options[:repo] = input
31
- end
32
31
  @options[:repo].chomp!
33
32
  @options[:repo].chomp!('/')
33
+ @options[:repo].gsub!(/\{HOST\}/, Socket.gethostname)
34
+ if @options[:repo] == "private"
35
+ Dir.mkdir @config_dir, 0755 unless File.exist?(@config_dir)
36
+ repo_dir = "#@config_dir/private_repo"
37
+ system3 "svnadmin create #{repo_dir}"
38
+ @options[:repo] = "file://#{repo_dir}"
39
+ end
34
40
 
35
- puts "SVN access test..."
41
+ puts "check SVN access..."
42
+ if @options.has_key?(:ro_username)
43
+ anon_access = false
44
+ else
45
+ anon_access = true
46
+ end
36
47
  url_parts = @options[:repo].split('/')
37
48
  url_parts_num = url_parts.size
38
- anon_access = true
39
49
  loop do
40
50
  if url_parts_num < 3
41
51
  if anon_access
42
52
  anon_access = false
43
53
  url_parts_num = url_parts.size
44
- input_user_pass
54
+ get_user_pass_if_need_to_read_repo
45
55
  else
46
56
  error "can not access to '#{@options[:repo]}'."
47
57
  end
@@ -51,7 +61,7 @@ class Yggdrasil
51
61
  url = url_parts[0...url_parts_num].join('/')
52
62
  puts "try url=#{url}" if @options[:debug?]
53
63
  cmd = "#{svn} ls --no-auth-cache --non-interactive #{url}"
54
- cmd += " --username '#{@options[:username]}' --password '#{@options[:password]}'" unless anon_access
64
+ cmd += username_password_options_to_read_repo
55
65
  ret = system3(cmd, false)
56
66
  unless ret.nil?
57
67
  puts "SVN access OK: #{url}"
@@ -95,17 +105,43 @@ class Yggdrasil
95
105
  system3 "rm -rf #@mirror_dir"
96
106
  end
97
107
 
108
+ # make config file
98
109
  File.open(@config_file, "w") do |f|
99
- f.write "path=#{ENV['PATH']}\n"\
100
- "svn=#{svn}\n"\
101
- "svn_version=#{svn_version}\n"\
102
- "repo=#{@options[:repo]}\n"\
103
- "anon-access=#{anon_access ? 'read' : 'none'}\n"
104
- end
110
+ f.puts "path=#{ENV['PATH']}\n"\
111
+ "svn=#{svn}\n"\
112
+ "svn_version=#{svn_version}\n"\
113
+ "repo=#{@options[:repo]}\n"\
114
+ "anon-access=#{anon_access ? 'read' : 'none'}\n"
115
+ f.puts "server=#{@options[:server]}\n" if @options.has_key?(:server)
116
+ end
105
117
 
118
+ # make mirror dir
106
119
  `rm -rf #@mirror_dir`
107
120
  cmd = "#{svn} checkout --no-auth-cache --non-interactive #{@options[:repo]} #@mirror_dir"
108
121
  cmd += " --username '#{@options[:username]}' --password '#{@options[:password]}'" unless anon_access
109
122
  system3 cmd
123
+
124
+ # make checker dir and checker example
125
+ Dir.mkdir @checker_dir, 0755 unless File.exist?(@checker_dir)
126
+ FileUtils.cd @checker_dir do
127
+ `echo 'gem list' > gem_list`
128
+ `chmod +x gem_list`
129
+ end
130
+ end
131
+
132
+
133
+ def init_get_repo_interactive
134
+ loop do
135
+ print "Input svn repo URL: "
136
+ input = $stdin.gets
137
+ error "can not input svn repo URL" unless input
138
+
139
+ if %r{^(http://|https://|file://|svn://|private)} =~ input
140
+ @options[:repo] = input
141
+ break
142
+ end
143
+
144
+ puts "ERROR: Invalid URL."
145
+ end
110
146
  end
111
147
  end
@@ -7,8 +7,7 @@ class Yggdrasil
7
7
  '-r'=>:revision, '--revision'=>:revision,
8
8
  '-R'=>:recursive?, '--recursive'=>:recursive?})
9
9
 
10
- input_user_pass unless @anon_access
11
-
10
+ get_user_pass_if_need_to_read_repo
12
11
  sync_mirror
13
12
 
14
13
  repos = Array.new
@@ -22,7 +21,7 @@ class Yggdrasil
22
21
  end
23
22
 
24
23
  cmd_arg = "#@svn list --no-auth-cache --non-interactive"
25
- cmd_arg += " --username #{@options[:username]} --password #{@options[:password]}" unless @anon_access
24
+ cmd_arg += username_password_options_to_read_repo
26
25
  cmd_arg += " -r #{@options[:revision]}" if @options.has_key?(:revision)
27
26
  cmd_arg += " -R" if @options.has_key?(:recursive?)
28
27
  cmd_arg += ' ' + repos.join(' ')
data/lib/yggdrasil/log.rb CHANGED
@@ -5,7 +5,7 @@ class Yggdrasil
5
5
  args = parse_options(args,
6
6
  {'--username'=>:username, '--password'=>:password,
7
7
  '-r'=>:revision, '--revision'=>:revision})
8
- input_user_pass unless @anon_access
8
+ get_user_pass_if_need_to_read_repo
9
9
 
10
10
  if args.size == 0
11
11
  dir = @mirror_dir + @current_dir
@@ -22,7 +22,7 @@ class Yggdrasil
22
22
  end
23
23
 
24
24
  cmd_arg = "#@svn log --verbose --no-auth-cache --non-interactive"
25
- cmd_arg += " --username #{@options[:username]} --password #{@options[:password]}" unless @anon_access
25
+ cmd_arg += username_password_options_to_read_repo
26
26
  if @options.has_key?(:revision)
27
27
  cmd_arg += " -r #{@options[:revision]}"
28
28
  else
@@ -5,7 +5,7 @@ class Yggdrasil
5
5
  target_paths = parse_options(args,
6
6
  {'--username'=>:username, '--password'=>:password,
7
7
  '--non-interactive'=>:non_interactive?})
8
- input_user_pass unless @anon_access
8
+ get_user_pass_if_need_to_read_repo
9
9
 
10
10
  updates = sync_mirror
11
11
  matched_updates = select_updates(updates, target_paths)
@@ -17,7 +17,7 @@ class Yggdrasil
17
17
  confirmed_updates = confirm_updates(matched_updates) do |relative_path|
18
18
  FileUtils.cd @mirror_dir do
19
19
  cmd = "#@svn diff --no-auth-cache --non-interactive #{relative_path}"
20
- cmd += " --username '#{@options[:username]}' --password '#{@options[:password]}'" unless @anon_access
20
+ cmd += username_password_options_to_read_repo
21
21
  puts system3(cmd)
22
22
  end
23
23
  end
@@ -27,12 +27,12 @@ class Yggdrasil
27
27
 
28
28
  FileUtils.cd @mirror_dir do
29
29
  cmd = "#@svn revert #{confirmed_updates.reverse.join(' ')}"
30
- cmd += " --username '#{@options[:username]}' --password '#{@options[:password]}'" unless @anon_access
30
+ cmd += username_password_options_to_read_repo
31
31
  system3 cmd
32
32
 
33
33
  # make ls hash
34
34
  cmd = "#@svn ls -R #@repo --no-auth-cache --non-interactive"
35
- cmd += " --username '#{@options[:username]}' --password '#{@options[:password]}'" unless @anon_access
35
+ cmd += username_password_options_to_read_repo
36
36
  out = system3(cmd)
37
37
 
38
38
  ls_hash = Hash.new
@@ -4,7 +4,7 @@ class Yggdrasil
4
4
  def status(args)
5
5
  args = parse_options(args,
6
6
  {'--username'=>:username, '--password'=>:password})
7
- input_user_pass unless @anon_access
7
+ get_user_pass_if_need_to_read_repo
8
8
 
9
9
  sync_mirror
10
10
 
@@ -19,7 +19,7 @@ class Yggdrasil
19
19
  end
20
20
 
21
21
  cmd_arg = "#@svn status#{paths} -qu --no-auth-cache --non-interactive"
22
- cmd_arg += " --username #{@options[:username]} --password #{@options[:password]}" unless @anon_access
22
+ cmd_arg += username_password_options_to_read_repo
23
23
  FileUtils.cd @mirror_dir do
24
24
  out = system3(cmd_arg)
25
25
  print out.gsub(/^Status against revision:.*\n/, '')
@@ -6,16 +6,18 @@ class Yggdrasil
6
6
  {'--username'=>:username, '--password'=>:password,
7
7
  '-r'=>:revision, '--revision'=>:revision,
8
8
  '--non-interactive'=>:non_interactive?})
9
- input_user_pass unless @anon_access
9
+ get_user_pass_if_need_to_read_repo
10
10
  sync_mirror
11
11
 
12
12
  updates = Array.new
13
13
  FileUtils.cd @mirror_dir do
14
14
  cmd = "#@svn status -qu --no-auth-cache --non-interactive"
15
- cmd += " --username '#{@options[:username]}' --password '#{@options[:password]}'" unless @anon_access
15
+ cmd += username_password_options_to_read_repo
16
16
  out = system3(cmd)
17
17
  out.split(/\n/).each do |line|
18
- updates << $1 if /^.*\*.*\s(\S+)\s*$/ =~ line
18
+ if /^.*\*.*\s(\S+)\s*$/ =~ line
19
+ updates << ['', $1]
20
+ end
19
21
  end
20
22
  end
21
23
 
@@ -29,7 +31,7 @@ class Yggdrasil
29
31
  FileUtils.cd @mirror_dir do
30
32
  cmd = "#@svn diff"
31
33
  cmd += " --no-auth-cache --non-interactive"
32
- cmd += " --username #{@options[:username]} --password #{@options[:password]}" unless @anon_access
34
+ cmd += username_password_options_to_read_repo
33
35
  if @options.has_key?(:revision)
34
36
  cmd += " --old=#{relative_path} --new=#{relative_path}@#{@options[:revision]}"
35
37
  else
@@ -44,7 +46,7 @@ class Yggdrasil
44
46
  return if confirmed_updates == 0 # no files to update
45
47
 
46
48
  cmd_arg = "#@svn update --no-auth-cache --non-interactive"
47
- cmd_arg += " --username #{@options[:username]} --password #{@options[:password]}" unless @anon_access
49
+ cmd_arg += username_password_options_to_read_repo
48
50
  if @options.has_key?(:revision)
49
51
  cmd_arg += " -r #{@options[:revision]}"
50
52
  else