ben+python at benfinney.id.au
Wed Nov 26 21:24:49 CET 2014
Tim Daneliuk <tundra at tundraware.com> writes:
> The problem I am trying to solve is to determine whether the user
> needs to provide a sudo password or not.
Again, the ‘sudo’ program itself will figure this out and ask for a
password if it needs one.
Examining the command line isn't enough. Even if you find a ‘sudo’
command there, there are common circumstances where no password is
needed. The program handles all this, you can't predict it from outside.
> Right now, the program just naively checks the arguments to see if
> .startswith("sudo'). As the example given illustrates, that clearly
> fails if the sudo is given later in a longer pipeline.
The problem as you've presented it requires you to re-implement the
command-line parsing from whatever command shell is used. You will
necessarily fall short of that, no matter what you do.
Your best course is to get the requirements changed, as they are
currently not implementable.
\ “Facts are stubborn things; and whatever may be our wishes, our |
`\ inclinations, or the dictates of our passion, they cannot alter |
_o__) the state of facts and evidence.” —John Adams, 1770-12-04 |
More information about the Python-list