gnulib-tool-py
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [gnulib-tool-py] func_gnulib_dir


From: Bruno Haible
Subject: Re: [gnulib-tool-py] func_gnulib_dir
Date: Sun, 24 Jun 2012 03:19:16 +0200
User-agent: KMail/4.7.4 (Linux/3.1.10-1.9-desktop; KDE/4.7.4; x86_64; ; )

Dmitriy Selyutin wrote:
> I can't understand all what happens in func_gnulib_dir.

It determines the location of gnulib-tool, under the assumption that
argv[0] contained the command, and that $PATH was used to resolve the
command.

In Python you can use built-ins such as __file__ or sys.modules. I've
been doing experiments with code like this:

def find_executable(filename):
    if (os.path.isabs(filename)):
        return filename
    if (os.path.dirname(filename) != ''):
        return os.path.join(os.getcwd(), filename)
    for dir in os.get_exec_path():
        os.path.join(dir, filename)
        <code unfinished here>

print(__file__)
print(sys.modules['__main__'].__file__)

I expect that you will not need to know in detail what func_gnulib_dir
does in the old gnulib-tool, because the shell does not have the __file__
built-in. Just write the equivalent of this function from scratch.

Bruno




reply via email to

[Prev in Thread] Current Thread [Next in Thread]