[U-Boot] [PATCH 6/7] tools/genboardscfg.py: check if the boards.cfg is up to date

Masahiro Yamada yamada.m at jp.panasonic.com
Thu Aug 21 06:02:57 CEST 2014


Hi Simon,



On Wed, 20 Aug 2014 13:13:13 -0600
Simon Glass <sjg at chromium.org> wrote:
> > +def output_is_new():
> > +    """Check if the boards.cfg file is up to date.
> > +
> > +    Returns:
> > +      True if the boards.cfg file exists and is newer than any of
> > +      *_defconfig, MAINTAINERS and Kconfig*.  False otherwise.
> > +    """
> > +    try:
> > +        ctime = os.path.getctime(BOARD_FILE)
> > +    except OSError, exception:
> > +        if exception.errno == errno.ENOENT:
> > +            # return False on 'No such file or directory' error
> > +            return False
> > +        else:
> > +            raise
> 
> if not os.path.exists(BOARD_FILE)
>    return False
> 
> would probably be enough.
> 


Actually my first code was as follows:

------------>8------------------------
if not os.path.exists(BOARD_FILE)
    return False

ctime = os.path.getctime(BOARD_FILE)
-------------8<----------------------



But what if someone deletes BOARD_FILE
between os.path.exists(BOARD_FILE) and os.path.getctime(BOARD_FILE)?

I know it is ridiculous to consider such a rare case.


But I believe it is Python style to follow
"try something and then handle an exception" thing.

I am trying to be a bit strict to this rule
when invoking OS system calls where there is possibility of failure.



Best Regards
Masahiro Yamada



More information about the U-Boot mailing list