commit:     fbe5cf2702c3555fb717f8d230be7a4ab9baf1f2
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Thu Jan 29 16:53:56 2015 +0000
Commit:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Fri Jan 30 20:05:26 2015 +0000
URL:        
http://sources.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=fbe5cf27

portage/sync/syncbase.py: Change has_bin to an @property function

This avoids that self.logger is None error in the __init__().

---
 pym/portage/sync/modules/websync/websync.py |  2 +-
 pym/portage/sync/syncbase.py                | 30 +++++++++++++++++++----------
 2 files changed, 21 insertions(+), 11 deletions(-)

diff --git a/pym/portage/sync/modules/websync/websync.py 
b/pym/portage/sync/modules/websync/websync.py
index 3576116..17f4ced 100644
--- a/pym/portage/sync/modules/websync/websync.py
+++ b/pym/portage/sync/modules/websync/websync.py
@@ -32,7 +32,7 @@ class WebRsync(SyncBase):
                if kwargs:
                        self._kwargs(kwargs)
 
-               if not self.has_bin:
+               if not self._has_bin:
                        return (1, False)
 
                emerge_config = self.options.get('emerge_config', None)

diff --git a/pym/portage/sync/syncbase.py b/pym/portage/sync/syncbase.py
index c820bcf..229927f 100644
--- a/pym/portage/sync/syncbase.py
+++ b/pym/portage/sync/syncbase.py
@@ -35,17 +35,27 @@ class SyncBase(object):
                self.xterm_titles = None
                self.spawn_kwargs = None
                self.bin_command = None
-               self.has_bin = False
+               self._bin_command = bin_command
+               self.bin_pkg = bin_pkg
                if bin_command:
                        self.bin_command = 
portage.process.find_binary(bin_command)
-                       if self.bin_command is None:
-                               msg = ["Command not found: %s" % bin_command,
-                               "Type \"emerge %s\" to enable %s support." % 
(bin_pkg, bin_command)]
-                               for l in msg:
-                                       writemsg_level("!!! %s\n" % l,
-                                               level=self.logger.ERROR, 
noiselevel=-1)
-                       else:
-                               self.has_bin = True
+
+
+       @property
+       def _has_bin(self):
+               '''Checks for existance of the external binary.
+
+               MUST only be called after _kwargs() has set the logger
+               '''
+               if self.bin_command is None:
+                       msg = ["Command not found: %s" % self._bin_command,
+                       "Type \"emerge %s\" to enable %s support."
+                       % (self.bin_pkg, self._bin_command)]
+                       for l in msg:
+                               writemsg_level("!!! %s\n" % l,
+                                       level=self.logger.ERROR, noiselevel=-1)
+                       return False
+               return True
 
 
        def _kwargs(self, kwargs):
@@ -106,7 +116,7 @@ class NewBase(SyncBase):
                if kwargs:
                        self._kwargs(kwargs)
 
-               if not self.has_bin:
+               if not self._has_bin:
                        return (1, False)
 
                if not self.exists():

Reply via email to