Using a python decorator to authenticate
<p>I have been trying to learn python decorators and wrote the following code. But it keeps giving errors. </p>

<pre><code>import os
import sys

def authenticate(fn):
    def wrapper(*args):
        euid = os.geteuid()
        if euid != 0:
            print "This command requires privliged mode. Enter password.."
            args = ['sudo', sys.executable] + sys.argv + [os.environ]
            os.execlpe('sudo', *args)
        fn(*args)
    return wrapper

@authenticate
def show_files(dir):
    files = [f for f in os.listdir(dir)]
    for file in files:
        if os.path.isfile(file):
            print file

dir = raw_input("Please enter a directory name\t")
show_files(dir) 
</code></pre>

<p>I get the following traceback:</p>

<pre><code>Traceback (most recent call last):
    File "auth1.py", line 24, in show_files(dir)
    File "auth1.py", line 11, in wrapper fn(*args)
    File "auth1.py", line 16, in show_files files = [f for f in os.listdir(dir)]
    OSError: [Errno 2] No such file or directory: ''
</code></pre>

<hr>

<p>The idea is to run the <code>show_files</code> function only to users who could authenticate themselves. My problem seems to be the way authenticate is written and the <code>execlpe</code> call. Any help appreciated.</p>
