[EMAIL PROTECTED] wrote:
> I looked at this code some more and re-thought some of my advice.
> 
> There's another problem lurking.  If your code chooses not to import
> libbe in bootenv.py, any calls to the BootEnv class will fail with a
> naming error as soon as you try to call functions from lg.  For example,
> the BootEnv constructor calls lg.beList(); however, if you've not imported
> the lg module, you'll get a NameError.

True however it is caught in the exception after the failed attempt to do a 
lg.beList() and processing continues without error.

> 
> When you don't import the lg module, you need to make sure that the
> bootenv.py code doesn't call functions from the module that haven't been
> imported.
> 

Each function call into BootEnv returns right away when libbe isn't imported. I 
chose this style instead of checking before each call is made in client.py. 
Keeps client.py cleaner.

> Regarding the location of modules, python stores the locations that it
> looks for modules in sys.path, so you could simplify your search by
> looking in those directories.
> 
> On my system this looks like:
> 
>       >>> import sys
>       >>> print sys.path
>       ['', '/usr/lib/python24.zip', '/usr/lib/python2.4', 
> '/usr/lib/python2.4/plat-sunos5', '/usr/lib/python2.4/lib-tk', 
> '/usr/lib/python2.4/lib-dynload', '/usr/lib/python2.4/site-packages', 
> '/usr/lib/python2.4/vendor-packages', 
> '/usr/lib/python2.4/vendor-packages/gtk-2.0']
> 
> Another approach might be to try to import libbe, but catch the
> ImportError that gets raised if the module cannot be found.  In this
> case, you could then set whatever variables you need so that the BootEnv
> classes won't fail in horrible ways when its methods are invoked.
> 

I like both these ideas better than using os.system() and your first 
suggestion. I'll implement something similar.

Thanks
Tim

> Danek may also have additional stylistic guidance for you.
> 
> -j
> 
> On Wed, Apr 02, 2008 at 11:23:55AM -0700, [EMAIL PROTECTED] wrote:
>>> - importing the library is done dynamically. If it exists it is
>>> imported, if not it isn't. This allows pkg(1) to not hard require
>>> SUNWinstall-libs which delivers libbe.so and also allows pkg(1) to
>>> exist on systems that SUNWinstall-libs will not be installed on.
>> Thanks for making this change.  I do, however, have a nit with the way
>> it's implemented.  I think this can be written in Python using
>> os.listdir(), os.walk(), and os.path.exists().  We shouldn't be calling
>> os.system() here.
>>
>> -j
>>
_______________________________________________
pkg-discuss mailing list
[email protected]
http://mail.opensolaris.org/mailman/listinfo/pkg-discuss

Reply via email to