FW: python import sys.path

Fuzzyman fuzzyman at gmail.com
Fri Jan 2 18:49:03 CET 2009


On Jan 2, 2:28 pm, John Machin <sjmac... at lexicon.net> wrote:
> On Jan 3, 1:09 am, "Kelly, Brian" <Brian.Ke... at uwsp.edu> wrote:> After following your suggestions I was able to confirm that the 2.5
> > interpreter was being invoked. So then I grepped for all instances of python
> > in the scripts that were imported as modules: from bacula_conf import *
>
> > The calling script cleanup.py is invoking purge_client.py like an external
> > script:
>
> > def purgeAll(options, computer_name):
> >     cmd = "python purge_client.py %s" % computer_name
> >     if options.pretend <> True:
>
> Who wrote that?
>
> >         error = os.system(cmd)
> >     else:
> >         _log.info("Done. No changes made due to --pretend flag.")
>
>            #### error is not defined in this branch>     if not error: #### Splat!
> >         return True
> >     else:
> >         return False
>
>  AArrgh! Try:
>
>    return not error
>

That will still blow up with a NameError when the path doing the
logging is invoked.

How about:


def purgeAll(options, computer_name):
    cmd = "python purge_client.py %s" % computer_name
    if options.pretend != True:  # if not options.pretend (assuming it
is a bool)
        error = os.system(cmd)
        return not error

    _log.info("Done. No changes made due to --pretend flag.")
    return True


Michael
--
http://www.ironpythoninaction.com/



More information about the Python-list mailing list