automateit 0.71006 → 0.71012

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig CHANGED
Binary file
@@ -1,3 +1,15 @@
1
+ 0.71012:
2
+ Date: Fri, 12 Oct 2007 03:54:30 -0700
3
+ Desc:
4
+ - (%) Fixed #touch, it worked fine but was corrupting log output
5
+ - (%) Fixed AccountManager::Linux, it now only runs when the OS detected is Linux.
6
+ - Added PlatformManager::SunOS.
7
+ - Added AddressManager::SunOS.
8
+ - Improved #render, added default :backup option to save files before overwriting them.
9
+ - Improved #backup, added :quiet option to prevent output.
10
+ - Improved #chperm, it now displays the exact changes made rather than approximations.
11
+ - Improved ServiceManager::SysV spec to validate :wait and :pause options with safe mocks.
12
+
1
13
  0.71006:
2
14
  Date: Sat, 06 Oct 2007 17:55:37 -0700
3
15
  Desc:
data/Rakefile CHANGED
@@ -97,13 +97,18 @@ task :loclines do
97
97
  if path.match(/(\bbin\b|.*\.(env|pl|py|rb|rake|java|sql|ftl|jsp|xml|properties|css|rcss|html|rhtml|erb|po|haml|sass)$)/)
98
98
  data = File.read(path)
99
99
  bytes += data.size
100
- lines += data.scan(/^.+$/).size
100
+ ### lines += data.scan(/^.*\w.*$/).size # Skip spaces
101
+ lines += data.scan(/^\s*(?!#)\w.*$/).size # Skip blanks and comments
101
102
  end
102
103
  end
103
104
  puts "Lines: "+lines.commify
104
105
  puts "Bytes: "+bytes.commify
105
106
  end
106
107
 
108
+ task :loccount do
109
+ sh ""
110
+ end
111
+
107
112
  desc "Display the lines of code changed in the repository"
108
113
  task :locdiff do
109
114
  if File.directory?(".hg")
data/TODO.txt CHANGED
@@ -2,6 +2,16 @@ KEY: Important? Urgent? Easy? 1=yes, 0=no
2
2
 
3
3
  #===[ App ]=============================================================
4
4
 
5
+ f=finished
6
+ d=disabled
7
+
8
+ Solaris 10
9
+ f Create PlatformManager::SunOS
10
+ d Create AccountManager::SunOS and prevent ::Linux from being used because it has the same commands but with different args
11
+ - Create ServiceManager::SMF
12
+ - Create PackageManager::Blastwave
13
+ - Create PackageManager::SunPkg
14
+
5
15
  100 Shell -- Expand glob patterns, e.g. chown_R(500, 500, "*")
6
16
 
7
17
  100 Edit -- Display summary of edits, return with :details as [rv, list]
@@ -9,12 +19,10 @@ KEY: Important? Urgent? Easy? 1=yes, 0=no
9
19
  100 Interpreter#invoke and HelpfulERB -- Extract error context code into class
10
20
 
11
21
  000 Shell#chperm -- With symbolic mode, wrap `chmod -v` as temporary workaround?
12
- 000 Changes -- Write parser and new format so I can use "#" symbol
13
22
  000 FreeBSD -- Write driver for PackageManager::Ports
14
23
  000 Darwin -- Write drivers, e.g. PackageManager for Fink, MacPorts, Pkgsrc
15
24
 
16
25
  ??? Shell -- Return false or list, never single item?
17
- ??? Shell -- Extract FileManager? change docs
18
26
  ??? Driver -- How to determine if a manager or driver method is available? Manager#available?, Manager#available and Driver#suitable? only say if it should be a default.
19
27
 
20
28
  #===[ Web ]=============================================================
@@ -3,8 +3,10 @@
3
3
  # A Linux-specific driver for the AccountManager.
4
4
  class ::AutomateIt::AccountManager::Linux < ::AutomateIt::AccountManager::Portable
5
5
  depends_on \
6
- :programs => %w(useradd usermod userdel groupadd groupmod groupdel),
7
- :callbacks => [lambda{AutomateIt::AccountManager::Portable.has_etc?}]
6
+ :programs => %w(uname useradd usermod userdel groupadd groupmod groupdel),
7
+ :callbacks => [lambda{
8
+ `uname -s`.match(/linux/i) && AutomateIt::AccountManager::Portable.has_etc?
9
+ }]
8
10
 
9
11
  def suitability(method, *args) # :nodoc:
10
12
  # Level must be higher than Portable
@@ -76,90 +76,10 @@ class AutomateIt::AddressManager < AutomateIt::Plugin::Manager
76
76
  # hostnames_for("kagami")
77
77
  # => ["kagami"]
78
78
  def hostnames_for(hostname) dispatch(hostname) end
79
-
80
- # Convert a mask to a CIDR.
81
- #
82
- # Example:
83
- # mask_to_cidr("255.255.255.0") # => 24
84
- def mask_to_cidr(mask) dispatch(mask) end
85
-
86
- # Convert CIDR to mask.
87
- #
88
- # Example:
89
- # cidr_to_mask(24) # => "255.255.255.0"
90
- def cidr_to_mask(cidr) dispatch(cidr) end
91
-
92
- # Convert a decimal number to binary notation.
93
- #
94
- # Example:
95
- # dec2bin(255) # => "11111111"
96
- def dec2bin(n) dispatch(n) end
97
-
98
- # Convert a binary number to decimal.
99
- #
100
- # Example:
101
- # bin2dec("11111111") # => 255
102
- def bin2dec(s) dispatch(s) end
103
- end
104
-
105
- # == AddressManager::BaseDriver
106
- #
107
- # Base class for all AddressManager drivers.
108
- class AutomateIt::AddressManager::BaseDriver< AutomateIt::Plugin::Driver
109
- # See AddressManager#hostnames
110
- def hostnames()
111
- # NOTE: depends on driver's implementation of addresses
112
- names = addresses.inject(Set.new) do |sum, address|
113
- # Some addresses can't be resolved, bummer.
114
- sum.merge(Resolv.getnames(address)) rescue Resolv::ResolvError; sum
115
- end
116
- names << Socket.gethostname
117
- names.merge(Socket.gethostbyname(Socket.gethostname)[1]) rescue SocketError
118
-
119
- names.each{|name| names.merge(hostnames_for(name))}
120
- names << "localhost"
121
- return names.to_a.sort
122
- end
123
-
124
- # See AddressManager#hostname_for
125
- def hostnames_for(hostname)
126
- results = []
127
- elements = hostname.split(".")
128
- for i in 1..elements.size
129
- results << elements[0..i-1].join(".")
130
- end
131
- return results.to_a.sort
132
- end
133
-
134
- # See AddressManager#mask_to_cidr
135
- def mask_to_cidr(mask)
136
- # TODO Find less horrible solution which can handle IPv6.
137
- result = ''
138
- for chunk in mask.split(".")
139
- result += dec2bin(chunk.to_i)
140
- end
141
- return result.scan(/1/).size
142
- end
143
-
144
- # See AddressManager#cidr_to_mask
145
- def cidr_to_mask(cidr)
146
- # TODO Find less horrible solution which can handle IPv6.
147
- require 'ipaddr'
148
- IPAddr.new("0.0.0.0/#{cidr}").inspect.match(%r{/([\d\.]+)>})[1]
149
- end
150
-
151
- # See AddressManager#dec2bin
152
- def dec2bin(n)
153
- # dec2bin(255)
154
- return "%b" % n
155
- end
156
-
157
- # See AddressManager#bin2dec
158
- def bin2dec(s)
159
- return s.to_i(2)
160
- end
161
79
  end
162
80
 
163
81
  # Drivers
82
+ require 'automateit/address_manager/base'
164
83
  require 'automateit/address_manager/portable'
165
84
  require 'automateit/address_manager/linux'
85
+ require 'automateit/address_manager/sunos'
@@ -0,0 +1,148 @@
1
+ # == AddressManager::BaseDriver
2
+ #
3
+ # Base class for all AddressManager drivers.
4
+ class AutomateIt::AddressManager::BaseDriver< AutomateIt::Plugin::Driver
5
+ public
6
+
7
+ # See AddressManager#hostnames
8
+ def hostnames()
9
+ # NOTE: depends on driver's implementation of addresses
10
+ names = addresses.inject(Set.new) do |sum, address|
11
+ # Some addresses can't be resolved, bummer.
12
+ sum.merge(Resolv.getnames(address)) rescue Resolv::ResolvError; sum
13
+ end
14
+ names << Socket.gethostname
15
+ names.merge(Socket.gethostbyname(Socket.gethostname)[1]) rescue SocketError
16
+
17
+ names.each{|name| names.merge(hostnames_for(name))}
18
+ names << "localhost"
19
+ return names.to_a.sort
20
+ end
21
+
22
+ # See AddressManager#hostname_for
23
+ def hostnames_for(hostname)
24
+ results = []
25
+ elements = hostname.split(".")
26
+ for i in 1..elements.size
27
+ results << elements[0..i-1].join(".")
28
+ end
29
+ return results.to_a.sort
30
+ end
31
+
32
+ # See AddressManager#has?
33
+ def has?(opts)
34
+ raise ArgumentError.new(":device or :address must be specified") unless opts[:device] or opts[:address]
35
+ result = true
36
+ result &= interfaces.include?(opts[:device]) if opts[:device] and not opts[:label]
37
+ result &= interfaces.include?(opts[:device]+":"+opts[:label]) if opts[:device] and opts[:label]
38
+ result &= addresses.include?(opts[:address]) if opts[:address]
39
+ return result
40
+ end
41
+
42
+ #-----------------------------------------------------------------------
43
+
44
+ protected
45
+
46
+ # Convert a mask to a CIDR.
47
+ #
48
+ # Example:
49
+ # mask_to_cidr("255.255.255.0") # => 24
50
+ def mask_to_cidr(mask)
51
+ # TODO Find less horrible solution which can handle IPv6.
52
+ result = ''
53
+ for chunk in mask.split(".")
54
+ result += dec2bin(chunk.to_i)
55
+ end
56
+ return result.scan(/1/).size
57
+ end
58
+
59
+ # Convert CIDR to mask.
60
+ #
61
+ # Example:
62
+ # cidr_to_mask(24) # => "255.255.255.0"
63
+ def cidr_to_mask(cidr)
64
+ # TODO Find less horrible solution which can handle IPv6.
65
+ require 'ipaddr'
66
+ IPAddr.new("0.0.0.0/#{cidr}").inspect.match(%r{/([\d\.]+)>})[1]
67
+ end
68
+
69
+ # Convert a decimal number to binary notation.
70
+ #
71
+ # Example:
72
+ # dec2bin(255) # => "11111111"
73
+ def dec2bin(n)
74
+ # dec2bin(255)
75
+ return "%b" % n
76
+ end
77
+
78
+ # Convert a binary number to decimal.
79
+ #
80
+ # Example:
81
+ # bin2dec("11111111") # => 255
82
+ def bin2dec(s)
83
+ return s.to_i(2)
84
+ end
85
+
86
+ # Helper for #add method.
87
+ def _add_helper(opts, &block)
88
+ opts[:announcements] = opts[:announcements].to_i || AutomateIt::AddressManager::DEFAULT_ANNOUNCEMENTS
89
+ raise SecurityError.new("you must be root") unless superuser?
90
+ raise ArgumentError.new(":device and :address must be specified") unless opts[:device] and opts[:address]
91
+ return false if has?(opts)
92
+ block.call(opts)
93
+ return true
94
+ end
95
+
96
+ # Helper for #remove method.
97
+ def _remove_helper(opts, &block)
98
+ return false unless has?(opts)
99
+ raise SecurityError.new("you must be root") unless superuser?
100
+ raise ArgumentError.new(":device and :address must be specified") unless opts[:device] and opts[:address]
101
+ return block.call(opts)
102
+ end
103
+
104
+ # Alter +opts+ hash to add alternative names for various options.
105
+ def _normalize_opts(opts)
106
+ # Accept common alternative names
107
+ opts[:mask] ||= opts[:netmask] if opts[:netmask]
108
+ opts[:alias] ||= opts[:alias] if opts[:alias]
109
+ opts[:device] ||= opts[:interface] if opts[:interface]
110
+
111
+ if opts[:mask] and not opts[:mask].match(/\./)
112
+ opts[:mask] = cidr_to_mask(opts[:mask])
113
+ end
114
+
115
+ return opts
116
+ end
117
+
118
+ # Return the interface and label specified in +opts+ hash, e.g., "eth0:1".
119
+ def _interface_and_label(opts)
120
+ return(
121
+ if opts[:device] and not opts[:label]
122
+ opts[:device]
123
+ elsif opts[:device] and opts[:label]
124
+ "%s:%s" % [opts[:device], opts[:label]]
125
+ else
126
+ raise ArgumentError.new("Can't derive interface and label for: #{opts.inspect}")
127
+ end
128
+ )
129
+ end
130
+
131
+ def _ifconfig_helper(action, opts)
132
+ _raise_unless_available
133
+ action = :del if action.to_sym == :remove
134
+
135
+ _normalize_opts(opts)
136
+
137
+ ### ifconfig hme0 192.9.2.106 netmask 255.255.255.0 up
138
+ ### ifconfig hme0:1 172.40.30.4 netmask 255.255.0.0 up
139
+
140
+ ipcmd = "ifconfig"
141
+ ipcmd << " " << _interface_and_label(opts)
142
+ ipcmd << " %s" % opts[:address]
143
+ ipcmd << " netmask %s" % opts[:mask] if opts[:mask]
144
+ ipcmd << " up" if action == :add
145
+ ipcmd << " down" if action == :del
146
+ return ipcmd
147
+ end
148
+ end
@@ -4,67 +4,29 @@
4
4
  # querying, adding and removing addresses on platforms that feature Linux-like
5
5
  # tools.
6
6
  class AutomateIt::AddressManager::Linux < AutomateIt::AddressManager::BaseDriver
7
- depends_on :programs => "ifconfig",
7
+ depends_on :programs => "ifconfig",
8
8
  :callbacks => lambda{`ifconfig --version 2>&1`.match(/net-tools/)}
9
9
 
10
10
  def suitability(method, *args) # :nodoc:
11
11
  available? ? 2 : 0
12
12
  end
13
13
 
14
- # See AddressManager#has?
15
- def has?(opts)
16
- raise ArgumentError.new(":device or :address must be specified") unless opts[:device] or opts[:address]
17
- result = true
18
- result &= interfaces.include?(opts[:device]) if opts[:device] and not opts[:label]
19
- result &= interfaces.include?(opts[:device]+":"+opts[:label]) if opts[:device] and opts[:label]
20
- result &= addresses.include?(opts[:address]) if opts[:address]
21
- return result
22
- end
23
-
24
14
  # See AddressManager#add
25
15
  def add(opts)
26
- announcements = opts[:announcements].to_i || AutomateIt::AddressManager::DEFAULT_ANNOUNCEMENTS
27
- raise SecurityError.new("you must be root") unless superuser?
28
- raise ArgumentError.new(":device and :address must be specified") unless opts[:device] and opts[:address]
29
- return false if has?(opts)
30
- interpreter.sh(_add_or_remove_command(:add, opts))
31
- if interpreter.which("arping")
32
- interpreter.sh("arping -q -c #{announcements} -w #{announcements} -I #{opts[:device]} #{opts[:address]}")
16
+ _add_helper(opts) do |opts|
17
+ interpreter.sh(_ifconfig_helper(:add, opts))
18
+ if interpreter.which("arping")
19
+ interpreter.sh("arping -q -c #{opts[:announcements]} -w #{opts[:announcements]} -I #{opts[:device]} #{opts[:address]}")
20
+ end
33
21
  end
34
- return true
35
22
  end
36
23
 
37
24
  # See AddressManager#remove
38
25
  def remove(opts)
39
- return false unless has?(opts)
40
- raise SecurityError.new("you must be root") unless superuser?
41
- raise ArgumentError.new(":device and :address must be specified") unless opts[:device] and opts[:address]
42
- return interpreter.sh(_add_or_remove_command(:remove, opts))
43
- end
44
-
45
- def _add_or_remove_command(action, opts)
46
- _raise_unless_available
47
- action = :del if action.to_sym == :remove
48
-
49
- # Accept common alternative names
50
- opts[:mask] ||= opts[:netmask] if opts[:netmask]
51
- opts[:alias] ||= opts[:alias] if opts[:alias]
52
- opts[:device] ||= opts[:interface] if opts[:interface]
53
-
54
- if opts[:mask] and not opts[:mask].match(/\./)
55
- opts[:mask] = cidr_to_mask(opts[:mask])
26
+ _remove_helper(opts) do |opts|
27
+ interpreter.sh(_ifconfig_helper(:remove, opts))
56
28
  end
57
-
58
- ipcmd = "ifconfig"
59
- ipcmd << " %s" % opts[:device] if opts[:device] and not opts[:label]
60
- ipcmd << " %s:%s" % [opts[:device], opts[:label]] if opts[:device] and opts[:label]
61
- ipcmd << " %s" % opts[:address]
62
- ipcmd << " netmask %s" % opts[:mask] if opts[:mask]
63
- ipcmd << " up" if action == :add
64
- ipcmd << " down" if action == :del
65
- return ipcmd
66
29
  end
67
- private :_add_or_remove_command
68
30
 
69
31
  # See AddressManager#interfaces
70
32
  def interfaces()
@@ -0,0 +1,46 @@
1
+ # == AddressManager::SunOS
2
+ #
3
+ # A SunOS-specific driver for the AddressManager provides complete support for
4
+ # querying, adding and removing addresses.
5
+ class AutomateIt::AddressManager::SunOS < AutomateIt::AddressManager::BaseDriver
6
+ def self.token
7
+ :sunos
8
+ end
9
+
10
+ depends_on :programs => %w(ifconfig uname),
11
+ :callbacks => lambda{`uname -s`.match(/sunos/i)}
12
+
13
+ def suitability(method, *args) # :nodoc:
14
+ available? ? 2 : 0
15
+ end
16
+
17
+ # See AddressManager#add
18
+ def add(opts)
19
+ _add_helper(opts) do |opts|
20
+ interpreter.sh("ifconfig %s plumb" % _interface_and_label(opts))
21
+ interpreter.sh(_ifconfig_helper(:add, opts))
22
+ end
23
+ end
24
+
25
+ # See AddressManager#remove
26
+ def remove(opts)
27
+ _remove_helper(opts) do |opts|
28
+ interpreter.sh(_ifconfig_helper(:remove, opts))
29
+ interpreter.sh("ifconfig %s unplumb" % _interface_and_label(opts))
30
+ true
31
+ end
32
+ end
33
+
34
+ # See AddressManager#interfaces
35
+ def interfaces()
36
+ _raise_unless_available
37
+ return `ifconfig -a`.scan(/^([^ ]+):\s+/s).flatten
38
+ end
39
+
40
+ # See AddressManager#addresses
41
+ def addresses()
42
+ _raise_unless_available
43
+ return `ifconfig -a`.scan(/\s+inet\s+([^\s]+)\s+/).flatten
44
+ end
45
+ end
46
+
@@ -633,6 +633,10 @@ module AutomateIt
633
633
  # * nil -- Returns boolean of whether nitpick messages will be displayed.
634
634
  # * Boolean -- Sets nitpick state.
635
635
  # * String or Symbol -- Displays nitpick message if state is on.
636
+ #
637
+ # Example:
638
+ # nitpick true
639
+ # nitpick "I'm nitpicking"
636
640
  def nitpick(value=nil)
637
641
  case value
638
642
  when NilClass: @nitpick