[rfc] UIFactory.is_interactive()

Gordon Tyler gordon at doxxx.net
Tue Nov 24 23:43:24 GMT 2009


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Martin Pool wrote:
> 2009/11/25 Gordon Tyler <gordon at doxxx.net>:
>> Andrew Bennetts wrote:
>>>> This somewhat violates "don't look before you leap" but it's probably
>>>> worthwhile to avoid thinking about interactive stuff before you do it.
>>> Maybe a less LBYL solution would be:
>>>
>>>    if not ui_factory.get_boolean("really delete everything?",
>>> default=True):
>>>        return
>>>    delete_everything()
>>>
>>> Although perhaps “default choice” is not precisely the same concept as
>>> “choice
>>> to take when non-interactive”, it's probably close enough.
> 
> Another option is to make them all raise some exception indicating
> that no user interaction is possible.

I thought about suggesting that but I realized that dealing with the
exception is messy on the calling side. It would lead to code like this:

  try:
    if ui_factory.get_boolean("really delete everything?"):
      delete_everything()
  except NonInteractiveError:
    pass

Which is really just too verbose for my liking. Although, I suppose you
could leave the handling of the error to the outer parts of the bzr
command processing code.

It would also be "invisible" in the interface because Python exceptions
are not checked like Java's.

> get_boolean was perhaps not a good example to use because it's likely
> in all those cases that you can just assume 'yes' or 'no' as the case
> may be.  For something like asking for a password or username, you
> actually want it to take a totally different path.  (But this could
> still potentially be accomodated by returning None.)

None seems like a reasonable indicator of "no answer". It would require
auditing of all calls to ui_factory methods requiring interaction to
ensure that they are dealing with None correctly.

Ciao,
Gordon

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJLDG+cAAoJEIrPJfWinA2uP9IH/14ardAifATCG7J7twt+ijnE
OCjYorCcmHz4KrusBaxIoQnBLiqE5byaHXbHnDUX/oylkWGBZKJQiRgtIEurywhW
mlvhpWfJLP1MvWM2T1L3OFOcM+EX1Xba/1M9E1wclMjHtM+b0ivGXCe7KZK3fHYB
SM8MGpvuXCJvyAjDs3CbtcgG4IPJ2rXmUcVe03nKOFrB8Jwz6FKhJMjrDHb7YQJX
ubsp84BAKLfdPlT5g5jf1M/Bx9vJ988ngkABsi1iEGE5Mb3QDVLTxspJNxI6zF+y
NPJ+yfg9QSo0fpdrFClTG3gAPhwWbIYZ3ZLTQNn5eNZnCE/9vgKXrvs2UuJ/fvw=
=VqM+
-----END PGP SIGNATURE-----



More information about the bazaar mailing list