@@ -1,96 +1,12 | |||||
1 | #!/usr/bin/env ruby |
|
1 | #!/usr/bin/env ruby | |
2 |
|
2 | |||
3 | # == Synopsis |
|
3 | require 'optparse' | |
4 | # |
|
|||
5 | # reposman: manages your repositories with Redmine |
|
|||
6 | # |
|
|||
7 | # == Usage |
|
|||
8 | # |
|
|||
9 | # reposman [OPTIONS...] -s [DIR] -r [HOST] |
|
|||
10 | # |
|
|||
11 | # Examples: |
|
|||
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 |
|
|||
14 | # |
|
|||
15 | # == Arguments (mandatory) |
|
|||
16 | # |
|
|||
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: |
|
|||
19 | # -r redmine.example.net |
|
|||
20 | # -r http://redmine.example.net |
|
|||
21 | # -r https://example.net/redmine |
|
|||
22 | # -k, --key=KEY use KEY as the Redmine API key (you can use the |
|
|||
23 | # --key-file option as an alternative) |
|
|||
24 | # |
|
|||
25 | # == Options |
|
|||
26 | # |
|
|||
27 | # -o, --owner=OWNER owner of the repository. using the rails login |
|
|||
28 | # allow user to browse the repository within |
|
|||
29 | # Redmine even for private project. If you want to |
|
|||
30 | # share repositories through Redmine.pm, you need |
|
|||
31 | # to use the apache owner. |
|
|||
32 | # -g, --group=GROUP group of the repository. (default: root) |
|
|||
33 | # --scm=SCM the kind of SCM repository you want to create (and |
|
|||
34 | # register) in Redmine (default: Subversion). |
|
|||
35 | # reposman is able to create Git and Subversion |
|
|||
36 | # repositories. For all other kind, you must specify |
|
|||
37 | # a --command option |
|
|||
38 | # -u, --url=URL the base url Redmine will use to access your |
|
|||
39 | # repositories. This option is used to automatically |
|
|||
40 | # register the repositories in Redmine. The project |
|
|||
41 | # identifier will be appended to this url. Examples: |
|
|||
42 | # -u https://example.net/svn |
|
|||
43 | # -u file:///var/svn/ |
|
|||
44 | # if this option isn't set, reposman won't register |
|
|||
45 | # the repositories in Redmine |
|
|||
46 | # -c, --command=COMMAND use this command instead of "svnadmin create" to |
|
|||
47 | # create a repository. This option can be used to |
|
|||
48 | # create repositories other than subversion and git |
|
|||
49 | # kind. |
|
|||
50 | # This command override the default creation for git |
|
|||
51 | # and subversion. |
|
|||
52 | # -f, --force force repository creation even if the project |
|
|||
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) |
|
|||
57 | # -t, --test only show what should be done |
|
|||
58 | # -h, --help show help and exit |
|
|||
59 | # -v, --verbose verbose |
|
|||
60 | # -V, --version print version and exit |
|
|||
61 | # -q, --quiet no log |
|
|||
62 | # |
|
|||
63 | # == References |
|
|||
64 | # |
|
|||
65 | # You can find more information on the redmine's wiki : http://www.redmine.org/wiki/redmine/HowTos |
|
|||
66 |
|
||||
67 |
|
||||
68 | require 'getoptlong' |
|
|||
69 | require 'rdoc/usage' |
|
|||
70 | require 'find' |
|
4 | require 'find' | |
71 | require 'etc' |
|
5 | require 'etc' | |
72 |
|
6 | |||
73 |
Version = "1. |
|
7 | Version = "1.4" | |
74 | SUPPORTED_SCM = %w( Subversion Darcs Mercurial Bazaar Git Filesystem ) |
|
8 | SUPPORTED_SCM = %w( Subversion Darcs Mercurial Bazaar Git Filesystem ) | |
75 |
|
9 | |||
76 | opts = GetoptLong.new( |
|
|||
77 | ['--svn-dir', '-s', GetoptLong::REQUIRED_ARGUMENT], |
|
|||
78 | ['--redmine-host', '-r', GetoptLong::REQUIRED_ARGUMENT], |
|
|||
79 | ['--key', '-k', GetoptLong::REQUIRED_ARGUMENT], |
|
|||
80 | ['--key-file', GetoptLong::REQUIRED_ARGUMENT], |
|
|||
81 | ['--owner', '-o', GetoptLong::REQUIRED_ARGUMENT], |
|
|||
82 | ['--group', '-g', GetoptLong::REQUIRED_ARGUMENT], |
|
|||
83 | ['--url', '-u', GetoptLong::REQUIRED_ARGUMENT], |
|
|||
84 | ['--command' , '-c', GetoptLong::REQUIRED_ARGUMENT], |
|
|||
85 | ['--scm', GetoptLong::REQUIRED_ARGUMENT], |
|
|||
86 | ['--test', '-t', GetoptLong::NO_ARGUMENT], |
|
|||
87 | ['--force', '-f', GetoptLong::NO_ARGUMENT], |
|
|||
88 | ['--verbose', '-v', GetoptLong::NO_ARGUMENT], |
|
|||
89 | ['--version', '-V', GetoptLong::NO_ARGUMENT], |
|
|||
90 | ['--help' , '-h', GetoptLong::NO_ARGUMENT], |
|
|||
91 | ['--quiet' , '-q', GetoptLong::NO_ARGUMENT] |
|
|||
92 | ) |
|
|||
93 |
|
||||
94 | $verbose = 0 |
|
10 | $verbose = 0 | |
95 | $quiet = false |
|
11 | $quiet = false | |
96 | $redmine_host = '' |
|
12 | $redmine_host = '' | |
@@ -133,35 +49,83 module SCM | |||||
133 |
|
49 | |||
134 | end |
|
50 | end | |
135 |
|
51 | |||
|
52 | def read_key_from_file(filename) | |||
136 | begin |
|
53 | begin | |
137 | opts.each do |opt, arg| |
|
54 | $api_key = File.read(filename).strip | |
138 | case opt |
|
|||
139 | when '--svn-dir'; $repos_base = arg.dup |
|
|||
140 | when '--redmine-host'; $redmine_host = arg.dup |
|
|||
141 | when '--key'; $api_key = arg.dup |
|
|||
142 | when '--key-file' |
|
|||
143 | begin |
|
|||
144 | $api_key = File.read(arg).strip |
|
|||
145 |
|
|
55 | rescue Exception => e | |
146 |
|
|
56 | $stderr.puts "Unable to read the key from #{filename}: #{e.message}" | |
147 |
|
|
57 | exit 1 | |
148 |
|
|
58 | end | |
149 | when '--owner'; $svn_owner = arg.dup; $use_groupid = false; |
|
|||
150 | when '--group'; $svn_group = arg.dup; $use_groupid = false; |
|
|||
151 | when '--url'; $svn_url = arg.dup |
|
|||
152 | when '--scm'; $scm = arg.dup.capitalize; log("Invalid SCM: #{$scm}", :exit => true) unless SUPPORTED_SCM.include?($scm) |
|
|||
153 | when '--command'; $command = arg.dup |
|
|||
154 | when '--verbose'; $verbose += 1 |
|
|||
155 | when '--test'; $test = true |
|
|||
156 | when '--force'; $force = true |
|
|||
157 | when '--version'; puts Version; exit |
|
|||
158 | when '--help'; RDoc::usage |
|
|||
159 | when '--quiet'; $quiet = true |
|
|||
160 | end |
|
|||
161 |
|
|
59 | end | |
162 | rescue |
|
60 | ||
|
61 | def set_scm(scm) | |||
|
62 | $scm = v.capitalize | |||
|
63 | unless SUPPORTED_SCM.include?($scm) | |||
|
64 | log("Invalid SCM: #{$scm}\nValid SCM are: #{SUPPORTED_SCM.join(', ')}", :exit => true) | |||
|
65 | end | |||
|
66 | end | |||
|
67 | ||||
|
68 | optparse = OptionParser.new do |opts| | |||
|
69 | opts.banner = "Usage: reposman.rb [OPTIONS...] -s [DIR] -r [HOST] -k [KEY]" | |||
|
70 | opts.separator("") | |||
|
71 | ||||
|
72 | opts.separator("Required arguments:") | |||
|
73 | opts.on("-s", "--svn-dir", "use DIR as base directory for svn repositories") {|v| $repos_base = v} | |||
|
74 | opts.on("-r", "--redmine-host", "assume Redmine is hosted on HOST. Examples:", " -r redmine.example.net", " -r http://redmine.example.net", " -r https://redmine.example.net") {|v| $redmine_host = v} | |||
|
75 | opts.on("-k", "--key KEY", "use KEY as the Redmine API key", "(you can use --key-file option as an alternative)") {|v| $api_key = v} | |||
|
76 | ||||
|
77 | opts.separator("") | |||
|
78 | opts.separator("Options:") | |||
|
79 | opts.on("-o", "--owner OWNER", "owner of the repository. using the rails login", | |||
|
80 | "allows users to browse the repository within", | |||
|
81 | "Redmine even for private projects. If you want to", | |||
|
82 | "share repositories through Redmine.pm, you need", | |||
|
83 | "to use the apache owner.") {|v| $svn_owner = v; $use_groupid = false} | |||
|
84 | opts.on("-g", "--group GROUP", "group of the repository (default: root)") {|v| $svn_group = v; $use_groupid = false} | |||
|
85 | opts.on("-u", "--url URL", "the base url Redmine will use to access your", | |||
|
86 | "repositories. This option is used to register", | |||
|
87 | "the repositories in Redmine automatically. The", | |||
|
88 | "project identifier will be appended to this url.", | |||
|
89 | "Examples:", | |||
|
90 | " -u https://example.net/svn", | |||
|
91 | " -u file:///var/svn/", | |||
|
92 | "if this option isn't set, reposman won't register", | |||
|
93 | "the repositories in Redmine") {|v| $svn_url = v} | |||
|
94 | opts.on( "--scm SCM", "the kind of SCM repository you want to create", | |||
|
95 | "(and register) in Redmine (default: Subversion).", | |||
|
96 | "reposman is able to create Git and Subversion", | |||
|
97 | "repositories.", | |||
|
98 | "For all other kind, you must specify a --command", | |||
|
99 | "option") {|v| set_scm(v)} | |||
|
100 | opts.on("-c", "--command COMMAND", "use this command instead of `svnadmin create` to", | |||
|
101 | "create a repository. This option can be used to", | |||
|
102 | "create repositories other than subversion and git", | |||
|
103 | "kind.", | |||
|
104 | "This command override the default creation for", | |||
|
105 | "git and subversion.") {|v| $command = v} | |||
|
106 | opts.on( "--key-file FILE", "path to a file that contains the Redmine API key", | |||
|
107 | "(use this option instead of --key if you don't", | |||
|
108 | "want the key to appear in the command line)") {|v| read_key_from_file(v)} | |||
|
109 | opts.on("-t", "--test", "only show what should be done") {$test = true} | |||
|
110 | opts.on("-f", "--force", "force repository creation even if the project", "repository is already declared in Redmine") {$force = true} | |||
|
111 | opts.on("-v", "--verbose", "verbose") {$verbose += 1} | |||
|
112 | opts.on("-V", "--version", "show version and exit") {puts Version; exit} | |||
|
113 | opts.on("-h", "--help", "show help and exit") do | |||
|
114 | puts opts | |||
163 | exit 1 |
|
115 | exit 1 | |
164 | end |
|
116 | end | |
|
117 | opts.on("-q", "--quiet", "no log") {$quiet = true} | |||
|
118 | opts.separator("") | |||
|
119 | ||||
|
120 | opts.separator("Examples:") | |||
|
121 | opts.separator(" reposman.rb --svn-dir=/var/svn --redmine-host=redmine.host") | |||
|
122 | opts.separator(" reposman.rb -s /var/git -r redmine.host -u http://git.host --scm git") | |||
|
123 | opts.separator("") | |||
|
124 | opts.separator("You can find more information on the redmine's wiki:\nhttp://www.redmine.org/projects/redmine/wiki/HowTos") | |||
|
125 | ||||
|
126 | opts.summary_width = 25 | |||
|
127 | end | |||
|
128 | optparse.parse! | |||
165 |
|
129 | |||
166 | if $test |
|
130 | if $test | |
167 | log("running in test mode") |
|
131 | log("running in test mode") | |
@@ -179,7 +143,8 end | |||||
179 | $svn_url += "/" if $svn_url and not $svn_url.match(/\/$/) |
|
143 | $svn_url += "/" if $svn_url and not $svn_url.match(/\/$/) | |
180 |
|
144 | |||
181 | if ($redmine_host.empty? or $repos_base.empty?) |
|
145 | if ($redmine_host.empty? or $repos_base.empty?) | |
182 | RDoc::usage |
|
146 | puts "Some arguments are missing. Use reposman.rb --help for getting help." | |
|
147 | exit 1 | |||
183 | end |
|
148 | end | |
184 |
|
149 | |||
185 | unless File.directory?($repos_base) |
|
150 | unless File.directory?($repos_base) |
General Comments 0
You need to be logged in to leave comments.
Login now