From 5db6c23109f123ecfe5d79986a931da685095e4e Mon Sep 17 00:00:00 2001 From: Sylvain Pineau Date: Mon, 13 Jul 2020 10:33:55 +0200 Subject: bin:disk_info -> disk_info.py --- bin/disk_info | 81 -------------------------------------------------------- bin/disk_info.py | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 81 deletions(-) delete mode 100755 bin/disk_info create mode 100755 bin/disk_info.py (limited to 'bin') diff --git a/bin/disk_info b/bin/disk_info deleted file mode 100755 index 0b45443..0000000 --- a/bin/disk_info +++ /dev/null @@ -1,81 +0,0 @@ -#!/usr/bin/env python3 -# -# This file is part of Checkbox. -# -# Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications -# Industrial Technology Research Institute -# Copyright 2016 Canonical Ltd. -# -# Authors: -# Nelson Chu -# Jeff Lane -# Sylvain Pineau -# -# Checkbox is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License version 3, -# as published by the Free Software Foundation. -# -# Checkbox is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Checkbox. If not, see . -"""disk_info utility.""" - -import re -import sys -from subprocess import check_output, CalledProcessError - -from checkbox_support.parsers.udevadm import find_pkname_is_root_mountpoint - - -def main(): - """ - disk_info. - - Uses lsblk to gather information about disks seen by the OS. - Outputs kernel name, model and size data - """ - pattern = re.compile('KNAME="(?P.*)" ' - 'TYPE="(?P.*)" ' - 'SIZE="(?P.*)" ' - 'MODEL="(?P.*)" ' - 'MOUNTPOINT="(?P.*)"') - try: - lsblk = check_output(["lsblk", "-i", "-n", "-P", "-o", - "KNAME,TYPE,SIZE,MODEL,MOUNTPOINT"], - universal_newlines=True) - except CalledProcessError as e: - sys.exit(e) - - disks = 0 - for line in lsblk.splitlines(): - m = pattern.match(line) - if not m or m.group('TYPE') not in ('disk', 'crypt'): - continue - # Only consider MMC block devices if one of their mounted partitions is - # root (/) - if ( - m.group('KNAME').startswith('mmcblk') and not - find_pkname_is_root_mountpoint(m.group('KNAME'), lsblk) - ): - continue - disks += 1 - model = m.group('MODEL') - if not model: - model = 'Unknown' - print("Name: /dev/{}".format(m.group('KNAME'))) - print("\t{:7}\t{}".format('Model:', model)) - print("\t{:7}\t{}".format('Size:', m.group('SIZE'))) - - if not disks: - print("No disk information discovered.") - return 10 - - return 0 - - -if __name__ == '__main__': - sys.exit(main()) diff --git a/bin/disk_info.py b/bin/disk_info.py new file mode 100755 index 0000000..0b45443 --- /dev/null +++ b/bin/disk_info.py @@ -0,0 +1,81 @@ +#!/usr/bin/env python3 +# +# This file is part of Checkbox. +# +# Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications +# Industrial Technology Research Institute +# Copyright 2016 Canonical Ltd. +# +# Authors: +# Nelson Chu +# Jeff Lane +# Sylvain Pineau +# +# Checkbox is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 3, +# as published by the Free Software Foundation. +# +# Checkbox is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Checkbox. If not, see . +"""disk_info utility.""" + +import re +import sys +from subprocess import check_output, CalledProcessError + +from checkbox_support.parsers.udevadm import find_pkname_is_root_mountpoint + + +def main(): + """ + disk_info. + + Uses lsblk to gather information about disks seen by the OS. + Outputs kernel name, model and size data + """ + pattern = re.compile('KNAME="(?P.*)" ' + 'TYPE="(?P.*)" ' + 'SIZE="(?P.*)" ' + 'MODEL="(?P.*)" ' + 'MOUNTPOINT="(?P.*)"') + try: + lsblk = check_output(["lsblk", "-i", "-n", "-P", "-o", + "KNAME,TYPE,SIZE,MODEL,MOUNTPOINT"], + universal_newlines=True) + except CalledProcessError as e: + sys.exit(e) + + disks = 0 + for line in lsblk.splitlines(): + m = pattern.match(line) + if not m or m.group('TYPE') not in ('disk', 'crypt'): + continue + # Only consider MMC block devices if one of their mounted partitions is + # root (/) + if ( + m.group('KNAME').startswith('mmcblk') and not + find_pkname_is_root_mountpoint(m.group('KNAME'), lsblk) + ): + continue + disks += 1 + model = m.group('MODEL') + if not model: + model = 'Unknown' + print("Name: /dev/{}".format(m.group('KNAME'))) + print("\t{:7}\t{}".format('Model:', model)) + print("\t{:7}\t{}".format('Size:', m.group('SIZE'))) + + if not disks: + print("No disk information discovered.") + return 10 + + return 0 + + +if __name__ == '__main__': + sys.exit(main()) -- cgit v1.2.3