Skip to content

Commit d575f0b

Browse files
authored
Merge pull request #157 from pranlawate/fix-seinfo-policy-arg-parsing
Fix seinfo argument parsing when policy path follows query options
2 parents 65c0f5b + a33a2e3 commit d575f0b

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

seinfo

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import logging
1212
import signal
1313
import ipaddress
1414
import warnings
15+
from pathlib import Path
1516
from typing import Callable, List, Tuple
1617

1718

@@ -102,6 +103,18 @@ xen.add_argument("--devicetreecon", help="Print all devicetreecon statements.",
102103

103104
args = parser.parse_args()
104105

106+
# Fix argument misparsing: when policy is None and a query option is a string,
107+
# check if the string is actually a policy file that is incorrectly consumed by the query option
108+
if not args.policy:
109+
# Check all query options defined in the queries argument group
110+
for action in queries._group_actions:
111+
value = getattr(args, action.dest, None)
112+
if isinstance(value, str) and Path(value).exists():
113+
# This query argument consumed the policy path - fix it
114+
args.policy = value
115+
setattr(args, action.dest, True)
116+
break
117+
105118
if args.debug:
106119
logging.basicConfig(level=logging.DEBUG,
107120
format='%(asctime)s|%(levelname)s|%(name)s|%(message)s')

0 commit comments

Comments
 (0)