Skip to content
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

Merged
merged 1 commit into from
Nov 17, 2024
Merged

Conversation

codefiles
Copy link
Contributor

No description provided.

@codefiles
Copy link
Contributor Author

codefiles commented Nov 7, 2024

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):
Copy link
Contributor Author

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

Copy link
Member

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.

@svartkanin svartkanin merged commit 8fc3dc4 into archlinux:master Nov 17, 2024
8 checks passed
@codefiles codefiles deleted the lsblk-pydantic branch November 17, 2024 20:47
castillofrancodamian pushed a commit to castillofrancodamian/archinstall that referenced this pull request Dec 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants