comparison extra/svn/reposman.rb @ 511:107d36338b70 live

Merge from branch "cannam"
author Chris Cannam
date Thu, 14 Jul 2011 10:43:07 +0100
parents 753f1380d6bc
children 5e80956cc792
comparison
equal deleted inserted replaced
451:a9f6345cb43d 511:107d36338b70
5 # reposman: manages your repositories with Redmine 5 # reposman: manages your repositories with Redmine
6 # 6 #
7 # == Usage 7 # == Usage
8 # 8 #
9 # reposman [OPTIONS...] -s [DIR] -r [HOST] 9 # reposman [OPTIONS...] -s [DIR] -r [HOST]
10 # 10 #
11 # Examples: 11 # Examples:
12 # reposman --svn-dir=/var/svn --redmine-host=redmine.example.net --scm subversion 12 # reposman --svn-dir=/var/svn --redmine-host=redmine.example.net --scm subversion
13 # reposman -s /var/git -r redmine.example.net -u http://svn.example.net --scm git 13 # reposman -s /var/git -r redmine.example.net -u http://svn.example.net --scm git
14 # 14 #
15 # == Arguments (mandatory) 15 # == Arguments (mandatory)
57 # -v, --verbose verbose 57 # -v, --verbose verbose
58 # -V, --version print version and exit 58 # -V, --version print version and exit
59 # -q, --quiet no log 59 # -q, --quiet no log
60 # 60 #
61 # == References 61 # == References
62 # 62 #
63 # You can find more information on the redmine's wiki : http://www.redmine.org/wiki/redmine/HowTos 63 # You can find more information on the redmine's wiki : http://www.redmine.org/wiki/redmine/HowTos
64 64
65 65
66 require 'getoptlong' 66 require 'getoptlong'
67 require 'rdoc/usage' 67 require 'rdoc/usage'
213 end 213 end
214 214
215 log("retrieved #{projects.size} projects", :level => 1) 215 log("retrieved #{projects.size} projects", :level => 1)
216 216
217 def set_owner_and_rights(project, repos_path, &block) 217 def set_owner_and_rights(project, repos_path, &block)
218 if RUBY_PLATFORM =~ /mswin/ 218 if mswin?
219 yield if block_given? 219 yield if block_given?
220 else 220 else
221 uid, gid = Etc.getpwnam($svn_owner).uid, ($use_groupid ? Etc.getgrnam(project.identifier).gid : Etc.getgrnam($svn_group).gid) 221 uid, gid = Etc.getpwnam($svn_owner).uid, ($use_groupid ? Etc.getgrnam(project.identifier).gid : Etc.getgrnam($svn_group).gid)
222 right = project.is_public ? 0775 : 0770 222 right = project.is_public ? 0775 : 0770
223 yield if block_given? 223 yield if block_given?
233 end 233 end
234 234
235 def owner_name(file) 235 def owner_name(file)
236 mswin? ? 236 mswin? ?
237 $svn_owner : 237 $svn_owner :
238 Etc.getpwuid( File.stat(file).uid ).name 238 Etc.getpwuid( File.stat(file).uid ).name
239 end 239 end
240 240
241 def mswin? 241 def mswin?
242 (RUBY_PLATFORM =~ /(:?mswin|mingw)/) || (RUBY_PLATFORM == 'java' && (ENV['OS'] || ENV['os']) =~ /windows/i) 242 (RUBY_PLATFORM =~ /(:?mswin|mingw)/) || (RUBY_PLATFORM == 'java' && (ENV['OS'] || ENV['os']) =~ /windows/i)
243 end 243 end
244 244
245 projects.each do |project| 245 projects.each do |project|
254 end 254 end
255 255
256 repos_path = File.join($repos_base, project.identifier).gsub(File::SEPARATOR, File::ALT_SEPARATOR || File::SEPARATOR) 256 repos_path = File.join($repos_base, project.identifier).gsub(File::SEPARATOR, File::ALT_SEPARATOR || File::SEPARATOR)
257 257
258 if File.directory?(repos_path) 258 if File.directory?(repos_path)
259
260 # we must verify that repository has the good owner and the good 259 # we must verify that repository has the good owner and the good
261 # rights before leaving 260 # rights before leaving
262 other_read = other_read_right?(repos_path) 261 other_read = other_read_right?(repos_path)
263 owner = owner_name(repos_path) 262 owner = owner_name(repos_path)
264 next if project.is_public == other_read and owner == $svn_owner 263 next if project.is_public == other_read and owner == $svn_owner
312 log("\trepository #{repos_path} registered in Redmine with url #{$svn_url}#{project.identifier}"); 311 log("\trepository #{repos_path} registered in Redmine with url #{$svn_url}#{project.identifier}");
313 rescue => e 312 rescue => e
314 log("\trepository #{repos_path} not registered in Redmine: #{e.message}"); 313 log("\trepository #{repos_path} not registered in Redmine: #{e.message}");
315 end 314 end
316 end 315 end
317
318 log("\trepository #{repos_path} created"); 316 log("\trepository #{repos_path} created");
319 end 317 end
320 318 end
321 end 319
322