All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Bartosz Golaszewski <brgl@bgdev.pl>
Cc: Kent Gibson <warthog618@gmail.com>,
	Linus Walleij <linus.walleij@linaro.org>,
	Viresh Kumar <viresh.kumar@linaro.org>,
	linux-gpio@vger.kernel.org
Subject: Re: [libgpiod v2][PATCH v4 2/4] bindings: python: add examples
Date: Wed, 26 Oct 2022 15:53:42 +0300	[thread overview]
Message-ID: <Y1kt1iHYpbZGaND4@smile.fi.intel.com> (raw)
In-Reply-To: <20221026123425.498912-3-brgl@bgdev.pl>

On Wed, Oct 26, 2022 at 02:34:23PM +0200, Bartosz Golaszewski wrote:
> This adds the regular set of example programs implemented using libgpiod
> python bindings.

...

> +if __name__ == "__main__":
> +    for chip in gpio_chips():
> +        info = chip.get_info()
> +        print("{} [{}] ({} lines)".format(info.name, info.label, info.num_lines))

In all of them I would prefer to see the main() explicitly, like

def main():
	...

if __name__ == "__main__":
    main()

(In this case the module can be imported by another one and main be reused)

Also have you considered use of SystemExit() wrapper?

...

> +                    sys.exit(0)
> +
> +    sys.exit(1)

Is it in the original C code?!
I would expect that no chips -- no error.

...

> +if __name__ == "__main__":
> +    if len(sys.argv) < 3:
> +        raise TypeError("usage: gpioget.py <gpiochip> <offset1> <offset2> ...")

	SystemExit(main(sys.argv)) ?

> +    path = sys.argv[1]
> +    lines = [int(line) if line.isdigit() else line for line in sys.argv[2:]]
> +
> +    request = gpiod.request_lines(
> +        path,
> +        consumer="gpioget.py",
> +        config={tuple(lines): gpiod.LineSettings(direction=Direction.INPUT)},
> +    )
> +
> +    vals = request.get_values()
> +
> +    for val in vals:
> +        print("{} ".format(val.value), end="")

> +    print()

Without any conditional it will print an empty line, was it originally in the C
variant?

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2022-10-26 12:53 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-26 12:34 [libgpiod v2][PATCH v4 0/4] bindings: implement python bindings for libgpiod v2 Bartosz Golaszewski
2022-10-26 12:34 ` [libgpiod v2][PATCH v4 1/4] bindings: python: remove old version Bartosz Golaszewski
2022-10-26 12:34 ` [libgpiod v2][PATCH v4 2/4] bindings: python: add examples Bartosz Golaszewski
2022-10-26 12:53   ` Andy Shevchenko [this message]
2022-10-27  8:05     ` Bartosz Golaszewski
2022-10-26 12:34 ` [libgpiod v2][PATCH v4 3/4] bindings: python: add tests Bartosz Golaszewski
2022-10-26 12:34 ` [libgpiod v2][PATCH v4 4/4] bindings: python: implement python bindings for libgpiod v2 Bartosz Golaszewski
2022-10-31 11:41 ` [libgpiod v2][PATCH v4 0/4] bindings: " Bartosz Golaszewski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y1kt1iHYpbZGaND4@smile.fi.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=brgl@bgdev.pl \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=viresh.kumar@linaro.org \
    --cc=warthog618@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.