Thanks Jack, that explains a lot about behavior I was seeing.
Jean
Jack Schwartz wrote:
> Hi Jean.
>
> One general comment: it's more useful to the (commandline) caller to
> return an appropriate errno when things go wrong. This will help in
> testing, and could also be useful if the DC is called from a script.
>
> Python doesn't do this when it raises an exception that isn't caught,
> as shown in the following example:
>
> strongheart:/usr/share/distro_const> python
> >>> import os
> >>> try:
> ... os.chmod("/tmp/abcdefg", 0777);
> ... except Exception, e:
> ... raise SystemExit(e)
> ...
> [Errno 2] No such file or directory: '/tmp/abcdefg'
> strongheart:/usr/share/distro_const> echo $?
> 1
>
> But in the main, you can retrieve the errno from an exception and call
> sys.exit with it, like this:
>
> import os
> import traceback
> import sys
> try:
> ... os.chmod("/tmp/abcdefg", 0777);
> ... except Exception, e:
> ... traceback.print_exc()
> ... sys.exit(e.args[0])
> ...
> Traceback (most recent call last):
> File "<stdin>", line 2, in ?
> OSError: [Errno 2] No such file or directory: '/tmp/abcdefg'
> strongheart:/usr/share/distro_const> echo $?
> 2
>
> So you see here that 2 (errno) is returned instead of 1.
>
> Thanks,
> Jack
>
>
>
>
> On 12/16/08 12:28, Jean McCormack wrote:
>> Karen Tung wrote:
>>
>>> Jean McCormack wrote:
>>>
>>>> Please review the following webrev for defects 4352 & 4354
>>>>
>>>> Defects:
>>>> http://defect.opensolaris.org/bz/show_bug.cgi?id=4352
>>>> http://defect.opensolaris.org/bz/show_bug.cgi?id=4354
>>>>
>>>> Webrev:
>>>> http://cr.opensolaris.org/~jeanm/slim_4352_4354/
>>>>
>>>> Jean
>>>> _______________________________________________
>>>> caiman-discuss mailing list
>>>> caiman-discuss at opensolaris.org
>>>> http://mail.opensolaris.org/mailman/listinfo/caiman-discuss
>>>>
>>>>
>>> Hi Jean,
>>>
>>> Here are my comments:
>>>
>>> distro_const.py, line 51:
>>> - What's changed in this line? I don't see anything, but it indicated
>>> that it's changed.
>>>
>>>
>> manifest <underscore> file was changed to manifest<dash>file. This now
>> agrees with the
>> rest of the usage statement.
>>
>> distro_const.py, line 574:
>>
>>> - While the code works the way it is now,
>>> I am concern about the possibility of information lost by just
>>> returning 2 for
>>> all the SystemExit. It's true that right now, the usage() is the only
>>> thing that returns 2.
>>> What about in the future? What about other part of the DC code that
>>> might
>>> call SystemExit() with an error message that we want to see?
>>> IMO, it is more correct to define an exception specific to usage
>>> related errors,
>>> and catch that exception, assign the appropriate return code, and
>>> leave SystemExit()
>>> the way it is.
>>>
>> That sounds good.
>>
>> Jean
>>
>>> Thanks,
>>>
>>> --Karen
>>>
>>
>> _______________________________________________
>> caiman-discuss mailing list
>> caiman-discuss at opensolaris.org
>> http://mail.opensolaris.org/mailman/listinfo/caiman-discuss
>>
>