def sudo_popen(*args, **kwargs):
 user = kwargs.get('user', None)
 full_command = [SUDO_PATH, SUDO_PRESERVE_ENVIRONMENT_ARG]
 if user:
  full_command.extend([SUDO_USER_ARG, user])
 full_command.extend(args)
 log.info(('About to execute the following sudo command - [%s]' % ' '.join(full_command)))
 p = Popen(full_command, shell=False, stdout=PIPE, stderr=PIPE)
 return p

def sudo_popen ( * args , ** kwargs ) : user = kwargs . get ( 'user' , None ) full_command = [ SUDO_PATH , SUDO_PRESERVE_ENVIRONMENT_ARG ] if user : full_command . extend ( [ SUDO_USER_ARG , user ] ) full_command . extend ( args ) log . info ( ( 'About to execute the following sudo command - [%s]' % ' ' . join ( full_command ) ) ) p = Popen ( full_command , shell = False , stdout = PIPE , stderr = PIPE ) return p
helper method for building and executing popen command .