##// END OF EJS Templates
Upgraded to Rails 2.3.4 (#3597)...
Upgraded to Rails 2.3.4 (#3597) * Ran the Rails upgrade * Upgraded to Rails Engines 2.3.2 * Added a plugin to let Engines override application views. * Converted tests to use the new classes: ** ActionController::TestCase for functional ** ActiveSupport::TestCase for units * Converted ActiveRecord::Error message to a string. * ActiveRecord grouping returns an ordered hash which doesn't have #sort! * Updated the I18n storage_units format. * Added some default initializers from a fresh rails app * Changed the order of check_box_tags and hidden_field_tags. The hidden tag needs to appear first in Rails 2.3, otherwise it will override any value in the check_box_tag. * Removed the custom handler for when the cookie store is tampered with. Rails 2.3 removed the TamperedWithCookie exception and instead Rails will not load the data from it when it's been tampered with (e.g. no user login). * Fixed mail layouts, 2.3 has problems with implicit multipart emails that use layouts. Also removed some custom Redmine mailer code. * Fixed a bug that occurred in tests where the "required" span tag would be added to the :field_status translation. This resulted in an email string of: <li>Status<span class="required"> *</span><span class="required"> *</span> Instead of: <li>Status: New</li> git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2887 e93f8b46-1217-0410-a6f0-8f06a7374b81

File last commit:

r2416:6359e514771a
r2773:7b0cb6aba871
Show More
reposman.rb
299 lines | 9.8 KiB | text/x-ruby | RubyLexer
Jean-Philippe Lang
Changes ruby bang path to #!/usr/bin/env ruby (#1876)....
r2015 #!/usr/bin/env ruby
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826
# == Synopsis
#
Nicolas Chuche
* reposman can create git repository with "--scm git" option...
r1864 # reposman: manages your repositories with Redmine
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826 #
# == Usage
#
Jean-Philippe Lang
Merged nbc branch @ r1812 (commit access permission and reposman improvements)....
r1812 # reposman [OPTIONS...] -s [DIR] -r [HOST]
#
# Examples:
Nicolas Chuche
* reposman can create git repository with "--scm git" option...
r1864 # reposman --svn-dir=/var/svn --redmine-host=redmine.example.net --scm subversion
# reposman -s /var/git -r redmine.example.net -u http://svn.example.net --scm git
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826 #
# == Arguments (mandatory)
#
Jean-Philippe Lang
Merged nbc branch @ r1812 (commit access permission and reposman improvements)....
r1812 # -s, --svn-dir=DIR use DIR as base directory for svn repositories
# -r, --redmine-host=HOST assume Redmine is hosted on HOST. Examples:
# -r redmine.example.net
# -r http://redmine.example.net
# -r https://example.net/redmine
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826 #
# == 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 #
Jean-Philippe Lang
Merged nbc branch @ r1812 (commit access permission and reposman improvements)....
r1812 # -o, --owner=OWNER owner of the repository. using the rails login
# allow user to browse the repository within
Nicolas Chuche
* reposman can create git repository with "--scm git" option...
r1864 # Redmine even for private project. If you want to share repositories
# through Redmine.pm, you need to use the apache owner.
Nicolas Chuche
Fixed: add group option to set the repository gid. Default is root (#2747)...
r2416 # -g, --group=GROUP group of the repository. (default: root)
Nicolas Chuche
* reposman can create git repository with "--scm git" option...
r1864 # --scm=SCM the kind of SCM repository you want to create (and register) in
# Redmine (default: Subversion). reposman is able to create Git
# and Subversion repositories. For all other kind (Bazaar,
# Darcs, Filesystem, Mercurial) you must specify a --command option
Jean-Philippe Lang
Merged nbc branch @ r1812 (commit access permission and reposman improvements)....
r1812 # -u, --url=URL the base url Redmine will use to access your
# repositories. This option is used to automatically
# register the repositories in Redmine. The project
# identifier will be appended to this url. Examples:
# -u https://example.net/svn
# -u file:///var/svn/
# if this option isn't set, reposman won't register
# the repositories in Redmine
# -c, --command=COMMAND use this command instead of "svnadmin create" to
# create a repository. This option can be used to
Nicolas Chuche
* reposman can create git repository with "--scm git" option...
r1864 # create repositories other than subversion and git kind.
# This command override the default creation for git and subversion.
Jean-Philippe Lang
Merged nbc branch @ r1812 (commit access permission and reposman improvements)....
r1812 # -f, --force force repository creation even if the project
# repository is already declared in Redmine
# -t, --test only show what should be done
# -h, --help show help and exit
# -v, --verbose verbose
# -V, --version print version and exit
# -q, --quiet no log
Nicolas Chuche
* reposman can create git repository with "--scm git" option...
r1864 #
# == References
#
# You can find more information on the redmine's wiki : http://www.redmine.org/wiki/redmine/HowTos
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826
require 'getoptlong'
require 'rdoc/usage'
require 'find'
require 'etc'
Nicolas Chuche
Fixed: add group option to set the repository gid. Default is root (#2747)...
r2416 Version = "1.3"
Jean-Philippe Lang
Merged nbc branch @ r1812 (commit access permission and reposman improvements)....
r1812 SUPPORTED_SCM = %w( Subversion Darcs Mercurial Bazaar Git Filesystem )
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826
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],
Nicolas Chuche
Fixed: add group option to set the repository gid. Default is root (#2747)...
r2416 ['--group', '-g', 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 ['--url', '-u', GetoptLong::REQUIRED_ARGUMENT],
Jean-Philippe Lang
Merged nbc branch @ r1812 (commit access permission and reposman improvements)....
r1812 ['--command' , '-c', GetoptLong::REQUIRED_ARGUMENT],
['--scm', GetoptLong::REQUIRED_ARGUMENT],
Nicolas Chuche
* add Redmine.pm to authenticate with mod_perl...
r903 ['--test', '-t', GetoptLong::NO_ARGUMENT],
Jean-Philippe Lang
Merged nbc branch @ r1812 (commit access permission and reposman improvements)....
r1812 ['--force', '-f', 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
Fixed: add group option to set the repository gid. Default is root (#2747)...
r2416 $svn_group = '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
Merged nbc branch @ r1812 (commit access permission and reposman improvements)....
r1812 $force = false
$scm = 'Subversion'
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826
Jean-Philippe Lang
reposman: change #log arguments....
r1873 def log(text, options={})
level = options[:level] || 0
Nicolas Chuche
bugfix...
r1858 puts text unless $quiet or level > $verbose
Jean-Philippe Lang
reposman: change #log arguments....
r1873 exit 1 if options[:exit]
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826 end
Nicolas Chuche
* reposman can create git repository with "--scm git" option...
r1864 def system_or_raise(command)
raise "\"#{command}\" failed" unless system command
end
module SCM
module Subversion
def self.create(path)
system_or_raise "svnadmin create #{path}"
end
end
module Git
def self.create(path)
Dir.mkdir path
Dir.chdir(path) do
system_or_raise "git --bare init --shared"
Jean-Philippe Lang
Slight change on git repository creation command....
r1874 system_or_raise "git update-server-info"
Nicolas Chuche
* reposman can create git repository with "--scm git" option...
r1864 end
end
end
end
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826 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;
Nicolas Chuche
Fixed: add group option to set the repository gid. Default is root (#2747)...
r2416 when '--group'; $svn_group = 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
reposman: change #log arguments....
r1873 when '--scm'; $scm = arg.dup.capitalize; log("Invalid SCM: #{$scm}", :exit => true) unless SUPPORTED_SCM.include?($scm)
Jean-Philippe Lang
Merged nbc branch @ r1812 (commit access permission and reposman improvements)....
r1812 when '--command'; $command = 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
Merged nbc branch @ r1812 (commit access permission and reposman improvements)....
r1812 when '--force'; $force = 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
Nicolas Chuche
* reposman can create git repository with "--scm git" option...
r1864 # Make sure command is overridden if SCM vendor is not handled internally (for the moment Subversion and Git)
if $command.nil?
begin
scm_module = SCM.const_get($scm)
rescue
Jean-Philippe Lang
reposman: change #log arguments....
r1873 log("Please use --command option to specify how to create a #{$scm} repository.", :exit => true)
Nicolas Chuche
* reposman can create git repository with "--scm git" option...
r1864 end
Jean-Philippe Lang
Merged nbc branch @ r1812 (commit access permission and reposman improvements)....
r1812 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)
Jean-Philippe Lang
reposman: change #log arguments....
r1873 log("directory '#{$repos_base}' doesn't exists", :exit => true)
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826 end
Jean-Philippe Lang
Replaces the repositories management SOAP API with a simple REST API....
r2374 begin
require 'activeresource'
rescue LoadError
log("This script requires activeresource.\nRun 'gem install activeresource' to install it.", :exit => true)
end
class Project < ActiveResource::Base; end
Jean-Philippe Lang
reposman: change #log arguments....
r1873 log("querying Redmine for projects...", :level => 1);
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826
$redmine_host.gsub!(/^/, "http://") unless $redmine_host.match("^https?://")
$redmine_host.gsub!(/\/$/, '')
Jean-Philippe Lang
Replaces the repositories management SOAP API with a simple REST API....
r2374 Project.site = "#{$redmine_host}/sys";
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826
begin
Jean-Philippe Lang
Replaces the repositories management SOAP API with a simple REST API....
r2374 # Get all active projects that have the Repository module enabled
projects = Project.find(:all)
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826 rescue => e
Jean-Philippe Lang
Replaces the repositories management SOAP API with a simple REST API....
r2374 log("Unable to connect to #{Project.site}: #{e}", :exit => true)
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826 end
if projects.nil?
Jean-Philippe Lang
reposman: change #log arguments....
r1873 log('no project found, perhaps you forgot to "Enable WS for repository management"', :exit => true)
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826 end
Jean-Philippe Lang
reposman: change #log arguments....
r1873 log("retrieved #{projects.size} projects", :level => 1)
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 def set_owner_and_rights(project, repos_path, &block)
if RUBY_PLATFORM =~ /mswin/
yield if block_given?
else
Nicolas Chuche
Fixed: add group option to set the repository gid. Default is root (#2747)...
r2416 uid, gid = Etc.getpwnam($svn_owner).uid, ($use_groupid ? Etc.getgrnam(project.identifier).gid : Etc.getgrnam($svn_group).gid)
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|
Jean-Philippe Lang
reposman: change #log arguments....
r1873 log("treating project #{project.name}", :level => 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
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
Make --command option usable on Windows....
r1875 repos_path = File.join($repos_base, project.identifier).gsub(File::SEPARATOR, File::ALT_SEPARATOR || File::SEPARATOR)
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
Jean-Philippe Lang
Merged nbc branch @ r1812 (commit access permission and reposman improvements)....
r1812 # if repository is already declared in redmine, we don't create
# unless user use -f with reposman
Jean-Philippe Lang
Replaces the repositories management SOAP API with a simple REST API....
r2374 if $force == false and project.respond_to?(:repository)
Jean-Philippe Lang
reposman: change #log arguments....
r1873 log("\trepository for project #{project.identifier} already exists in Redmine", :level => 1)
Jean-Philippe Lang
Merged nbc branch @ r1812 (commit access permission and reposman improvements)....
r1812 next
end
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
Nicolas Chuche
* reposman can create git repository with "--scm git" option...
r1864 if scm_module.nil?
system_or_raise "#{$command} #{repos_path}"
else
scm_module.create(repos_path)
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 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
Jean-Philippe Lang
Replaces the repositories management SOAP API with a simple REST API....
r2374 begin
project.post(:repository, :vendor => $scm, :repository => {:url => "#{$svn_url}#{project.identifier}"})
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("\trepository #{repos_path} registered in Redmine with url #{$svn_url}#{project.identifier}");
Jean-Philippe Lang
Replaces the repositories management SOAP API with a simple REST API....
r2374 rescue => e
log("\trepository #{repos_path} not registered in Redmine: #{e.message}");
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 end
end
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826 log("\trepository #{repos_path} created");
end
end