15 |
15 |
# == Arguments (mandatory)
|
16 |
16 |
#
|
17 |
17 |
# -s, --svn-dir=DIR use DIR as base directory for svn repositories
|
|
18 |
# -a, --archive-dir=DIR Archive repositories to DIR before deleting them
|
18 |
19 |
# -r, --redmine-host=HOST assume Redmine is hosted on HOST. Examples:
|
19 |
20 |
# -r redmine.example.net
|
20 |
21 |
# -r http://redmine.example.net
|
... | ... | |
29 |
30 |
# share repositories through Redmine.pm, you need
|
30 |
31 |
# to use the apache owner.
|
31 |
32 |
# -g, --group=GROUP group of the repository. (default: root)
|
|
33 |
# --with-tar=/path/to/tar Path to the tar command (default: /bin/tar)
|
32 |
34 |
# --scm=SCM the kind of SCM repository you want to create (and
|
33 |
35 |
# register) in Redmine (default: Subversion).
|
34 |
36 |
# reposman is able to create Git and Subversion
|
... | ... | |
50 |
52 |
# and subversion.
|
51 |
53 |
# -f, --force force repository creation even if the project
|
52 |
54 |
# repository is already declared in Redmine
|
|
55 |
# -d, --delete Delete repositories that doesn't exist in redmine anymore
|
53 |
56 |
# -t, --test only show what should be done
|
54 |
57 |
# -h, --help show help and exit
|
55 |
58 |
# -v, --verbose verbose
|
... | ... | |
65 |
68 |
require 'rdoc/usage'
|
66 |
69 |
require 'find'
|
67 |
70 |
require 'etc'
|
|
71 |
require 'fileutils'
|
68 |
72 |
|
69 |
73 |
Version = "1.3"
|
70 |
74 |
SUPPORTED_SCM = %w( Subversion Darcs Mercurial Bazaar Git Filesystem )
|
... | ... | |
80 |
84 |
['--scm', GetoptLong::REQUIRED_ARGUMENT],
|
81 |
85 |
['--test', '-t', GetoptLong::NO_ARGUMENT],
|
82 |
86 |
['--force', '-f', GetoptLong::NO_ARGUMENT],
|
|
87 |
['--delete', '-d', GetoptLong::NO_ARGUMENT],
|
83 |
88 |
['--verbose', '-v', GetoptLong::NO_ARGUMENT],
|
84 |
89 |
['--version', '-V', GetoptLong::NO_ARGUMENT],
|
85 |
90 |
['--help' , '-h', GetoptLong::NO_ARGUMENT],
|
86 |
|
['--quiet' , '-q', GetoptLong::NO_ARGUMENT]
|
|
91 |
['--archive-dir', '-a', GetoptLong::REQUIRED_ARGUMENT],
|
|
92 |
['--with-tar', GetoptLong::REQUIRED_ARGUMENT],
|
|
93 |
['--quiet' , '-q', GetoptLong::NO_ARGUMENT]
|
87 |
94 |
)
|
88 |
95 |
|
89 |
96 |
$verbose = 0
|
... | ... | |
96 |
103 |
$svn_url = false
|
97 |
104 |
$test = false
|
98 |
105 |
$force = false
|
|
106 |
$delete = false
|
|
107 |
$archive = ''
|
99 |
108 |
$scm = 'Subversion'
|
|
109 |
$tarcmd = '/bin/tar'
|
100 |
110 |
|
101 |
111 |
def log(text, options={})
|
102 |
112 |
level = options[:level] || 0
|
... | ... | |
132 |
142 |
opts.each do |opt, arg|
|
133 |
143 |
case opt
|
134 |
144 |
when '--svn-dir'; $repos_base = arg.dup
|
|
145 |
when '--archive-dir'; $archive = arg.dup
|
135 |
146 |
when '--redmine-host'; $redmine_host = arg.dup
|
136 |
147 |
when '--key'; $api_key = arg.dup
|
137 |
148 |
when '--owner'; $svn_owner = arg.dup; $use_groupid = false;
|
138 |
149 |
when '--group'; $svn_group = arg.dup; $use_groupid = false;
|
139 |
150 |
when '--url'; $svn_url = arg.dup
|
|
151 |
when '--with-tar'; $tarcmd = arg.dup
|
140 |
152 |
when '--scm'; $scm = arg.dup.capitalize; log("Invalid SCM: #{$scm}", :exit => true) unless SUPPORTED_SCM.include?($scm)
|
141 |
153 |
when '--command'; $command = arg.dup
|
142 |
154 |
when '--verbose'; $verbose += 1
|
143 |
155 |
when '--test'; $test = true
|
144 |
156 |
when '--force'; $force = true
|
|
157 |
when '--delete'; $delete = true
|
145 |
158 |
when '--version'; puts Version; exit
|
146 |
159 |
when '--help'; RDoc::usage
|
147 |
160 |
when '--quiet'; $quiet = true
|
... | ... | |
230 |
243 |
(RUBY_PLATFORM =~ /(:?mswin|mingw)/) || (RUBY_PLATFORM == 'java' && (ENV['OS'] || ENV['os']) =~ /windows/i)
|
231 |
244 |
end
|
232 |
245 |
|
|
246 |
if $delete == true
|
|
247 |
log("checking for svn directories to delete", :level => 1)
|
|
248 |
svnprojects = Dir.glob("#{$repos_base}/*/")
|
|
249 |
svnprojects.each do |svnproject|
|
|
250 |
matches = svnproject.match(/\/([a-z0-9-]+)\/$/)
|
|
251 |
svnname = matches[1]
|
|
252 |
|
|
253 |
if svnname.match(/^\./)
|
|
254 |
next
|
|
255 |
end
|
|
256 |
|
|
257 |
$found = false
|
|
258 |
projects.each do |project|
|
|
259 |
if project.identifier.match(svnname)
|
|
260 |
$found = true
|
|
261 |
end
|
|
262 |
end
|
|
263 |
|
|
264 |
if $found == false
|
|
265 |
log("\tsvn project #{svnproject} doesn't exist in redmine anymore")
|
|
266 |
if (!($archive.empty?))
|
|
267 |
time = Time.new
|
|
268 |
$dateoftheday = time.strftime("%Y-%m-%d")
|
|
269 |
$prjname = File.basename(svnproject)
|
|
270 |
log("\tarchiving project #{$prjname} to #{$archive}")
|
|
271 |
if $test == false
|
|
272 |
if File.exists?($archive) && File.directory?($archive)
|
|
273 |
$archivename=$archive+"/"+$prjname+"-"+$dateoftheday+".tgz"
|
|
274 |
$archivesrc="./"+$prjname
|
|
275 |
system("#{$tarcmd} zcf #{$archivename} -C #{$repos_base} #{$archivesrc}")
|
|
276 |
else
|
|
277 |
log("\tERROR : #{$archive} does not exists or is not a valid directory")
|
|
278 |
end
|
|
279 |
end
|
|
280 |
end
|
|
281 |
log("\tdeleting svn project #{svnproject}")
|
|
282 |
if $test == false
|
|
283 |
FileUtils.rm_r(svnproject)
|
|
284 |
end
|
|
285 |
end
|
|
286 |
end
|
|
287 |
end
|
|
288 |
|
233 |
289 |
projects.each do |project|
|
234 |
290 |
log("treating project #{project.name}", :level => 1)
|
235 |
291 |
|