-
Notifications
You must be signed in to change notification settings - Fork 567
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
Parse lsblk data with pydantic #2775
Conversation
f09c6b5
to
a57044e
Compare
a57044e
to
9ef343e
Compare
Here is a simple example script that uses archinstall as a library: import argparse
import sys
from archinstall.lib.disk import get_lsblk_info
from archinstall.lib.exceptions import DiskError
def main() -> int:
parser = argparse.ArgumentParser()
parser.add_argument('device')
args = parser.parse_args()
try:
lsblk_info = get_lsblk_info(args.device)
except DiskError as e:
print(e, file=sys.stderr)
return 32
print(lsblk_info.json())
return 0
if __name__ == '__main__':
sys.exit(main()) This works but the message below will always be emitted before the expected output. We ignore the entry device as it isn't related to any argument This is related to #2728 and the way the archinstall entry point is handled; not an issue with this pull request. |
@classmethod | ||
def exclude(cls) -> List[str]: | ||
return ['children'] | ||
class LsblkInfo(BaseModel): |
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.
name
, path
, size
, rota
, and type
may need the addition of None
.
I do not see a way in which type
will not be a str
though:
https://github.com/util-linux/util-linux/blob/2bf297b55f78b77b0e585502546afa79264e693d/misc-utils/lsblk.c#L447
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.
Correct, there's no way the type won't be a str
.
I think the Optional
was there because it wasn't always the case that lsblk returned the type.
No description provided.