##// END OF EJS Templates
Do not crash on reload....
Do not crash on reload. git-svn-id: http://redmine.rubyforge.org/svn/branches/swistak@1423 e93f8b46-1217-0410-a6f0-8f06a7374b81

File last commit:

r989:1af9c47a2743
r1408:0f8df81b87d7
Show More
reposman.rb
234 lines | 6.3 KiB | text/x-ruby | RubyLexer
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826 #!/usr/bin/ruby
# == Synopsis
#
Jean-Philippe Lang
SVN integration: reposman.rb can now register created repositories in Redmine, so that the administrator doesn't have to enter the repository url in Redmine once it's created....
r847 # reposman: manages your svn repositories with Redmine
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826 #
# == Usage
#
# reposman [ -h | --help ] [ -v | --verbose ] [ -V | --version ] [ -q | --quiet ] -s /var/svn -r redmine.host.org
# example: reposman --svn-dir=/var/svn --redmine-host=redmine.mydomain.foo
# reposman -s /var/svn -r redmine.mydomain.foo
#
# == Arguments (mandatory)
#
# -s, --svn-dir=DIR
# use DIR as base directory for svn repositories
#
# -r, --redmine-host=HOST
Jean-Philippe Lang
SVN integration: reposman.rb can now register created repositories in Redmine, so that the administrator doesn't have to enter the repository url in Redmine once it's created....
r847 # assume Redmine is hosted on HOST.
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826 # you can use :
# * -r redmine.mydomain.foo (will add http://)
# * -r http://redmine.mydomain.foo
# * -r https://mydomain.foo/redmine
#
# == Options
Jean-Philippe Lang
SVN integration: reposman.rb can now register created repositories in Redmine, so that the administrator doesn't have to enter the repository url in Redmine once it's created....
r847 #
# -o, --owner=OWNER
# owner of the repository. using the rails login allow user to browse
# the repository in Redmine even for private project
#
# -u, --url=URL
# the base url Redmine will use to access your repositories. This
# will be used to register the repository in Redmine so that user
# doesn't need to do anything. reposman will add the identifier to this url :
#
# -u https://my.svn.server/my/reposity/root # if the repository can be access by http
# -u file:///var/svn/ # if the repository is local
# if this option isn't set, reposman won't register the repository
#
Nicolas Chuche
* add Redmine.pm to authenticate with mod_perl...
r903 # -t, --test
# only show what should be done
Jean-Philippe Lang
SVN integration: reposman.rb can now register created repositories in Redmine, so that the administrator doesn't have to enter the repository url in Redmine once it's created....
r847 #
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826 # -h, --help:
# show help and exit
#
# -v, --verbose
# verbose
#
# -V, --version
# print version and exit
#
# -q, --quiet
# no log
#
require 'getoptlong'
require 'rdoc/usage'
require 'soap/wsdlDriver'
require 'find'
require 'etc'
Version = "1.0"
opts = GetoptLong.new(
['--svn-dir', '-s', GetoptLong::REQUIRED_ARGUMENT],
['--redmine-host', '-r', GetoptLong::REQUIRED_ARGUMENT],
Jean-Philippe Lang
SVN integration: reposman.rb can now register created repositories in Redmine, so that the administrator doesn't have to enter the repository url in Redmine once it's created....
r847 ['--owner', '-o', GetoptLong::REQUIRED_ARGUMENT],
['--url', '-u', GetoptLong::REQUIRED_ARGUMENT],
Nicolas Chuche
* add Redmine.pm to authenticate with mod_perl...
r903 ['--test', '-t', GetoptLong::NO_ARGUMENT],
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826 ['--verbose', '-v', GetoptLong::NO_ARGUMENT],
['--version', '-V', GetoptLong::NO_ARGUMENT],
['--help' , '-h', GetoptLong::NO_ARGUMENT],
['--quiet' , '-q', GetoptLong::NO_ARGUMENT]
)
$verbose = 0
$quiet = false
$redmine_host = ''
$repos_base = ''
Jean-Philippe Lang
SVN integration: reposman.rb can now register created repositories in Redmine, so that the administrator doesn't have to enter the repository url in Redmine once it's created....
r847 $svn_owner = 'root'
Nicolas Chuche
bug when using apache authentication method...
r989 $use_groupid = true
Jean-Philippe Lang
SVN integration: reposman.rb can now register created repositories in Redmine, so that the administrator doesn't have to enter the repository url in Redmine once it's created....
r847 $svn_url = false
Nicolas Chuche
* add Redmine.pm to authenticate with mod_perl...
r903 $test = false
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826
def log(text,level=0, exit=false)
return if $quiet or level > $verbose
puts text
exit 1 if exit
end
begin
opts.each do |opt, arg|
case opt
Jean-Philippe Lang
SVN integration: reposman.rb can now register created repositories in Redmine, so that the administrator doesn't have to enter the repository url in Redmine once it's created....
r847 when '--svn-dir'; $repos_base = arg.dup
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826 when '--redmine-host'; $redmine_host = arg.dup
Nicolas Chuche
bug when using apache authentication method...
r989 when '--owner'; $svn_owner = arg.dup; $use_groupid = false;
Jean-Philippe Lang
SVN integration: reposman.rb can now register created repositories in Redmine, so that the administrator doesn't have to enter the repository url in Redmine once it's created....
r847 when '--url'; $svn_url = arg.dup
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826 when '--verbose'; $verbose += 1
Nicolas Chuche
* add Redmine.pm to authenticate with mod_perl...
r903 when '--test'; $test = true
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826 when '--version'; puts Version; exit
when '--help'; RDoc::usage
when '--quiet'; $quiet = true
end
end
rescue
exit 1
end
Nicolas Chuche
* add Redmine.pm to authenticate with mod_perl...
r903 if $test
log("running in test mode")
end
Jean-Philippe Lang
SVN integration: reposman.rb can now register created repositories in Redmine, so that the administrator doesn't have to enter the repository url in Redmine once it's created....
r847 $svn_url += "/" if $svn_url and not $svn_url.match(/\/$/)
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826 if ($redmine_host.empty? or $repos_base.empty?)
RDoc::usage
end
unless File.directory?($repos_base)
log("directory '#{$repos_base}' doesn't exists", 0, true)
end
Jean-Philippe Lang
SVN integration: reposman.rb can now register created repositories in Redmine, so that the administrator doesn't have to enter the repository url in Redmine once it's created....
r847 log("querying Redmine for projects...", 1);
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826
$redmine_host.gsub!(/^/, "http://") unless $redmine_host.match("^https?://")
$redmine_host.gsub!(/\/$/, '')
wsdl_url = "#{$redmine_host}/sys/service.wsdl";
begin
soap = SOAP::WSDLDriverFactory.new(wsdl_url).create_rpc_driver
rescue => e
log("Unable to connect to #{wsdl_url} : #{e}", 0, true)
end
projects = soap.Projects
if projects.nil?
log('no project found, perhaps you forgot to "Enable WS for repository management"', 0, true)
end
log("retrieved #{projects.size} projects", 1)
Jean-Philippe Lang
SVN integration: reposman.rb can now register created repositories in Redmine, so that the administrator doesn't have to enter the repository url in Redmine once it's created....
r847 def set_owner_and_rights(project, repos_path, &block)
if RUBY_PLATFORM =~ /mswin/
yield if block_given?
else
Nicolas Chuche
bug when using apache authentication method...
r989 uid, gid = Etc.getpwnam($svn_owner).uid, ($use_groupid ? Etc.getgrnam(project.identifier).gid : 0)
Nicolas Chuche
* add Redmine.pm to authenticate with mod_perl...
r903 right = project.is_public ? 0775 : 0770
Jean-Philippe Lang
SVN integration: reposman.rb can now register created repositories in Redmine, so that the administrator doesn't have to enter the repository url in Redmine once it's created....
r847 yield if block_given?
Find.find(repos_path) do |f|
File.chmod right, f
File.chown uid, gid, f
end
end
end
def other_read_right?(file)
(File.stat(file).mode & 0007).zero? ? false : true
end
def owner_name(file)
RUBY_PLATFORM =~ /mswin/ ?
$svn_owner :
Etc.getpwuid( File.stat(file).uid ).name
end
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826
Jean-Philippe Lang
SVN integration: reposman.rb can now register created repositories in Redmine, so that the administrator doesn't have to enter the repository url in Redmine once it's created....
r847 projects.each do |project|
log("treating project #{project.name}", 1)
if project.identifier.empty?
log("\tno identifier for project #{project.name}")
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826 next
Jean-Philippe Lang
SVN integration: reposman.rb can now register created repositories in Redmine, so that the administrator doesn't have to enter the repository url in Redmine once it's created....
r847 elsif not project.identifier.match(/^[a-z0-9\-]+$/)
log("\tinvalid identifier for project #{project.name} : #{project.identifier}");
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826 next;
end
Jean-Philippe Lang
SVN integration: reposman.rb can now register created repositories in Redmine, so that the administrator doesn't have to enter the repository url in Redmine once it's created....
r847 repos_path = $repos_base + "/" + project.identifier
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826
if File.directory?(repos_path)
Jean-Philippe Lang
SVN integration: reposman.rb can now register created repositories in Redmine, so that the administrator doesn't have to enter the repository url in Redmine once it's created....
r847 # we must verify that repository has the good owner and the good
# rights before leaving
other_read = other_read_right?(repos_path)
owner = owner_name(repos_path)
next if project.is_public == other_read and owner == $svn_owner
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826
Nicolas Chuche
* add Redmine.pm to authenticate with mod_perl...
r903 if $test
log("\tchange mode on #{repos_path}")
next
end
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826 begin
Jean-Philippe Lang
SVN integration: reposman.rb can now register created repositories in Redmine, so that the administrator doesn't have to enter the repository url in Redmine once it's created....
r847 set_owner_and_rights(project, repos_path)
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826 rescue Errno::EPERM => e
log("\tunable to change mode on #{repos_path} : #{e}\n")
next
end
log("\tmode change on #{repos_path}");
else
Nicolas Chuche
* add Redmine.pm to authenticate with mod_perl...
r903 project.is_public ? File.umask(0002) : File.umask(0007)
if $test
log("\tcreate repository #{repos_path}")
log("\trepository #{repos_path} registered in Redmine with url #{$svn_url}#{project.identifier}") if $svn_url;
next
end
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826
begin
Jean-Philippe Lang
SVN integration: reposman.rb can now register created repositories in Redmine, so that the administrator doesn't have to enter the repository url in Redmine once it's created....
r847 set_owner_and_rights(project, repos_path) do
raise "svnadmin create #{repos_path} failed" unless system("svnadmin", "create", repos_path)
end
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826 rescue => e
log("\tunable to create #{repos_path} : #{e}\n")
next
end
Jean-Philippe Lang
SVN integration: reposman.rb can now register created repositories in Redmine, so that the administrator doesn't have to enter the repository url in Redmine once it's created....
r847 if $svn_url
ret = soap.RepositoryCreated project.identifier, "#{$svn_url}#{project.identifier}"
if ret > 0
log("\trepository #{repos_path} registered in Redmine with url #{$svn_url}#{project.identifier}");
else
log("\trepository #{repos_path} not registered in Redmine. Look in your log to find why.");
end
end
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826 log("\trepository #{repos_path} created");
end
end