Use decorator library
This commit is contained in:
+15
-17
@@ -1,24 +1,22 @@
|
||||
from functools import wraps
|
||||
import six
|
||||
from decorator import decorator
|
||||
from ..types import Command
|
||||
|
||||
|
||||
def sudo_support(fn):
|
||||
@decorator
|
||||
def sudo_support(fn, command, settings):
|
||||
"""Removes sudo before calling fn and adds it after."""
|
||||
@wraps(fn)
|
||||
def wrapper(command, settings):
|
||||
if not command.script.startswith('sudo '):
|
||||
return fn(command, settings)
|
||||
if not command.script.startswith('sudo '):
|
||||
return fn(command, settings)
|
||||
|
||||
result = fn(Command(command.script[5:],
|
||||
command.stdout,
|
||||
command.stderr),
|
||||
settings)
|
||||
result = fn(Command(command.script[5:],
|
||||
command.stdout,
|
||||
command.stderr),
|
||||
settings)
|
||||
|
||||
if result and isinstance(result, six.string_types):
|
||||
return u'sudo {}'.format(result)
|
||||
elif isinstance(result, list):
|
||||
return [u'sudo {}'.format(x) for x in result]
|
||||
else:
|
||||
return result
|
||||
return wrapper
|
||||
if result and isinstance(result, six.string_types):
|
||||
return u'sudo {}'.format(result)
|
||||
elif isinstance(result, list):
|
||||
return [u'sudo {}'.format(x) for x in result]
|
||||
else:
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user