Rev 44: Fix compatibility with python2.4. in http://bazaar.launchpad.net/%7Evila/bzr/local-test-server
Vincent Ladeuil
v.ladeuil+lp at free.fr
Fri Jul 4 17:16:53 BST 2008
At http://bazaar.launchpad.net/%7Evila/bzr/local-test-server
------------------------------------------------------------
revno: 44
revision-id: v.ladeuil+lp at free.fr-20080704161650-bgygyjpea7cfjd1i
parent: v.ladeuil+lp at free.fr-20080629084230-jnu02vxgw4tesvti
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: local_test_server
timestamp: Fri 2008-07-04 18:16:50 +0200
message:
Fix compatibility with python2.4.
* server.py:
(Server._start_via_command, Server._stop_via_command): New helpers
to work around subprocess.check_call not defined in python-2.4.
modified:
server.py server.py-20080524160639-rqhbexqatjqbwypw-1
-------------- next part --------------
=== modified file 'server.py'
--- a/server.py 2008-06-29 08:42:30 +0000
+++ b/server.py 2008-07-04 16:16:50 +0000
@@ -332,6 +332,32 @@
return False
+ def _start_via_command(self, cmd_args, apparent_cmd_name=None):
+ """Start the server with a command launched in a subprocess.
+
+ A failure to execute the command is fatal.
+ """
+ if apparent_cmd_name is None:
+ apparent_cmd_name = cmd_args[0]
+ retcode = subprocess.call(cmd_args)
+ if retcode:
+ raise LTSCantStartError(
+ self, extra='%s returned non-zero exit status %d'
+ % (apparent_cmd_name, retcode))
+
+ def _stop_via_command(self, cmd_args, apparent_cmd_name=None):
+ """Stop the server with a command launched in a subprocess.
+
+ A failure to execute the command is fatal.
+ """
+ if apparent_cmd_name is None:
+ apparent_cmd_name = cmd_args[0]
+ retcode = subprocess.call(cmd_args)
+ if retcode:
+ raise LTSCantStopError(
+ self, extra='%s returned non-zero exit status %d'
+ % (apparent_cmd_name, retcode))
+
class Apache2(Server):
@@ -350,12 +376,9 @@
self.output_config_path = self.config.abspath('etc/apache2.conf')
def _start(self):
- try:
- subprocess.check_call([self._server_command_name,
- '-k', 'start',
- '-f', self.output_config_path])
- except subprocess.CalledProcessError, e:
- raise LTSCantStartError(self, extra=e)
+ self._start_via_command([self._server_command_name,
+ '-k', 'start',
+ '-f', self.output_config_path])
if not self._wait_for_server_start_in_log():
raise LTSCantStartError(self, extra='logfile contains no start')
@@ -363,14 +386,6 @@
if not self._wait_for_server_stop_in_log():
raise LTSCantStopError(self)
- def _stop_apache2(self):
- try:
- subprocess.check_call([self._server_command_name,
- '-k', 'stop',
- '-f', self.output_config_path ])
- except subprocess.CalledProcessError, e:
- raise LTSCantStopError(self, extra=e)
-
def _wait_for_server_start_in_log(self):
"""Reliably check that the server is started.
@@ -392,7 +407,9 @@
"""
def apache2_stopped():
if not self._find_in_log(self._stopped_re):
- self._stop_apache2()
+ self._stop_via_command([self._server_command_name,
+ '-k', 'stop',
+ '-f', self.output_config_path ])
return False
else:
return True
@@ -429,11 +446,8 @@
self.output_config_path = self.config.abspath('etc/cherokee.conf')
def _start(self):
- try:
- subprocess.check_call([self._server_command_name,
- '-b', '-C', self.output_config_path])
- except subprocess.CalledProcessError, e:
- raise LTSCantStartError(self, extra=e)
+ self._start_via_command([self._server_command_name,
+ '-b', '-C', self.output_config_path])
if not self._wait_for_pidfile_to_be_created():
raise LTSCantStartError(
self, extra='Did not create pid file %s'
@@ -460,11 +474,8 @@
self.output_config_path = self.config.abspath('etc/lighttpd.conf')
def _start(self):
- try:
- subprocess.check_call([self._server_command_name,
- '-f', self.output_config_path])
- except subprocess.CalledProcessError, e:
- raise LTSCantStartError(self, extra=e)
+ self._start_via_command([self._server_command_name,
+ '-f', self.output_config_path])
# Since lighttpd deamonize itself early, the return code is useless,
# most starting errors happening after the fork. Resort to log polling
# for lack of better means :-/
@@ -560,13 +571,11 @@
self.output_config_path = self.config.abspath('etc/proftpd.conf')
def _start(self):
- try:
- subprocess.check_call(['sudo', self._server_command_name,
- '-c', self.output_config_path,
- # Collision checking requires root access
- '--nocollision',])
- except subprocess.CalledProcessError, e:
- raise LTSCantStartError(self, extra=e)
+ self._start_via_command(['sudo', self._server_command_name,
+ '-c', self.output_config_path,
+ # Collision checking requires root access
+ '--nocollision',],
+ apparent_cmd_name=self._server_command_name)
if not self._wait_for_pidfile_to_be_created():
raise LTSCantStartError(
self, extra='Did not create pid file %s'
@@ -575,10 +584,8 @@
def _kill_server_via_sudo(self, pid, sig=None):
if sig is None:
sig = signal.SIGTERM
- try:
- subprocess.check_call(['sudo', 'kill', '-%s' % sig, '%s' % pid])
- except subprocess.CalledProcessError, e:
- raise LTSCantStopError(self, extra=e)
+ self._stop_via_command(['sudo', 'kill', '-%s' % sig, '%s' % pid],
+ apparent_cmd_name='sudo kill')
# Don't try yo be too smart, just rely on pid check to find out if the
# process is dead or not
return False
More information about the bazaar-commits
mailing list