Gentoo Archives: gentoo-portage-dev

From: Zac Medico <zmedico@g.o>
To: gentoo-portage-dev@l.g.o
Subject: Re: [gentoo-portage-dev] [PATCH 2/3] portage/sync/syncbase.py: Change has_bin to an @property function
Date: Fri, 30 Jan 2015 07:45:54
Message-Id: 54CB36AE.8050407@gentoo.org
In Reply to: [gentoo-portage-dev] [PATCH 2/3] portage/sync/syncbase.py: Change has_bin to an @property function by Brian Dolbec
1 On 01/29/2015 11:45 AM, Brian Dolbec wrote:
2 > This avoids that self.logger is None error in the __init__().
3 > ---
4 > pym/portage/sync/syncbase.py | 24 +++++++++++++++---------
5 > 1 file changed, 15 insertions(+), 9 deletions(-)
6 >
7 > diff --git a/pym/portage/sync/syncbase.py b/pym/portage/sync/syncbase.py
8 > index c820bcf..973d545 100644
9 > --- a/pym/portage/sync/syncbase.py
10 > +++ b/pym/portage/sync/syncbase.py
11 > @@ -35,17 +35,23 @@ class SyncBase(object):
12 > self.xterm_titles = None
13 > self.spawn_kwargs = None
14 > self.bin_command = None
15 > - self.has_bin = False
16 > + self._bin_command = bin_command
17 > + self.bin_pkg = bin_pkg
18 > if bin_command:
19 > self.bin_command = portage.process.find_binary(bin_command)
20 > - if self.bin_command is None:
21 > - msg = ["Command not found: %s" % bin_command,
22 > - "Type \"emerge %s\" to enable %s support." % (bin_pkg, bin_command)]
23 > - for l in msg:
24 > - writemsg_level("!!! %s\n" % l,
25 > - level=self.logger.ERROR, noiselevel=-1)
26 > - else:
27 > - self.has_bin = True
28 > +
29 > +
30 > + @property
31 > + def has_bin(self):
32 > + if self.bin_command is None:
33 > + msg = ["Command not found: %s" % self._bin_command,
34 > + "Type \"emerge %s\" to enable %s support."
35 > + % (self.bin_pkg, self._bin_command)]
36 > + for l in msg:
37 > + writemsg_level("!!! %s\n" % l,
38 > + level=self.logger.ERROR, noiselevel=-1)
39 > + return False
40 > + return True
41 >
42 >
43 > def _kwargs(self, kwargs):
44 >
45
46 Maybe it should be named _has_bin instead, since it should only be
47 called by a subclass after it has called _kwargs to initialize
48 self.logger. Otherwise, somebody might think they can access has_bin
49 before _kwargs has been called.
50 --
51 Thanks,
52 Zac