gitorious-munin-plugins 0.9.12 → 0.9.13

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,9 +1,12 @@
1
1
  #!/usr/bin/env ruby
2
2
  require "gitorious-munin-plugins"
3
+ require "gitorious-munin-plugins/version"
3
4
  require "gitorious-munin-plugins/database"
4
5
  require "gitorious-munin-plugins/cli"
5
6
  require "gitorious-munin-plugins/plugin"
7
+ require "gitorious-munin-plugins/usage_plugin"
6
8
  require "term/ansicolor"
9
+ require "trollop"
7
10
 
8
11
 
9
12
 
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
8
8
  s.email = ["marius@gitorious.com"]
9
9
  s.homepage = "http://gitorious.org/gitorious/gitorious-munin-plugins"
10
10
  s.summary = "Gitorious Munin Plugins"
11
- s.description = "Various binaries that can be used as Munin plugins for a Gitorious server"
11
+ s.description = "A binary that can be used as Munin plugins for a Gitorious server by linking to it under different names."
12
12
 
13
13
  s.files = `git ls-files`.split("\n") - [".gitignore", "readme.org"]
14
14
  s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
@@ -16,4 +16,5 @@ Gem::Specification.new do |s|
16
16
 
17
17
  s.add_dependency "mysql", "~> 2.8"
18
18
  s.add_dependency "term-ansicolor", "~> 1.0"
19
+ s.add_dependency "trollop", "~> 2.0"
19
20
  end
@@ -11,29 +11,14 @@ module GitoriousMuninPlugins
11
11
  if plugins.any? {|plugin| plugin.named?(called_as)}
12
12
  load_plugin(called_as)
13
13
  else
14
- display_usage
14
+ UsagePlugin.new(plugins).run
15
15
  end
16
16
  end
17
17
 
18
- def display_usage
19
- msg = [Term::ANSIColor.bold { "Munin plugins for Gitorious, symlink to me in /etc/munin/plugins/"} ]
20
- msg << ""
21
- msg << "I may be called by these names:"
22
- plugins.each do |p|
23
- msg << "- #{p.description}"
24
- end
25
- msg << ""
26
-
27
- fail_with_message(msg.join("\n"))
28
- end
29
-
30
- def fail_with_message(message)
31
- puts message
32
- exit 1
33
- end
34
18
 
35
19
  def load_plugin(name)
36
20
  load Plugin.root.realpath + "#{name}.rb"
37
21
  end
38
22
  end
23
+
39
24
  end
@@ -12,6 +12,34 @@ module GitoriousMuninPlugins
12
12
  Pathname(File.dirname(__FILE__)) + "plugins"
13
13
  end
14
14
 
15
+ # The binary, used as a target for Munin symlinks
16
+ def binary
17
+ (self.class.root + "../../../bin/gitorious-munin-plugin").realpath
18
+ end
19
+
20
+ # Where the symlink should be placed
21
+ def target
22
+ Pathname("/etc/munin/plugins/#{name}")
23
+ end
24
+
25
+ def install!
26
+ if target.exist?
27
+ puts "#{target} exists, ignoring"
28
+ else
29
+ puts "Installing #{target}"
30
+ target.make_symlink(binary)
31
+ end
32
+ end
33
+
34
+ def uninstall!
35
+ if target.exist?
36
+ puts "Deleting #{target}"
37
+ target.delete
38
+ else
39
+ puts "#{target} exists"
40
+ end
41
+ end
42
+
15
43
  attr_reader :name
16
44
  def initialize(name)
17
45
  @name = name
@@ -0,0 +1,66 @@
1
+ module GitoriousMuninPlugins
2
+ class UsagePlugin
3
+ def initialize(known_plugins)
4
+ @known_plugins = known_plugins
5
+ end
6
+
7
+ def run
8
+ global_options = Trollop::options do
9
+ version "#{GitoriousMuninPlugins::VERSION} (c) 2012 Gitorious AS."
10
+ banner <<-EOS
11
+ Munin plugins for Gitorious
12
+
13
+ Usage:
14
+ gitorious-munin-plugins [options]
15
+ where [options] are:
16
+ EOS
17
+ opt :status, "List install status of plugins"
18
+ opt :install, "Install PACKAGE1 PACKAGE2"
19
+ opt :uninstall, "Uninstall PACKAGE1 PACKAGE2 "
20
+ end
21
+
22
+ if global_options[:status_given]
23
+ display_install_status
24
+ elsif global_options[:install_given]
25
+ install_plugins(ARGV)
26
+ elsif global_options[:uninstall_given]
27
+ uninstall_plugins(ARGV)
28
+ end
29
+ end
30
+
31
+ def install_plugins(plugins)
32
+ plugins.each do |p|
33
+ if plugin = @known_plugins.detect {|_p| _p.named?(p)}
34
+ plugin.install!
35
+ else
36
+ puts "Ignoring #{p}"
37
+ end
38
+ end
39
+ end
40
+
41
+ def uninstall_plugins(plugins)
42
+ plugins.each do |p|
43
+ if plugin = @known_plugins.detect {|_p| _p.named?(p)}
44
+ plugin.uninstall!
45
+ else
46
+ puts "Ignoring #{p}"
47
+ end
48
+ end
49
+ end
50
+
51
+ def display_install_status
52
+ msg = [Term::ANSIColor.bold { "These plugins are available"} ]
53
+ @known_plugins.each do |p|
54
+ msg << "- #{p.description}"
55
+ end
56
+ msg << ""
57
+
58
+ fail_with_message(msg.join("\n"))
59
+ end
60
+
61
+ def fail_with_message(message)
62
+ puts message
63
+ exit 1
64
+ end
65
+ end
66
+ end
@@ -1,3 +1,3 @@
1
1
  module GitoriousMuninPlugins
2
- VERSION = "0.9.12"
2
+ VERSION = "0.9.13"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitorious-munin-plugins
3
3
  version: !ruby/object:Gem::Version
4
- hash: 35
4
+ hash: 33
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 12
10
- version: 0.9.12
9
+ - 13
10
+ version: 0.9.13
11
11
  platform: ruby
12
12
  authors:
13
13
  - Marius Mathiesen
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-10-31 00:00:00 +01:00
18
+ date: 2012-11-01 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -48,7 +48,22 @@ dependencies:
48
48
  version: "1.0"
49
49
  type: :runtime
50
50
  version_requirements: *id002
51
- description: Various binaries that can be used as Munin plugins for a Gitorious server
51
+ - !ruby/object:Gem::Dependency
52
+ name: trollop
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ~>
58
+ - !ruby/object:Gem::Version
59
+ hash: 3
60
+ segments:
61
+ - 2
62
+ - 0
63
+ version: "2.0"
64
+ type: :runtime
65
+ version_requirements: *id003
66
+ description: A binary that can be used as Munin plugins for a Gitorious server by linking to it under different names.
52
67
  email:
53
68
  - marius@gitorious.com
54
69
  executables:
@@ -66,6 +81,7 @@ files:
66
81
  - lib/gitorious-munin-plugins/plugin.rb
67
82
  - lib/gitorious-munin-plugins/plugins/gitorious_ssh_keys.rb
68
83
  - lib/gitorious-munin-plugins/plugins/gitorious_users.rb
84
+ - lib/gitorious-munin-plugins/usage_plugin.rb
69
85
  - lib/gitorious-munin-plugins/version.rb
70
86
  has_rdoc: true
71
87
  homepage: http://gitorious.org/gitorious/gitorious-munin-plugins