Re: Linux application deployment

From: klappnase (klappnase_at_web.de)
Date: 09/06/04


Date: 5 Sep 2004 16:14:36 -0700

Jarek Zgoda <jzgoda@gazeta.usun.pl> wrote in message news:<chfh9i$kda$1@nemesis.news.tpi.pl>...
> Grant Edwards <grante@visi.com> pisze:
>
> >> import sys, os
> >>
> >> me = os.path.abspath(sys.argv[0])
> >
> > That's only mostly reliable. Nothing in Linux/Unix actually requires that
> > argv[0] be the program's path. It is the convention to pass that as
> > argv[0], but there may be corner cases where it doesn't work.
>
> Based on Python docs:
>
> """
> argv
>
> The list of command line arguments passed to a Python script.
> argv[0] is the script name (it is operating system dependent whether
> this is a full pathname or not). If the command was executed using
> the -c command line option to the interpreter, argv[0] is set to the
> string '-c'. If no script name was passed to the Python interpreter,
> argv has zero length.
> """
>
> http://docs.python.org/lib/module-sys.html
>
> In my opinion, this would be enough to get full path of currently
> running program, if run from script. Are there any caveats (except this
> "-c" option, which I don't count, as is not relevant in most cases)?

If you use a symbolic link to start the program sys.argv[0] will
return the location of the link instead of the path to your
application file I think. Anyway you can get the directory of the
application file with sys.path[0] if you need it.
However, why not just put all application files into one directory
(like /usr/local/share/yourApp or /opt/lib/myApp or something) and
start it from a link from /usr/local/bin (or /opt/bin) to your app's
main program file instead of messing around with sys.path , at least
it's the easiest solution and I don't really see the benefit of
putting the files into different directories unless you have modules
other people might want to use, in which case python's site-packages
directory would probably be the preferred location.
Just a personal opinion of course.

Regards

Michael



Relevant Pages

  • Re: perl to python
    ... sed and perl can let you do all that quick command line stuff. ... into a full blown script. ... scripts, call it from the python interpreter, whatever I need. ... If I stick to the traditional unix approach, ...
    (comp.lang.python)
  • Re: newbie question
    ... Python is fun and it's easier to use a real OS to develop the programs, ... Grant it I am a command line junky, ... "The script can be given a executable mode, or permission, using the ... the above seems to me like you are useing windows. ...
    (comp.lang.python)
  • Re: Python executable
    ... Python scripts can be made directly ... >of the script and giving the file an executable mode. ... >$ chmod +x myscript.py ... >but I was given the bash: helloworld.py: command not found error. ...
    (comp.lang.python)
  • Re: Module problem
    ... I am writing some simple script, and when I start my script from command ... Do you have more than one version of Python installed? ...
    (comp.lang.python)
  • Re: call f(a, *b) with f(*a, **b) ?
    ... The actual application is an option-parser wrapper (it inherits from ... mainso that you can have a script with a variable number ... (The actual application is a command ... values) and a list of extraneous values to be passed to argv, ...
    (comp.lang.python)