comparison extra/svn/reposman.rb @ 909:cbb26bc654de redmine-1.3

Update to Redmine 1.3-stable branch (Redmine SVN rev 8964)
author Chris Cannam
date Fri, 24 Feb 2012 19:09:32 +0000
parents cbce1fd3b1b7
children 5e80956cc792 433d4f72a19b
comparison
equal deleted inserted replaced
908:c6c2cbd0afee 909:cbb26bc654de
17 # -s, --svn-dir=DIR use DIR as base directory for svn repositories 17 # -s, --svn-dir=DIR use DIR as base directory for svn repositories
18 # -r, --redmine-host=HOST assume Redmine is hosted on HOST. Examples: 18 # -r, --redmine-host=HOST assume Redmine is hosted on HOST. Examples:
19 # -r redmine.example.net 19 # -r redmine.example.net
20 # -r http://redmine.example.net 20 # -r http://redmine.example.net
21 # -r https://example.net/redmine 21 # -r https://example.net/redmine
22 # -k, --key=KEY use KEY as the Redmine API key 22 # -k, --key=KEY use KEY as the Redmine API key (you can use the
23 # --key-file option as an alternative)
23 # 24 #
24 # == Options 25 # == Options
25 # 26 #
26 # -o, --owner=OWNER owner of the repository. using the rails login 27 # -o, --owner=OWNER owner of the repository. using the rails login
27 # allow user to browse the repository within 28 # allow user to browse the repository within
48 # kind. 49 # kind.
49 # This command override the default creation for git 50 # This command override the default creation for git
50 # and subversion. 51 # and subversion.
51 # -f, --force force repository creation even if the project 52 # -f, --force force repository creation even if the project
52 # repository is already declared in Redmine 53 # repository is already declared in Redmine
54 # --key-file=PATH path to a file that contains the Redmine API key
55 # (use this option instead of --key if you don't
56 # the key to appear in the command line)
53 # -t, --test only show what should be done 57 # -t, --test only show what should be done
54 # -h, --help show help and exit 58 # -h, --help show help and exit
55 # -v, --verbose verbose 59 # -v, --verbose verbose
56 # -V, --version print version and exit 60 # -V, --version print version and exit
57 # -q, --quiet no log 61 # -q, --quiet no log
71 75
72 opts = GetoptLong.new( 76 opts = GetoptLong.new(
73 ['--svn-dir', '-s', GetoptLong::REQUIRED_ARGUMENT], 77 ['--svn-dir', '-s', GetoptLong::REQUIRED_ARGUMENT],
74 ['--redmine-host', '-r', GetoptLong::REQUIRED_ARGUMENT], 78 ['--redmine-host', '-r', GetoptLong::REQUIRED_ARGUMENT],
75 ['--key', '-k', GetoptLong::REQUIRED_ARGUMENT], 79 ['--key', '-k', GetoptLong::REQUIRED_ARGUMENT],
80 ['--key-file', GetoptLong::REQUIRED_ARGUMENT],
76 ['--owner', '-o', GetoptLong::REQUIRED_ARGUMENT], 81 ['--owner', '-o', GetoptLong::REQUIRED_ARGUMENT],
77 ['--group', '-g', GetoptLong::REQUIRED_ARGUMENT], 82 ['--group', '-g', GetoptLong::REQUIRED_ARGUMENT],
78 ['--url', '-u', GetoptLong::REQUIRED_ARGUMENT], 83 ['--url', '-u', GetoptLong::REQUIRED_ARGUMENT],
79 ['--command' , '-c', GetoptLong::REQUIRED_ARGUMENT], 84 ['--command' , '-c', GetoptLong::REQUIRED_ARGUMENT],
80 ['--scm', GetoptLong::REQUIRED_ARGUMENT], 85 ['--scm', GetoptLong::REQUIRED_ARGUMENT],
132 opts.each do |opt, arg| 137 opts.each do |opt, arg|
133 case opt 138 case opt
134 when '--svn-dir'; $repos_base = arg.dup 139 when '--svn-dir'; $repos_base = arg.dup
135 when '--redmine-host'; $redmine_host = arg.dup 140 when '--redmine-host'; $redmine_host = arg.dup
136 when '--key'; $api_key = arg.dup 141 when '--key'; $api_key = arg.dup
142 when '--key-file'
143 begin
144 $api_key = File.read(arg).strip
145 rescue Exception => e
146 $stderr.puts "Unable to read the key from #{arg}: #{e.message}"
147 exit 1
148 end
137 when '--owner'; $svn_owner = arg.dup; $use_groupid = false; 149 when '--owner'; $svn_owner = arg.dup; $use_groupid = false;
138 when '--group'; $svn_group = arg.dup; $use_groupid = false; 150 when '--group'; $svn_group = arg.dup; $use_groupid = false;
139 when '--url'; $svn_url = arg.dup 151 when '--url'; $svn_url = arg.dup
140 when '--scm'; $scm = arg.dup.capitalize; log("Invalid SCM: #{$scm}", :exit => true) unless SUPPORTED_SCM.include?($scm) 152 when '--scm'; $scm = arg.dup.capitalize; log("Invalid SCM: #{$scm}", :exit => true) unless SUPPORTED_SCM.include?($scm)
141 when '--command'; $command = arg.dup 153 when '--command'; $command = arg.dup
180 log("This script requires activeresource.\nRun 'gem install activeresource' to install it.", :exit => true) 192 log("This script requires activeresource.\nRun 'gem install activeresource' to install it.", :exit => true)
181 end 193 end
182 194
183 class Project < ActiveResource::Base 195 class Project < ActiveResource::Base
184 self.headers["User-agent"] = "Redmine repository manager/#{Version}" 196 self.headers["User-agent"] = "Redmine repository manager/#{Version}"
197 self.format = :xml
185 end 198 end
186 199
187 log("querying Redmine for projects...", :level => 1); 200 log("querying Redmine for projects...", :level => 1);
188 201
189 $redmine_host.gsub!(/^/, "http://") unless $redmine_host.match("^https?://") 202 $redmine_host.gsub!(/^/, "http://") unless $redmine_host.match("^https?://")
192 Project.site = "#{$redmine_host}/sys"; 205 Project.site = "#{$redmine_host}/sys";
193 206
194 begin 207 begin
195 # Get all active projects that have the Repository module enabled 208 # Get all active projects that have the Repository module enabled
196 projects = Project.find(:all, :params => {:key => $api_key}) 209 projects = Project.find(:all, :params => {:key => $api_key})
210 rescue ActiveResource::ForbiddenAccess
211 log("Request was denied by your Redmine server. Make sure that 'WS for repository management' is enabled in application settings and that you provided the correct API key.")
197 rescue => e 212 rescue => e
198 log("Unable to connect to #{Project.site}: #{e}", :exit => true) 213 log("Unable to connect to #{Project.site}: #{e}", :exit => true)
199 end 214 end
200 215
201 if projects.nil? 216 if projects.nil?
202 log('no project found, perhaps you forgot to "Enable WS for repository management"', :exit => true) 217 log('No project found, perhaps you forgot to "Enable WS for repository management"', :exit => true)
203 end 218 end
204 219
205 log("retrieved #{projects.size} projects", :level => 1) 220 log("retrieved #{projects.size} projects", :level => 1)
206 221
207 def set_owner_and_rights(project, repos_path, &block) 222 def set_owner_and_rights(project, repos_path, &block)