automateit 0.71003 → 0.71006

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data.tar.gz.sig CHANGED
Binary file
data/CHANGES.txt CHANGED
@@ -1,3 +1,12 @@
1
+ 0.71006:
2
+ Date: Sat, 06 Oct 2007 17:55:37 -0700
3
+ Desc:
4
+ - (%) Fixed EditSession#delete to delete lines matching substrings rather than exact matches.
5
+ - Fixed EditSession#comment to not comment already commented-out lines.
6
+ - Fixed SessionManager#start and #stop so these don't check status when called with :force option.
7
+ - Improved SessionManager#restart to use :wait option.
8
+ - Improved #download to accept array or hash as arguments.
9
+
1
10
  0.71003:
2
11
  Date: Wed, 03 Oct 2007 01:17:32 -0700
3
12
  Desc:
data/Rakefile CHANGED
@@ -299,4 +299,8 @@ task :chown do
299
299
  end
300
300
  end
301
301
 
302
+ task :rdoclink do
303
+ automateit.ln_s("/home/lagi/stash/automateit_rdoc", "doc")
304
+ end
305
+
302
306
  #===[ fin ]=============================================================
@@ -9,7 +9,7 @@ module AutomateIt
9
9
  #
10
10
  # Options:
11
11
  # * :to -- Saves source to this filename or directory. Defaults to current directory.
12
- def download(source, opts={}) dispatch(source, opts) end
12
+ def download(*arguments) dispatch(*arguments) end
13
13
 
14
14
  # == DownloadManager::BaseDriver
15
15
  #
@@ -28,8 +28,10 @@ module AutomateIt
28
28
  end
29
29
 
30
30
  # See DownloadManager#download
31
- def download(source, opts={})
32
- target = opts[:to] || File.basename(source)
31
+ def download(*arguments)
32
+ args, opts = args_and_opts(*arguments)
33
+ source = args[0] or raise ArgumentError.new("No source specified")
34
+ target = args[1] || opts[:to] || File.basename(source)
33
35
  target = File.join(target, File.basename(source)) if File.directory?(target)
34
36
  log.info(PNOTE+"Downloading #{target}")
35
37
  if writing?
@@ -217,7 +217,7 @@ class AutomateIt::EditManager::EditSession < AutomateIt::Common
217
217
  # Delete lines matching the String or Regexp +query+
218
218
  def delete(query, opts={})
219
219
  query = Regexp.escape(query) if query.is_a?(String)
220
- query = Regexp.new(query+"\n?")
220
+ query = Regexp.new("^[^\n]*%s[^\n]*\n?" % query)
221
221
  @contents.gsub!(query, "")
222
222
  end
223
223
 
@@ -234,7 +234,7 @@ class AutomateIt::EditManager::EditSession < AutomateIt::Common
234
234
  # Comment out lines matching the String or Regexp +query+.
235
235
  def comment(query, opts={})
236
236
  query = Regexp.escape(query) if query.is_a?(String)
237
- query = Regexp.new("^([^\n]*%s[^\n]*)(\n*)" % query)
237
+ query = Regexp.new("^(?!#{comment_prefix})([^\n]*%s[^\n]*)(\n*)" % query)
238
238
  return false unless @contents.match(query)
239
239
  @contents.gsub!(query, "%s%s%s%s" % [@comment_prefix, $1, @comment_suffix, $2])
240
240
  end
@@ -1,7 +1,7 @@
1
1
  # See AutomateIt::Interpreter for usage information.
2
2
  module AutomateIt # :nodoc:
3
3
  # AutomateIt version
4
- VERSION=Gem::Version.new("0.71003")
4
+ VERSION=Gem::Version.new("0.71006")
5
5
 
6
6
  # Instantiates a new Interpreter. See documentation for
7
7
  # Interpreter#setup.
@@ -23,15 +23,29 @@ class AutomateIt::ServiceManager < AutomateIt::Plugin::Manager
23
23
  def running?(service, opts={}) dispatch_to(:started?, service, opts) end
24
24
 
25
25
  # Start this +service+ if it's not running.
26
+ #
27
+ # Options:
28
+ # * :wait -- Same as :wait option for #started?
29
+ # * :force -- Start service without checking if it's running.
26
30
  def start(service, opts={}) dispatch(service, opts) end
27
31
 
28
32
  # Stop this +service+ if it's running.
33
+ #
34
+ # Options:
35
+ # * :wait -- Same as :wait option for #stopped?
36
+ # * :force -- Stop service without checking if it's running.
29
37
  def stop(service, opts={}) dispatch(service, opts) end
30
38
 
31
39
  # Restart this +service+ if it's running, or start it if it's stopped.
40
+ #
41
+ # Options:
42
+ # * :wait -- Maxmimum seconds to wait for service to STOP.
43
+ # * :pause -- Maximum seconds to wait for service to START before stopping
44
+ # it. Only set this if you just started the service and then decided to
45
+ # restart it.
32
46
  def restart(service, opts={}) dispatch(service, opts) end
33
47
 
34
- # If +is_restart+, #restart the service, otherwise #start it.
48
+ # If +is_restart+, #restart the service, otherwise #start it.
35
49
  #
36
50
  # Example:
37
51
  # modified = edit "/etc/myapp.conf" {#...}
@@ -76,6 +76,7 @@ class AutomateIt::ServiceManager::SYSV < AutomateIt::ServiceManager::BaseDriver
76
76
  end
77
77
  return result
78
78
  end
79
+ protected :_started_and_stopped_helper
79
80
 
80
81
  # See ServiceManager#started?
81
82
  def started?(service, opts={})
@@ -89,8 +90,7 @@ class AutomateIt::ServiceManager::SYSV < AutomateIt::ServiceManager::BaseDriver
89
90
 
90
91
  # See ServiceManager#start
91
92
  def start(service, opts={})
92
- # TODO maybe add a :wait option?
93
- if started?(service) and not opts[:force]
93
+ if not opts[:force] and started?(service, :wait => opts[:wait])
94
94
  # Already started
95
95
  return false
96
96
  else
@@ -102,8 +102,7 @@ class AutomateIt::ServiceManager::SYSV < AutomateIt::ServiceManager::BaseDriver
102
102
 
103
103
  # See ServiceManager#stop
104
104
  def stop(service, opts={})
105
- # TODO maybe add a :wait option?
106
- if stopped?(service) and not opts[:force]
105
+ if not opts[:force] and stopped?(service, :wait => opts[:wait])
107
106
  # Already stopped
108
107
  return false
109
108
  else
@@ -115,8 +114,17 @@ class AutomateIt::ServiceManager::SYSV < AutomateIt::ServiceManager::BaseDriver
115
114
 
116
115
  # See ServiceManager#restart
117
116
  def restart(service, opts={})
118
- stop(service, opts) if running?(service)
119
- return start(service, opts)
117
+ if started?(service, :wait => opts[:pause])
118
+ # We're certain that service is started
119
+ stop_opts = opts.clone
120
+ stop_opts[:force] = true # Don't check again
121
+ stop(service, stop_opts)
122
+ end
123
+
124
+ # We're certain that service is stopped
125
+ start_opts = opts.clone
126
+ start_opts[:force] = true # Don't check again
127
+ return start(service, start_opts)
120
128
  end
121
129
 
122
130
  # See ServiceManager#enabled?
@@ -23,12 +23,12 @@ else
23
23
  @service_name = "automateit_service_sysv_test"
24
24
  @service_file = "/etc/init.d/"+@service_name
25
25
  @source_file = File.join(File.dirname(__FILE__), "..", "extras", @service_name)
26
+ end
26
27
 
28
+ before(:each) do
27
29
  FileUtils.cp(@source_file, @service_file)
28
30
  FileUtils.chmod(0755, @service_file)
29
- end
30
31
 
31
- before(:each) do
32
32
  @m.stop(@service_name, :quiet => true) if @m.running?(@service_name)
33
33
  end
34
34
 
@@ -64,6 +64,23 @@ else
64
64
  @m.running?(@service_name).should be_true
65
65
  end
66
66
 
67
+ it "should wait for service to restart" do
68
+ # NOTE: Test depends on race condition because checks must pass before the service starts
69
+
70
+ timeout = 1
71
+ wait = timeout+2
72
+ @a.edit(@service_file, :backup => false) do
73
+ replace "touch $STATE", "sleep #{timeout} && touch $STATE &"
74
+ end
75
+
76
+ @m.start(@service_name, :quiet => true).should be_true
77
+ @m.started?(@service_name).should be_false # Still starting
78
+ @m.started?(@service_name, :wait => wait).should be_true
79
+ @m.restart(@service_name, :quiet => true, :wait => wait).should be_true
80
+ @m.started?(@service_name).should be_false
81
+ @m.started?(@service_name, :wait => wait).should be_true
82
+ end
83
+
67
84
  if @has_enable
68
85
  # It's more correct to disable the service using before/after, but the
69
86
  # platform-specific scripts are ridiculously slow, so manually disabling
@@ -6,12 +6,12 @@ describe "AutomateIt::EditManager for strings" do
6
6
  end
7
7
 
8
8
  before(:each) do
9
- @input = "This\nis\n\a\nstring."
9
+ @input = "This\nis\na\nstring."
10
10
  end
11
11
 
12
12
  it "should pass contents" do
13
13
  @a.edit(:text => @input) do
14
- contents.should == "This\nis\n\a\nstring."
14
+ contents.should == "This\nis\na\nstring."
15
15
  end
16
16
  end
17
17
 
@@ -67,9 +67,10 @@ describe "AutomateIt::EditManager for strings" do
67
67
 
68
68
  it "should delete lines" do
69
69
  output = @a.edit(:text => @input) do
70
- delete "This"
70
+ delete "is"
71
71
  end
72
- output.should_not =~ /This/
72
+ output.should_not =~ /is/
73
+ output.should == "a\nstring."
73
74
  end
74
75
 
75
76
  it "should comment lines" do
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: automateit
5
5
  version: !ruby/object:Gem::Version
6
- version: "0.71003"
7
- date: 2007-10-04 00:00:00 -07:00
6
+ version: "0.71006"
7
+ date: 2007-10-08 00:00:00 -07:00
8
8
  summary: AutomateIt is an open-source tool for automating the setup and maintenance of UNIX-like systems
9
9
  require_paths:
10
10
  - lib
metadata.gz.sig CHANGED
Binary file