commit:     3dc78ff91eccd81c972ceadf59d059aabe9ccdbc
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Tue Mar 15 18:40:06 2016 +0000
Commit:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Mon Apr 25 15:28:53 2016 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=3dc78ff9

repoman: Create a new boolean Fuse type

Create a Fuse type which implememts a boolean as a one time fuse.
The Fuse is initialized True, then is pop()'d to become False.
Once the Fuse is blown, it can not be reset to True.
Convert the use of the dynamic_data variable 'allvalid' to a Fuse instance.

 pym/repoman/fuse.py                         | 68 +++++++++++++++++++++++++++++
 pym/repoman/modules/scan/ebuild/ebuild.py   |  7 ++-
 pym/repoman/modules/scan/ebuild/isebuild.py | 13 +++---
 pym/repoman/modules/scan/metadata/unused.py |  2 +-
 pym/repoman/scanner.py                      |  2 +
 5 files changed, 83 insertions(+), 9 deletions(-)

diff --git a/pym/repoman/fuse.py b/pym/repoman/fuse.py
new file mode 100644
index 0000000..ac864fd
--- /dev/null
+++ b/pym/repoman/fuse.py
@@ -0,0 +1,68 @@
+
+'''
+fuse.py
+
+A tiny one-time-fuse class that uses a boolean to mimic the property of
+an electrical fuse.  IT's good (True) until it is popped (bad, False).
+It is not resetable.
+'''
+
+
+class Fuse(object):
+       '''A One time fuse style boolean instance'''
+
+       __slots__ = ('_state')
+
+       def __init__(self):
+               self._state = True
+
+       def pop(self):
+               '''Blow's the fuse state (makes it False)'''
+               self._state = False
+
+       def __repr__(self):
+               '''x.__repr__() <==> repr(x)'''
+               return repr(self._state>0)
+
+       def __str__(self):
+               '''x.__str__() <==> str(x)'''
+               return ['False', 'True'][self._state]
+
+       def __bool__(self):
+               '''self != 0'''
+               return self._state != 0
+
+       def __nonzero__(self):
+               '''self != 0'''
+               return self._state != 0
+
+       def __abs__(self):
+               '''x.__abs__() <==> abs(x)'''
+               return [0, 1] [self._state]
+
+       def __int__(self):
+               '''int(self)'''
+               return [0, 1][self._state]
+
+       def __eq__(self, value):
+               '''Return self==value.'''
+               return self._state == value
+
+       def __ne__(self, value):
+               '''Return self!=value.'''
+               return self._state != value
+
+       def __ge__(self, value):
+               '''Return self>=value.'''
+               return self._state >= value
+
+       def __gt__(self, value):
+               return self._state > value
+
+       def __le__(self, value):
+               '''Return self<=value.'''
+               return self._state <= value
+
+       def __lt__(self, value):
+               '''Return self<value.'''
+               return self._state < value

diff --git a/pym/repoman/modules/scan/ebuild/ebuild.py 
b/pym/repoman/modules/scan/ebuild/ebuild.py
index e9a2cdd..540411f 100644
--- a/pym/repoman/modules/scan/ebuild/ebuild.py
+++ b/pym/repoman/modules/scan/ebuild/ebuild.py
@@ -127,13 +127,16 @@ class Ebuild(ScanBase):
        def pkg_invalid(self, **kwargs):
                '''Sets some pkg info and checks for invalid packages
 
-               @returns: dictionary, including {pkg object, allvalid}
+               @param validity_fuse: Fuse instance
+               @returns: dictionary, including {pkg object}
                '''
+               fuse = kwargs.get('validity_fuse')
                if self.pkg.invalid:
                        for k, msgs in self.pkg.invalid.items():
                                for msg in msgs:
                                        self.qatracker.add_error(k, "%s: %s" % 
(self.relative_path, msg))
-                       return {'continue': True, 'allvalid': False, 'pkg': 
self.pkg}
+                       fuse.pop()
+                       return {'continue': True, 'pkg': self.pkg}
                return {'continue': False, 'pkg': self.pkg}
 
        @property

diff --git a/pym/repoman/modules/scan/ebuild/isebuild.py 
b/pym/repoman/modules/scan/ebuild/isebuild.py
index 1dffc6a..474a874 100644
--- a/pym/repoman/modules/scan/ebuild/isebuild.py
+++ b/pym/repoman/modules/scan/ebuild/isebuild.py
@@ -35,15 +35,16 @@ class IsEbuild(ScanBase):
                @param checkdirlist: list of files in the current package 
directory
                @param checkdir: current package directory path
                @param xpkg: current package directory being checked
-               @returns: dictionary, including {pkgs, allvalid, can_force}
+               @param validity_fuse: Fuse instance
+               @returns: dictionary, including {pkgs, can_force}
                '''
                checkdirlist = kwargs.get('checkdirlist')
                checkdir = kwargs.get('checkdir')
                xpkg = kwargs.get('xpkg')
+               fuse = kwargs.get('validity_fuse')
                self.continue_ = False
                ebuildlist = []
                pkgs = {}
-               allvalid = True
                for y in checkdirlist:
                        file_is_ebuild = y.endswith(".ebuild")
                        file_should_be_non_executable = y in no_exec or 
file_is_ebuild
@@ -62,15 +63,15 @@ class IsEbuild(ScanBase):
                                try:
                                        myaux = dict(zip(allvars, 
self.portdb.aux_get(cpv, allvars)))
                                except KeyError:
-                                       allvalid = False
+                                       fuse.pop()
                                        
self.qatracker.add_error("ebuild.syntax", os.path.join(xpkg, y))
                                        continue
                                except IOError:
-                                       allvalid = False
+                                       fuse.pop()
                                        
self.qatracker.add_error("ebuild.output", os.path.join(xpkg, y))
                                        continue
                                if not portage.eapi_is_supported(myaux["EAPI"]):
-                                       allvalid = False
+                                       fuse.pop()
                                        
self.qatracker.add_error("EAPI.unsupported", os.path.join(xpkg, y))
                                        continue
                                pkgs[pf] = Package(
@@ -85,7 +86,7 @@ class IsEbuild(ScanBase):
                        # positives confuse users.
                        self.continue_ = True
 
-               return {'continue': self.continue_, 'pkgs': pkgs, 'allvalid': 
allvalid,
+               return {'continue': self.continue_, 'pkgs': pkgs,
                        'can_force': not self.continue_}
 
        @property

diff --git a/pym/repoman/modules/scan/metadata/unused.py 
b/pym/repoman/modules/scan/metadata/unused.py
index 2ca7466..9ff7e56 100644
--- a/pym/repoman/modules/scan/metadata/unused.py
+++ b/pym/repoman/modules/scan/metadata/unused.py
@@ -13,7 +13,7 @@ class UnusedCheck(ScanBase):
                used_useflags = kwargs.get('used_useflags')
                # check if there are unused local USE-descriptions in 
metadata.xml
                # (unless there are any invalids, to avoid noise)
-               if kwargs.get('allvalid'):
+               if kwargs.get('validity_fuse'):
                        for myflag in muselist.difference(used_useflags):
                                self.qatracker.add_error(
                                        "metadata.warning",

diff --git a/pym/repoman/scanner.py b/pym/repoman/scanner.py
index 86e389a..9c6f5ac 100644
--- a/pym/repoman/scanner.py
+++ b/pym/repoman/scanner.py
@@ -9,6 +9,7 @@ import portage
 from portage import normalize_path
 from portage import os
 from portage.output import green
+from repoman.fuse import Fuse
 from repoman.modules.commit import repochecks
 from repoman.profile import check_profiles, dev_profile_keywords, setup_profile
 from repoman.repos import repo_metadata
@@ -232,6 +233,7 @@ class Scanner(object):
                                'repolevel': self.repolevel,
                                'catdir': catdir,
                                'pkgdir': pkgdir,
+                               'validity_fuse': Fuse()
                                }
                        # need to set it up for ==> self.modules or some other 
ordered list
                        for mod in ['Manifests', 'IsEbuild', 'KeywordChecks', 
'FileChecks',

Reply via email to