Commit 050aadbe authored by Vincent Pelletier's avatar Vincent Pelletier

Increase verbosity.

Output system commands and system-altering functions from python's os
module.
parent 18e7b0f6
...@@ -41,6 +41,32 @@ import subprocess ...@@ -41,6 +41,32 @@ import subprocess
import sys import sys
import time import time
class OS(object):
_os = os
def __init__(self, config):
self._verbose = config.verbose
self._logger = config.logger
add = self._addWrapper
add('chown')
add('chmod')
add('makedirs')
add('mkdir')
def _addWrapper(self, name):
def wrapper(*args, **kw):
if self._verbose:
arg_list = [repr(x) for x in args] + [
'%s=%r' % (x, y) for x, y in kw.iteritems()]
self._logger.debug('%s(%s)' % (
name,
', '.join(arg_list)
))
getattr(self._os, name)(*args, **kw)
setattr(self, name, wrapper)
def __getattr__(self, name):
return getattr(self._os, name)
class SlapError(Exception): class SlapError(Exception):
""" """
...@@ -944,6 +970,9 @@ class Config: ...@@ -944,6 +970,9 @@ class Config:
def main(): def main():
"Run default configuration." "Run default configuration."
global os
global callAndRead
real_callAndRead = callAndRead
usage = "usage: %s [options] CONFIGURATION_FILE" % sys.argv[0] usage = "usage: %s [options] CONFIGURATION_FILE" % sys.argv[0]
try: try:
...@@ -951,6 +980,12 @@ def main(): ...@@ -951,6 +980,12 @@ def main():
options, configuration_file_path = Parser(usage=usage).check_args() options, configuration_file_path = Parser(usage=usage).check_args()
config = Config() config = Config()
config.setConfig(options, configuration_file_path) config.setConfig(options, configuration_file_path)
os = OS(config)
if config.verbose:
def logging_callAndRead(argument_list, raise_on_error=True):
config.logger.debug(' '.join(argument_list))
return real_callAndRead(argument_list, raise_on_error)
callAndRead = logging_callAndRead
run(config) run(config)
except UsageError, err: except UsageError, err:
print >>sys.stderr, err.msg print >>sys.stderr, err.msg
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment