-
Notifications
You must be signed in to change notification settings - Fork 219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(systemextensionsctl): add functionality #597
Open
georgettica
wants to merge
16
commits into
kellyjonbrazil:dev
Choose a base branch
from
georgettica:georgettica/feat/systemextensionsctl
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+433
−0
Open
Changes from 4 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
abda873
Merge pull request #551 from kellyjonbrazil/dev
kellyjonbrazil 5f8c65c
Merge branch 'dev'
kellyjonbrazil 6a1a73c
feat(systemextensionsctl): add functionality
georgettica 48b0313
Merge branch 'dev' into georgettica/feat/systemextensionsctl
kellyjonbrazil 91ae7e5
fix: shorten and add email
georgettica 467afcd
Update systemextensionsctl.py
georgettica 99fbe4b
just add tests that fail
georgettica 4819f0d
add test data and change a bit test code
georgettica 18f01b4
Merge branch 'dev' into georgettica/feat/systemextensionsctl
georgettica 1525b33
forgot to remove empty reads
georgettica 03de306
revamped to make tests pass
georgettica fdb18e3
review notes
georgettica 912b3e5
filename typo
georgettica 901c047
Update systemextensionsctl.py
georgettica 203762e
Merge branch 'dev' into georgettica/feat/systemextensionsctl
kellyjonbrazil 23ef46c
Merge branch 'dev' into georgettica/feat/systemextensionsctl
kellyjonbrazil File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
"""jc - JSON Convert `systemextensionsctl list` command output parser | ||
|
||
Usage: | ||
|
||
$ systemextensionsctl list | jc --systemextensionsctl-list | ||
georgettica marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Compatibility: | ||
|
||
macOS | ||
Comment on lines
+7
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't need this section |
||
|
||
Example: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing a Schema section |
||
|
||
$ systemextensionsctl list | jc --systemextensionsctl-list -p | ||
{ | ||
"total_extensions": 1, | ||
"sections": [ | ||
{ | ||
"category": "com.apple.system_extension.network_extension", | ||
"description": "Go to 'System Settings > General > Login Items & Extensions > Network Extensions' to modify these system extension(s)", | ||
"entries": [ | ||
{ | ||
"enabled": "*", | ||
"active": "*", | ||
"teamID": "XXX", | ||
"bundleID": "YYY", | ||
"version": "QQQ", | ||
"name": "ZZZ", | ||
"state": "activated enabled" | ||
georgettica marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
] | ||
}, | ||
|
||
] | ||
} | ||
|
||
""" | ||
|
||
import jc.utils | ||
import jc.parsers.universal | ||
import re | ||
|
||
class info(): | ||
version = '1.0' | ||
description = '`systemextensionsctl list` command parser' | ||
author = 'Ron Green' | ||
compatible = ['darwin'] | ||
georgettica marked this conversation as resolved.
Show resolved
Hide resolved
|
||
magic_commands = ['systemextensionsctl list'] | ||
|
||
def parse(data, raw=False, quiet=False): | ||
""" | ||
Parses the output of `systemextensionsctl list` command. | ||
|
||
Parameters: | ||
|
||
data: (string) Text data to parse | ||
|
||
Returns: | ||
|
||
Dictionary with parsed data | ||
""" | ||
jc.utils.compatibility(__name__, info.compatible, quiet) | ||
if jc.utils.has_data(data): | ||
|
||
lines = data.strip().splitlines() | ||
total_extensions = None | ||
sections = [] | ||
section = None | ||
headers = None | ||
|
||
line_iter = iter(lines) | ||
for line in line_iter: | ||
line = line.strip('\n') | ||
if line.endswith('extension(s)'): | ||
# Extract total_extensions | ||
match = re.match(r'(\d+)\s+extension\(s\)', line) | ||
if match: | ||
total_extensions = int(match.group(1)) | ||
elif line.startswith('--- '): | ||
# Start of a new section | ||
category_line = line | ||
# Extract category and description | ||
category_and_desc = line[4:] | ||
# Category is up to the first '(' | ||
if '(' in category_and_desc: | ||
category = category_and_desc.split('(')[0].strip() | ||
description = category_and_desc[category_and_desc.find('(')+1:-1] | ||
else: | ||
category = category_and_desc.strip() | ||
description = '' | ||
section = { | ||
'category': category, | ||
'description': description, | ||
'entries': [] | ||
} | ||
sections.append(section) | ||
# Read the header line | ||
headers_line = next(line_iter) | ||
headers = headers_line.split('\t') | ||
# Normalize headers | ||
headers = [h.strip() for h in headers] | ||
else: | ||
# Data line | ||
if not line.strip(): | ||
continue | ||
fields = line.split('\t') | ||
# Pad fields with empty strings if needed | ||
if len(fields) < len(headers): | ||
fields = fields + ['']*(len(headers) - len(fields)) | ||
entry = {} | ||
for h, f in zip(headers, fields): | ||
entry[h] = f.strip() | ||
# Optionally parse the 'bundleID (version)' field | ||
if 'bundleID (version)' in entry: | ||
bundleID_version = entry['bundleID (version)'] | ||
match = re.match(r'(.+)\s+\((.+)\)', bundleID_version) | ||
if match: | ||
bundleID = match.group(1).strip() | ||
version = match.group(2).strip() | ||
entry['bundleID'] = bundleID | ||
entry['version'] = version | ||
else: | ||
entry['bundleID'] = bundleID_version.strip() | ||
entry['version'] = '' | ||
del entry['bundleID (version)'] | ||
# Optionally parse the '[state]' field | ||
if '[state]' in entry: | ||
state = entry['[state]'] | ||
if state.startswith('[') and state.endswith(']'): | ||
state_content = state[1:-1] | ||
entry['state'] = state_content.strip() | ||
else: | ||
entry['state'] = state.strip() | ||
del entry['[state]'] | ||
# Add entry to the current section | ||
section['entries'].append(entry) | ||
|
||
result = { | ||
'total_extensions': total_extensions, | ||
'sections': sections | ||
} | ||
return result | ||
else: | ||
return {} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sure to add the new parser to
lib.py
.