SELinux Archive on lore.kernel.org
 help / Atom feed
* [PATCH 0/3] Support flake8 version 3.7
@ 2019-01-31 21:07 Nicolas Iooss
  2019-01-31 21:07 ` [PATCH 1/3] python: reindent lines that were over-indented Nicolas Iooss
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Nicolas Iooss @ 2019-01-31 21:07 UTC (permalink / raw)
  To: selinux

flake8 3.7.0, 3.7.1, 3.7.2 and 3.7.3 were released on 2019-01-29 and
2019-01-30 (cf. http://flake8.pycqa.org/en/latest/release-notes/3.7.0.html).
These releases introduced new warnings, which broke building with
Travis-CI (cf. https://travis-ci.org/fishilico/selinux/builds/487098420).

Fix Travis-CI's builds by fixing the warnings that are now reported.
The first two commits are related to coding style and the third one is
a fix for an actual bug.


Nicolas Iooss (3):
  python: reindent lines that were over-indented
  python: use == or != when comparing a variable with a string or a
    integer
  python/sepolicy: fix variable name

 python/semanage/semanage                  | 118 ++++++------
 python/sepolgen/src/sepolgen/output.py    |   6 +-
 python/sepolgen/src/sepolgen/refparser.py |   2 +-
 python/sepolgen/src/sepolgen/yacc.py      | 214 +++++++++++-----------
 python/sepolicy/sepolicy/generate.py      |   4 +-
 python/sepolicy/sepolicy/gui.py           |   2 +-
 python/sepolicy/sepolicy/interface.py     |   8 +-
 python/sepolicy/sepolicy/manpage.py       |   4 +-
 8 files changed, 179 insertions(+), 179 deletions(-)

-- 
2.20.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/3] python: reindent lines that were over-indented
  2019-01-31 21:07 [PATCH 0/3] Support flake8 version 3.7 Nicolas Iooss
@ 2019-01-31 21:07 ` Nicolas Iooss
  2019-01-31 21:07 ` [PATCH 2/3] python: use == or != when comparing a variable with a string or a integer Nicolas Iooss
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Nicolas Iooss @ 2019-01-31 21:07 UTC (permalink / raw)
  To: selinux

Flake8 3.7.0 warns about lines that are over-indented, i.e. lines that
are indented with more than 4 spaces:

    python/sepolgen/src/sepolgen/refparser.py:1047:26: E117 over-indented
    python/sepolgen/src/sepolgen/yacc.py:2569:21: E117 over-indented
    python/sepolicy/sepolicy/interface.py:196:13: E117 over-indented
    python/sepolicy/sepolicy/interface.py:198:13: E117 over-indented
    python/sepolicy/sepolicy/interface.py:215:13: E117 over-indented
    python/sepolicy/sepolicy/interface.py:217:13: E117 over-indented
    python/sepolicy/sepolicy/manpage.py:172:13: E117 over-indented
    python/sepolicy/sepolicy/manpage.py:174:13: E117 over-indented

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
---
 python/sepolgen/src/sepolgen/refparser.py |   2 +-
 python/sepolgen/src/sepolgen/yacc.py      | 214 +++++++++++-----------
 python/sepolicy/sepolicy/interface.py     |   8 +-
 python/sepolicy/sepolicy/manpage.py       |   4 +-
 4 files changed, 114 insertions(+), 114 deletions(-)

diff --git a/python/sepolgen/src/sepolgen/refparser.py b/python/sepolgen/src/sepolgen/refparser.py
index 9fb931828278..f506dc3ae189 100644
--- a/python/sepolgen/src/sepolgen/refparser.py
+++ b/python/sepolgen/src/sepolgen/refparser.py
@@ -1044,7 +1044,7 @@ def list_headers(root):
                 if name == "obj_perm_sets.spt":
                     support_macros = filename
                 elif len(re.findall("patterns", modname[0])):
-                         modules.append((modname[0], filename))
+                    modules.append((modname[0], filename))
             elif modname[1] == '.if':
                 modules.append((modname[0], filename))
 
diff --git a/python/sepolgen/src/sepolgen/yacc.py b/python/sepolgen/src/sepolgen/yacc.py
index 88188a1e8ead..55c1ef7d8b30 100644
--- a/python/sepolgen/src/sepolgen/yacc.py
+++ b/python/sepolgen/src/sepolgen/yacc.py
@@ -2566,118 +2566,118 @@ class LRGeneratedTable(LRTable):
             log.info('')
 
             for p in I:
-                    if p.len == p.lr_index + 1:
-                        if p.name == "S'":
-                            # Start symbol. Accept!
-                            st_action['$end'] = 0
-                            st_actionp['$end'] = p
+                if p.len == p.lr_index + 1:
+                    if p.name == "S'":
+                        # Start symbol. Accept!
+                        st_action['$end'] = 0
+                        st_actionp['$end'] = p
+                    else:
+                        # We are at the end of a production.  Reduce!
+                        if self.lr_method == 'LALR':
+                            laheads = p.lookaheads[st]
                         else:
-                            # We are at the end of a production.  Reduce!
-                            if self.lr_method == 'LALR':
-                                laheads = p.lookaheads[st]
-                            else:
-                                laheads = self.grammar.Follow[p.name]
-                            for a in laheads:
-                                actlist.append((a, p, 'reduce using rule %d (%s)' % (p.number, p)))
-                                r = st_action.get(a)
-                                if r is not None:
-                                    # Whoa. Have a shift/reduce or reduce/reduce conflict
-                                    if r > 0:
-                                        # Need to decide on shift or reduce here
-                                        # By default we favor shifting. Need to add
-                                        # some precedence rules here.
-
-                                        # Shift precedence comes from the token
-                                        sprec, slevel = Precedence.get(a, ('right', 0))
-
-                                        # Reduce precedence comes from rule being reduced (p)
-                                        rprec, rlevel = Productions[p.number].prec
-
-                                        if (slevel < rlevel) or ((slevel == rlevel) and (rprec == 'left')):
-                                            # We really need to reduce here.
-                                            st_action[a] = -p.number
-                                            st_actionp[a] = p
-                                            if not slevel and not rlevel:
-                                                log.info('  ! shift/reduce conflict for %s resolved as reduce', a)
-                                                self.sr_conflicts.append((st, a, 'reduce'))
-                                            Productions[p.number].reduced += 1
-                                        elif (slevel == rlevel) and (rprec == 'nonassoc'):
-                                            st_action[a] = None
-                                        else:
-                                            # Hmmm. Guess we'll keep the shift
-                                            if not rlevel:
-                                                log.info('  ! shift/reduce conflict for %s resolved as shift', a)
-                                                self.sr_conflicts.append((st, a, 'shift'))
-                                    elif r < 0:
-                                        # Reduce/reduce conflict.   In this case, we favor the rule
-                                        # that was defined first in the grammar file
-                                        oldp = Productions[-r]
-                                        pp = Productions[p.number]
-                                        if oldp.line > pp.line:
-                                            st_action[a] = -p.number
-                                            st_actionp[a] = p
-                                            chosenp, rejectp = pp, oldp
-                                            Productions[p.number].reduced += 1
-                                            Productions[oldp.number].reduced -= 1
-                                        else:
-                                            chosenp, rejectp = oldp, pp
-                                        self.rr_conflicts.append((st, chosenp, rejectp))
-                                        log.info('  ! reduce/reduce conflict for %s resolved using rule %d (%s)',
-                                                 a, st_actionp[a].number, st_actionp[a])
+                            laheads = self.grammar.Follow[p.name]
+                        for a in laheads:
+                            actlist.append((a, p, 'reduce using rule %d (%s)' % (p.number, p)))
+                            r = st_action.get(a)
+                            if r is not None:
+                                # Whoa. Have a shift/reduce or reduce/reduce conflict
+                                if r > 0:
+                                    # Need to decide on shift or reduce here
+                                    # By default we favor shifting. Need to add
+                                    # some precedence rules here.
+
+                                    # Shift precedence comes from the token
+                                    sprec, slevel = Precedence.get(a, ('right', 0))
+
+                                    # Reduce precedence comes from rule being reduced (p)
+                                    rprec, rlevel = Productions[p.number].prec
+
+                                    if (slevel < rlevel) or ((slevel == rlevel) and (rprec == 'left')):
+                                        # We really need to reduce here.
+                                        st_action[a] = -p.number
+                                        st_actionp[a] = p
+                                        if not slevel and not rlevel:
+                                            log.info('  ! shift/reduce conflict for %s resolved as reduce', a)
+                                            self.sr_conflicts.append((st, a, 'reduce'))
+                                        Productions[p.number].reduced += 1
+                                    elif (slevel == rlevel) and (rprec == 'nonassoc'):
+                                        st_action[a] = None
+                                    else:
+                                        # Hmmm. Guess we'll keep the shift
+                                        if not rlevel:
+                                            log.info('  ! shift/reduce conflict for %s resolved as shift', a)
+                                            self.sr_conflicts.append((st, a, 'shift'))
+                                elif r < 0:
+                                    # Reduce/reduce conflict.   In this case, we favor the rule
+                                    # that was defined first in the grammar file
+                                    oldp = Productions[-r]
+                                    pp = Productions[p.number]
+                                    if oldp.line > pp.line:
+                                        st_action[a] = -p.number
+                                        st_actionp[a] = p
+                                        chosenp, rejectp = pp, oldp
+                                        Productions[p.number].reduced += 1
+                                        Productions[oldp.number].reduced -= 1
                                     else:
-                                        raise LALRError('Unknown conflict in state %d' % st)
+                                        chosenp, rejectp = oldp, pp
+                                    self.rr_conflicts.append((st, chosenp, rejectp))
+                                    log.info('  ! reduce/reduce conflict for %s resolved using rule %d (%s)',
+                                             a, st_actionp[a].number, st_actionp[a])
                                 else:
-                                    st_action[a] = -p.number
-                                    st_actionp[a] = p
-                                    Productions[p.number].reduced += 1
-                    else:
-                        i = p.lr_index
-                        a = p.prod[i+1]       # Get symbol right after the "."
-                        if a in self.grammar.Terminals:
-                            g = self.lr0_goto(I, a)
-                            j = self.lr0_cidhash.get(id(g), -1)
-                            if j >= 0:
-                                # We are in a shift state
-                                actlist.append((a, p, 'shift and go to state %d' % j))
-                                r = st_action.get(a)
-                                if r is not None:
-                                    # Whoa have a shift/reduce or shift/shift conflict
-                                    if r > 0:
-                                        if r != j:
-                                            raise LALRError('Shift/shift conflict in state %d' % st)
-                                    elif r < 0:
-                                        # Do a precedence check.
-                                        #   -  if precedence of reduce rule is higher, we reduce.
-                                        #   -  if precedence of reduce is same and left assoc, we reduce.
-                                        #   -  otherwise we shift
-
-                                        # Shift precedence comes from the token
-                                        sprec, slevel = Precedence.get(a, ('right', 0))
-
-                                        # Reduce precedence comes from the rule that could have been reduced
-                                        rprec, rlevel = Productions[st_actionp[a].number].prec
-
-                                        if (slevel > rlevel) or ((slevel == rlevel) and (rprec == 'right')):
-                                            # We decide to shift here... highest precedence to shift
-                                            Productions[st_actionp[a].number].reduced -= 1
-                                            st_action[a] = j
-                                            st_actionp[a] = p
-                                            if not rlevel:
-                                                log.info('  ! shift/reduce conflict for %s resolved as shift', a)
-                                                self.sr_conflicts.append((st, a, 'shift'))
-                                        elif (slevel == rlevel) and (rprec == 'nonassoc'):
-                                            st_action[a] = None
-                                        else:
-                                            # Hmmm. Guess we'll keep the reduce
-                                            if not slevel and not rlevel:
-                                                log.info('  ! shift/reduce conflict for %s resolved as reduce', a)
-                                                self.sr_conflicts.append((st, a, 'reduce'))
-
+                                    raise LALRError('Unknown conflict in state %d' % st)
+                            else:
+                                st_action[a] = -p.number
+                                st_actionp[a] = p
+                                Productions[p.number].reduced += 1
+                else:
+                    i = p.lr_index
+                    a = p.prod[i+1]       # Get symbol right after the "."
+                    if a in self.grammar.Terminals:
+                        g = self.lr0_goto(I, a)
+                        j = self.lr0_cidhash.get(id(g), -1)
+                        if j >= 0:
+                            # We are in a shift state
+                            actlist.append((a, p, 'shift and go to state %d' % j))
+                            r = st_action.get(a)
+                            if r is not None:
+                                # Whoa have a shift/reduce or shift/shift conflict
+                                if r > 0:
+                                    if r != j:
+                                        raise LALRError('Shift/shift conflict in state %d' % st)
+                                elif r < 0:
+                                    # Do a precedence check.
+                                    #   -  if precedence of reduce rule is higher, we reduce.
+                                    #   -  if precedence of reduce is same and left assoc, we reduce.
+                                    #   -  otherwise we shift
+
+                                    # Shift precedence comes from the token
+                                    sprec, slevel = Precedence.get(a, ('right', 0))
+
+                                    # Reduce precedence comes from the rule that could have been reduced
+                                    rprec, rlevel = Productions[st_actionp[a].number].prec
+
+                                    if (slevel > rlevel) or ((slevel == rlevel) and (rprec == 'right')):
+                                        # We decide to shift here... highest precedence to shift
+                                        Productions[st_actionp[a].number].reduced -= 1
+                                        st_action[a] = j
+                                        st_actionp[a] = p
+                                        if not rlevel:
+                                            log.info('  ! shift/reduce conflict for %s resolved as shift', a)
+                                            self.sr_conflicts.append((st, a, 'shift'))
+                                    elif (slevel == rlevel) and (rprec == 'nonassoc'):
+                                        st_action[a] = None
                                     else:
-                                        raise LALRError('Unknown conflict in state %d' % st)
+                                        # Hmmm. Guess we'll keep the reduce
+                                        if not slevel and not rlevel:
+                                            log.info('  ! shift/reduce conflict for %s resolved as reduce', a)
+                                            self.sr_conflicts.append((st, a, 'reduce'))
+
                                 else:
-                                    st_action[a] = j
-                                    st_actionp[a] = p
+                                    raise LALRError('Unknown conflict in state %d' % st)
+                            else:
+                                st_action[a] = j
+                                st_actionp[a] = p
 
             # Print the actions associated with each terminal
             _actprint = {}
diff --git a/python/sepolicy/sepolicy/interface.py b/python/sepolicy/sepolicy/interface.py
index 18374dcfed96..27c37bb8e1f8 100644
--- a/python/sepolicy/sepolicy/interface.py
+++ b/python/sepolicy/sepolicy/interface.py
@@ -193,9 +193,9 @@ def get_xml_file(if_file):
     """ Returns xml format of interfaces for given .if policy file"""
     import os
     try:
-            from commands import getstatusoutput
+        from commands import getstatusoutput
     except ImportError:
-            from subprocess import getstatusoutput
+        from subprocess import getstatusoutput
     basedir = os.path.dirname(if_file) + "/"
     filename = os.path.basename(if_file).split(".")[0]
     rc, output = getstatusoutput("python /usr/share/selinux/devel/include/support/segenxml.py -w -m %s" % basedir + filename)
@@ -212,9 +212,9 @@ def interface_compile_test(interface, path="/usr/share/selinux/devel/policy.xml"
     exclude_interface_type = ["template"]
 
     try:
-            from commands import getstatusoutput
+        from commands import getstatusoutput
     except ImportError:
-            from subprocess import getstatusoutput
+        from subprocess import getstatusoutput
     import os
     policy_files = {'pp': "compiletest.pp", 'te': "compiletest.te", 'fc': "compiletest.fc", 'if': "compiletest.if"}
     idict = get_interface_dict(path)
diff --git a/python/sepolicy/sepolicy/manpage.py b/python/sepolicy/sepolicy/manpage.py
index cfcb7c3932d7..af18b6ffc12f 100755
--- a/python/sepolicy/sepolicy/manpage.py
+++ b/python/sepolicy/sepolicy/manpage.py
@@ -169,9 +169,9 @@ def get_alphabet_manpages(manpage_list):
 
 def convert_manpage_to_html(html_manpage, manpage):
     try:
-            from commands import getstatusoutput
+        from commands import getstatusoutput
     except ImportError:
-            from subprocess import getstatusoutput
+        from subprocess import getstatusoutput
     rc, output = getstatusoutput("/usr/bin/groff -man -Thtml %s 2>/dev/null" % manpage)
     if rc == 0:
         print(html_manpage, "has been created")
-- 
2.20.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 2/3] python: use == or != when comparing a variable with a string or a integer
  2019-01-31 21:07 [PATCH 0/3] Support flake8 version 3.7 Nicolas Iooss
  2019-01-31 21:07 ` [PATCH 1/3] python: reindent lines that were over-indented Nicolas Iooss
@ 2019-01-31 21:07 ` Nicolas Iooss
  2019-01-31 21:07 ` [PATCH 3/3] python/sepolicy: fix variable name Nicolas Iooss
  2019-02-04 15:21 ` [PATCH 0/3] Support flake8 version 3.7 Petr Lautrbach
  3 siblings, 0 replies; 6+ messages in thread
From: Nicolas Iooss @ 2019-01-31 21:07 UTC (permalink / raw)
  To: selinux

Flake8 3.7.0 added a new fatal error message when parsing Python files:

    python/semanage/semanage:112:16: F632 use ==/!= to compare str, bytes, and int literals
    python/semanage/semanage:124:23: F632 use ==/!= to compare str, bytes, and int literals
    ...
    python/sepolgen/src/sepolgen/output.py:77:8: F632 use ==/!= to compare str, bytes, and int literals
    python/sepolgen/src/sepolgen/output.py:80:8: F632 use ==/!= to compare str, bytes, and int literals
    python/sepolgen/src/sepolgen/output.py:83:8: F632 use ==/!= to compare str, bytes, and int literals
    python/sepolicy/sepolicy/generate.py:646:16: F632 use ==/!= to compare str, bytes, and int literals
    python/sepolicy/sepolicy/generate.py:1349:16: F632 use ==/!= to compare str, bytes, and int literals

Fix all these warnings.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
---
 python/semanage/semanage               | 118 ++++++++++++-------------
 python/sepolgen/src/sepolgen/output.py |   6 +-
 python/sepolicy/sepolicy/generate.py   |   4 +-
 3 files changed, 64 insertions(+), 64 deletions(-)

diff --git a/python/semanage/semanage b/python/semanage/semanage
index 49add51ec24e..6afeac140b08 100644
--- a/python/semanage/semanage
+++ b/python/semanage/semanage
@@ -109,7 +109,7 @@ class SetExportFile(argparse.Action):
 
     def __call__(self, parser, namespace, values, option_string=None):
         if values:
-            if values is not "-":
+            if values != "-":
                 try:
                     sys.stdout = open(values, 'w')
                 except:
@@ -121,7 +121,7 @@ class SetExportFile(argparse.Action):
 class SetImportFile(argparse.Action):
 
     def __call__(self, parser, namespace, values, option_string=None):
-        if values and values is not "-":
+        if values and values != "-":
             try:
                 sys.stdin = open(values, 'r')
             except IOError as e:
@@ -189,17 +189,17 @@ def handleLogin(args):
 
     OBJECT = object_dict['login'](args)
 
-    if args.action is "add":
+    if args.action == "add":
         OBJECT.add(args.login, args.seuser, args.range)
-    if args.action is "modify":
+    if args.action == "modify":
         OBJECT.modify(args.login, args.seuser, args.range)
-    if args.action is "delete":
+    if args.action == "delete":
         OBJECT.delete(args.login)
-    if args.action is "list":
+    if args.action == "list":
         OBJECT.list(args.noheading, args.locallist)
-    if args.action is "deleteall":
+    if args.action == "deleteall":
         OBJECT.deleteall()
-    if args.action is "extract":
+    if args.action == "extract":
         for i in OBJECT.customized():
             print("login %s" % (str(i)))
 
@@ -322,26 +322,26 @@ def handleFcontext(args):
 
     OBJECT = object_dict['fcontext'](args)
 
-    if args.action is "add":
+    if args.action == "add":
         if args.equal:
             OBJECT.add_equal(args.file_spec, args.equal)
         else:
             OBJECT.add(args.file_spec, args.type, args.ftype, args.range, args.seuser)
-    if args.action is "modify":
+    if args.action == "modify":
         if args.equal:
             OBJECT.add_equal(args.file_spec, args.equal)
         else:
             OBJECT.modify(args.file_spec, args.type, args.ftype, args.range, args.seuser)
-    if args.action is "delete":
+    if args.action == "delete":
         if args.equal:
             OBJECT.delete(args.file_spec, args.equal)
         else:
             OBJECT.delete(args.file_spec, args.ftype)
-    if args.action is "list":
+    if args.action == "list":
         OBJECT.list(args.noheading, args.locallist)
-    if args.action is "deleteall":
+    if args.action == "deleteall":
         OBJECT.deleteall()
-    if args.action is "extract":
+    if args.action == "extract":
         for i in OBJECT.customized():
             print("fcontext %s" % str(i))
 
@@ -390,17 +390,17 @@ def handleUser(args):
 
     OBJECT = object_dict['user'](args)
 
-    if args.action is "add":
+    if args.action == "add":
         OBJECT.add(args.selinux_name, args.roles, args.level, args.range, args.prefix)
-    if args.action is "modify":
+    if args.action == "modify":
         OBJECT.modify(args.selinux_name, args.roles, args.level, args.range, args.prefix)
-    if args.action is "delete":
+    if args.action == "delete":
         OBJECT.delete(args.selinux_name)
-    if args.action is "list":
+    if args.action == "list":
         OBJECT.list(args.noheading, args.locallist)
-    if args.action is "deleteall":
+    if args.action == "deleteall":
         OBJECT.deleteall()
-    if args.action is "extract":
+    if args.action == "extract":
         for i in OBJECT.customized():
             print("user %s" % str(i))
 
@@ -440,17 +440,17 @@ def handlePort(args):
 
     OBJECT = object_dict['port'](args)
 
-    if args.action is "add":
+    if args.action == "add":
         OBJECT.add(args.port, args.proto, args.range, args.type)
-    if args.action is "modify":
+    if args.action == "modify":
         OBJECT.modify(args.port, args.proto, args.range, args.type)
-    if args.action is "delete":
+    if args.action == "delete":
         OBJECT.delete(args.port, args.proto)
-    if args.action is "list":
+    if args.action == "list":
         OBJECT.list(args.noheading, args.locallist)
-    if args.action is "deleteall":
+    if args.action == "deleteall":
         OBJECT.deleteall()
-    if args.action is "extract":
+    if args.action == "extract":
         for i in OBJECT.customized():
             print("port %s" % str(i))
 
@@ -485,17 +485,17 @@ def handlePkey(args):
 
     OBJECT = object_dict['ibpkey'](args)
 
-    if args.action is "add":
+    if args.action == "add":
         OBJECT.add(args.ibpkey, args.subnet_prefix, args.range, args.type)
-    if args.action is "modify":
+    if args.action == "modify":
         OBJECT.modify(args.ibpkey, args.subnet_prefix, args.range, args.type)
-    if args.action is "delete":
+    if args.action == "delete":
         OBJECT.delete(args.ibpkey, args.subnet_prefix)
-    if args.action is "list":
+    if args.action == "list":
         OBJECT.list(args.noheading, args.locallist)
-    if args.action is "deleteall":
+    if args.action == "deleteall":
         OBJECT.deleteall()
-    if args.action is "extract":
+    if args.action == "extract":
         for i in OBJECT.customized():
             print("ibpkey %s" % str(i))
 
@@ -528,17 +528,17 @@ def handleIbendport(args):
 
     OBJECT = object_dict['ibendport'](args)
 
-    if args.action is "add":
+    if args.action == "add":
         OBJECT.add(args.ibendport, args.ibdev_name, args.range, args.type)
-    if args.action is "modify":
+    if args.action == "modify":
         OBJECT.modify(args.ibendport, args.ibdev_name, args.range, args.type)
-    if args.action is "delete":
+    if args.action == "delete":
         OBJECT.delete(args.ibendport, args.ibdev_name)
-    if args.action is "list":
+    if args.action == "list":
         OBJECT.list(args.noheading, args.locallist)
-    if args.action is "deleteall":
+    if args.action == "deleteall":
         OBJECT.deleteall()
-    if args.action is "extract":
+    if args.action == "extract":
         for i in OBJECT.customized():
             print("ibendport %s" % str(i))
 
@@ -571,17 +571,17 @@ def handleInterface(args):
 
     OBJECT = object_dict['interface'](args)
 
-    if args.action is "add":
+    if args.action == "add":
         OBJECT.add(args.interface, args.range, args.type)
-    if args.action is "modify":
+    if args.action == "modify":
         OBJECT.modify(args.interface, args.range, args.type)
-    if args.action is "delete":
+    if args.action == "delete":
         OBJECT.delete(args.interface)
-    if args.action is "list":
+    if args.action == "list":
         OBJECT.list(args.noheading, args.locallist)
-    if args.action is "deleteall":
+    if args.action == "deleteall":
         OBJECT.deleteall()
-    if args.action is "extract":
+    if args.action == "extract":
         for i in OBJECT.customized():
             print("interface %s" % str(i))
 
@@ -617,11 +617,11 @@ def handleModule(args):
         OBJECT.set_enabled(args.module_name, False)
     if args.action == "remove":
         OBJECT.delete(args.module_name, args.priority)
-    if args.action is "deleteall":
+    if args.action == "deleteall":
         OBJECT.deleteall()
     if args.action == "list":
         OBJECT.list(args.noheading, args.locallist)
-    if args.action is "extract":
+    if args.action == "extract":
         for i in OBJECT.customized():
             print("module %s" % str(i))
 
@@ -652,17 +652,17 @@ def handleNode(args):
 
     OBJECT = object_dict['node'](args)
 
-    if args.action is "add":
+    if args.action == "add":
         OBJECT.add(args.node, args.netmask, args.proto, args.range, args.type)
-    if args.action is "modify":
+    if args.action == "modify":
         OBJECT.modify(args.node, args.netmask, args.proto, args.range, args.type)
-    if args.action is "delete":
+    if args.action == "delete":
         OBJECT.delete(args.node, args.netmask, args.proto)
-    if args.action is "list":
+    if args.action == "list":
         OBJECT.list(args.noheading, args.locallist)
-    if args.action is "deleteall":
+    if args.action == "deleteall":
         OBJECT.deleteall()
-    if args.action is "extract":
+    if args.action == "extract":
         for i in OBJECT.customized():
             print("node %s" % str(i))
 
@@ -698,14 +698,14 @@ def handleBoolean(args):
 
     OBJECT = object_dict['boolean'](args)
 
-    if args.action is "modify":
+    if args.action == "modify":
         if args.boolean:
             OBJECT.modify(args.boolean, args.state, False)
-    if args.action is "list":
+    if args.action == "list":
         OBJECT.list(args.noheading, args.locallist)
-    if args.action is "deleteall":
+    if args.action == "deleteall":
         OBJECT.deleteall()
-    if args.action is "extract":
+    if args.action == "extract":
         for i in OBJECT.customized():
             print("boolean %s" % str(i))
 
@@ -736,12 +736,12 @@ def setupBooleanParser(subparsers):
 def handlePermissive(args):
     OBJECT = object_dict['permissive'](args)
 
-    if args.action is "list":
+    if args.action == "list":
         OBJECT.list(args.noheading)
     elif args.type is not None:
-        if args.action is "add":
+        if args.action == "add":
             OBJECT.add(args.type)
-        if args.action is "delete":
+        if args.action == "delete":
             OBJECT.delete(args.type)
     else:
         args.parser.print_usage(sys.stderr)
diff --git a/python/sepolgen/src/sepolgen/output.py b/python/sepolgen/src/sepolgen/output.py
index 7a83aee407cf..3a21b64c19f7 100644
--- a/python/sepolgen/src/sepolgen/output.py
+++ b/python/sepolgen/src/sepolgen/output.py
@@ -74,13 +74,13 @@ def id_set_cmp(x, y):
 # Compare two avrules
 def avrule_cmp(a, b):
     ret = id_set_cmp(a.src_types, b.src_types)
-    if ret is not 0:
+    if ret != 0:
         return ret
     ret = id_set_cmp(a.tgt_types, b.tgt_types)
-    if ret is not 0:
+    if ret != 0:
         return ret
     ret = id_set_cmp(a.obj_classes, b.obj_classes)
-    if ret is not 0:
+    if ret != 0:
         return ret
 
     # At this point, who cares - just return something
diff --git a/python/sepolicy/sepolicy/generate.py b/python/sepolicy/sepolicy/generate.py
index 37ddfc7a2d63..5a2195b8033f 100644
--- a/python/sepolicy/sepolicy/generate.py
+++ b/python/sepolicy/sepolicy/generate.py
@@ -643,7 +643,7 @@ allow %s_t %s_t:%s_socket name_%s;
 
     def __find_path(self, file):
         for d in self.DEFAULT_DIRS:
-            if file.find(d) is 0:
+            if file.find(d) == 0:
                 self.DEFAULT_DIRS[d][1].append(file)
                 return self.DEFAULT_DIRS[d]
         self.DEFAULT_DIRS["rw"][1].append(file)
@@ -1346,7 +1346,7 @@ allow %s_t %s_t:%s_socket name_%s;
                 else:
                     continue
 
-            if len(temp_dirs) is not 0:
+            if len(temp_dirs) != 0:
                 for i in temp_dirs:
                     if i in self.dirs.keys():
                         del(self.dirs[i])
-- 
2.20.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 3/3] python/sepolicy: fix variable name
  2019-01-31 21:07 [PATCH 0/3] Support flake8 version 3.7 Nicolas Iooss
  2019-01-31 21:07 ` [PATCH 1/3] python: reindent lines that were over-indented Nicolas Iooss
  2019-01-31 21:07 ` [PATCH 2/3] python: use == or != when comparing a variable with a string or a integer Nicolas Iooss
@ 2019-01-31 21:07 ` Nicolas Iooss
  2019-02-04 15:21 ` [PATCH 0/3] Support flake8 version 3.7 Petr Lautrbach
  3 siblings, 0 replies; 6+ messages in thread
From: Nicolas Iooss @ 2019-01-31 21:07 UTC (permalink / raw)
  To: selinux

modify_button_clicked() used variable "type" in a comparison instead of
"ftype". This is a bug, which has been found with flake8 3.7.0. This
linter reported:

    python/sepolicy/sepolicy/gui.py:1548:20: F823 local variable 'type'
    {0} referenced before assignment

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
---
 python/sepolicy/sepolicy/gui.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/python/sepolicy/sepolicy/gui.py b/python/sepolicy/sepolicy/gui.py
index fde233ad98b1..d4bf3b48e629 100644
--- a/python/sepolicy/sepolicy/gui.py
+++ b/python/sepolicy/sepolicy/gui.py
@@ -1545,7 +1545,7 @@ class SELinuxGui():
                 path = self.executable_files_liststore.get_value(iter, 0)
                 self.files_path_entry.set_text(path)
                 ftype = self.executable_files_liststore.get_value(iter, 1)
-                if type != None:
+                if ftype != None:
                     self.combo_set_active_text(self.files_type_combobox, ftype)
                 tclass = self.executable_files_liststore.get_value(iter, 2)
                 if tclass != None:
-- 
2.20.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/3] Support flake8 version 3.7
  2019-01-31 21:07 [PATCH 0/3] Support flake8 version 3.7 Nicolas Iooss
                   ` (2 preceding siblings ...)
  2019-01-31 21:07 ` [PATCH 3/3] python/sepolicy: fix variable name Nicolas Iooss
@ 2019-02-04 15:21 ` Petr Lautrbach
  2019-02-04 19:22   ` Nicolas Iooss
  3 siblings, 1 reply; 6+ messages in thread
From: Petr Lautrbach @ 2019-02-04 15:21 UTC (permalink / raw)
  To: Nicolas Iooss; +Cc: selinux


flake8 3.7.0, 3.7.1, 3.7.2 and 3.7.3 were released on 2019-01-29 and
2019-01-30 (cf. http://flake8.pycqa.org/en/latest/release-notes/3.7.0.html).
These releases introduced new warnings, which broke building with
Travis-CI (cf. https://travis-ci.org/fishilico/selinux/builds/487098420).

Fix Travis-CI's builds by fixing the warnings that are now reported.
The first two commits are related to coding style and the third one is
a fix for an actual bug.


Nicolas Iooss (3):
  python: reindent lines that were over-indented
  python: use == or != when comparing a variable with a string or a
    integer
  python/sepolicy: fix variable name

 python/semanage/semanage                  | 118 ++++++------
 python/sepolgen/src/sepolgen/output.py    |   6 +-
 python/sepolgen/src/sepolgen/refparser.py |   2 +-
 python/sepolgen/src/sepolgen/yacc.py      | 214 +++++++++++-----------
 python/sepolicy/sepolicy/generate.py      |   4 +-
 python/sepolicy/sepolicy/gui.py           |   2 +-
 python/sepolicy/sepolicy/interface.py     |   8 +-
 python/sepolicy/sepolicy/manpage.py       |   4 +-
 8 files changed, 179 insertions(+), 179 deletions(-)



Acked-by: Petr Lautrbach <plautrba@redhat.com>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/3] Support flake8 version 3.7
  2019-02-04 15:21 ` [PATCH 0/3] Support flake8 version 3.7 Petr Lautrbach
@ 2019-02-04 19:22   ` Nicolas Iooss
  0 siblings, 0 replies; 6+ messages in thread
From: Nicolas Iooss @ 2019-02-04 19:22 UTC (permalink / raw)
  To: Petr Lautrbach; +Cc: selinux

On Mon, Feb 4, 2019 at 4:21 PM Petr Lautrbach <plautrba@redhat.com> wrote:
>
> flake8 3.7.0, 3.7.1, 3.7.2 and 3.7.3 were released on 2019-01-29 and
> 2019-01-30 (cf. http://flake8.pycqa.org/en/latest/release-notes/3.7.0.html).
> These releases introduced new warnings, which broke building with
> Travis-CI (cf. https://travis-ci.org/fishilico/selinux/builds/487098420).
>
> Fix Travis-CI's builds by fixing the warnings that are now reported.
> The first two commits are related to coding style and the third one is
> a fix for an actual bug.
>
>
> Nicolas Iooss (3):
>   python: reindent lines that were over-indented
>   python: use == or != when comparing a variable with a string or a
>     integer
>   python/sepolicy: fix variable name
>
>  python/semanage/semanage                  | 118 ++++++------
>  python/sepolgen/src/sepolgen/output.py    |   6 +-
>  python/sepolgen/src/sepolgen/refparser.py |   2 +-
>  python/sepolgen/src/sepolgen/yacc.py      | 214 +++++++++++-----------
>  python/sepolicy/sepolicy/generate.py      |   4 +-
>  python/sepolicy/sepolicy/gui.py           |   2 +-
>  python/sepolicy/sepolicy/interface.py     |   8 +-
>  python/sepolicy/sepolicy/manpage.py       |   4 +-
>  8 files changed, 179 insertions(+), 179 deletions(-)
>
>
>
> Acked-by: Petr Lautrbach <plautrba@redhat.com>

Thanks, merged.

Nicolas


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, back to index

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-31 21:07 [PATCH 0/3] Support flake8 version 3.7 Nicolas Iooss
2019-01-31 21:07 ` [PATCH 1/3] python: reindent lines that were over-indented Nicolas Iooss
2019-01-31 21:07 ` [PATCH 2/3] python: use == or != when comparing a variable with a string or a integer Nicolas Iooss
2019-01-31 21:07 ` [PATCH 3/3] python/sepolicy: fix variable name Nicolas Iooss
2019-02-04 15:21 ` [PATCH 0/3] Support flake8 version 3.7 Petr Lautrbach
2019-02-04 19:22   ` Nicolas Iooss

SELinux Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/selinux/0 selinux/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 selinux selinux/ https://lore.kernel.org/selinux \
		selinux@vger.kernel.org selinux@archiver.kernel.org
	public-inbox-index selinux


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.selinux


AGPL code for this site: git clone https://public-inbox.org/ public-inbox