Skip to contentSkip to conversation

policycoreutils: improve sepolicy command line interface

PATCH Applied Petr Lautrbach 2 participants 2 messages Nov 16, 2015 – Nov 19, 2015 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 policycoreutils: improve sepolicy command line interface

Previously, when sepolicy was run without any argument, the usage message with the error "too few arguments" was shown. Using Python 3 it threw a traceback. This patch unifies behavior on Py2 and Py3 so that sepolicy shows the help message in this case.

Fixes:
Traceback (most recent call last):
File "/usr/bin/sepolicy", line 647, in <module>
args.func(args)
AttributeError: 'Namespace' object has no attribute 'func'

---
 policycoreutils/sepolicy/sepolicy.py | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
policycoreutils/sepolicy/sepolicy.py +5 -2
index 08a5c2f..7d57f6e 100755
@@ -685,9 +685,12 @@ if __name__ == '__main__':
 
     try:
         if os.path.basename(sys.argv[0]) == "sepolgen":
-            args = parser.parse_args(["generate"] + sys.argv[1:])
+            parser_args = [ "generate" ] + sys.argv[1:]
+        elif len(sys.argv) > 1:
+            parser_args = sys.argv[1:]
         else:
-            args = parser.parse_args()
+            parser_args = ["-h"]
+        args = parser.parse_args(args=parser_args)
         args.func(args)
         sys.exit(0)
     except ValueError, e:
Signature · 1 line
2.6.2
Applied
#1 lore raw
Quoted 5 lines · Petr Lautrbach

Previously, when sepolicy was run without any argument, the usage message with the error "too few arguments" was shown. Using Python 3 it threw a traceback. This patch unifies behavior on Py2 and Py3 so that sepolicy shows the help message in this case.

Quoted 7 lines

Fixes:
Traceback (most recent call last):

   File "/usr/bin/sepolicy", line 647, in <module>
     args.func(args)

AttributeError: 'Namespace' object has no attribute 'func'

Applied.

Thanks,
Jim

Quoted 24 lines
---
  policycoreutils/sepolicy/sepolicy.py | 7 +++++--
  1 file changed, 5 insertions(+), 2 deletions(-)
policycoreutils/sepolicy/sepolicy.py +5 -2
index 08a5c2f..7d57f6e 100755
@@ -685,9 +685,12 @@ if __name__ == '__main__':
 
      try:
          if os.path.basename(sys.argv[0]) == "sepolgen":
-            args = parser.parse_args(["generate"] + sys.argv[1:])
+            parser_args = [ "generate" ] + sys.argv[1:]
+        elif len(sys.argv) > 1:
+            parser_args = sys.argv[1:]
          else:
-            args = parser.parse_args()
+            parser_args = ["-h"]
+        args = parser.parse_args(args=parser_args)
          args.func(args)
          sys.exit(0)
      except ValueError, e:
Signature · 2 lines
James Carter <[email protected]>
National Security Agency