aboutsummaryrefslogtreecommitdiffstats
path: root/mpm/python/usrp_mpm
diff options
context:
space:
mode:
authorJoerg Hofrichter <joerg.hofrichter@ni.com>2020-09-02 15:04:58 +0200
committerAaron Rossetto <aaron.rossetto@ni.com>2020-10-06 15:21:27 -0500
commit86cadf12c5c4d4599fa311c83b112c5a21404564 (patch)
treed133c2c8637bfb2b91cbeff646cb82ebcdaf73b4 /mpm/python/usrp_mpm
parent73d25757de4b9c40029048a19e83d1ab24f0317c (diff)
downloaduhd-86cadf12c5c4d4599fa311c83b112c5a21404564.tar.gz
uhd-86cadf12c5c4d4599fa311c83b112c5a21404564.tar.bz2
uhd-86cadf12c5c4d4599fa311c83b112c5a21404564.zip
mpm: added check-filesystem utility
Diffstat (limited to 'mpm/python/usrp_mpm')
-rw-r--r--mpm/python/usrp_mpm/sys_utils/filesystem_status.py67
1 files changed, 67 insertions, 0 deletions
diff --git a/mpm/python/usrp_mpm/sys_utils/filesystem_status.py b/mpm/python/usrp_mpm/sys_utils/filesystem_status.py
new file mode 100644
index 000000000..865741316
--- /dev/null
+++ b/mpm/python/usrp_mpm/sys_utils/filesystem_status.py
@@ -0,0 +1,67 @@
+#
+# Copyright 2020 Ettus Research, a National Instruments Company
+#
+# SPDX-License-Identifier: GPL-3.0-or-later
+#
+"""
+Utilities for checking the filesystem status
+"""
+
+import hashlib
+import pathlib
+import subprocess
+import time
+
+def get_uhd_version(filesystem_root='/'):
+ def parse_uhd_version(versionstring):
+ assert(versionstring[0:4] == 'UHD ')
+ array = versionstring[4:].split('-')
+ assert(len(array) == 3)
+ return {
+ 'version': array[0],
+ 'appendix': array[1],
+ 'githash': array[2],
+ }
+ file = pathlib.Path(filesystem_root, 'usr/bin/uhd_config_info')
+ versionstring = subprocess.check_output([file, '--version']).decode('utf-8').splitlines()[0]
+ return parse_uhd_version(versionstring)
+
+def get_mender_artifact(filesystem_root='/', parse_manually=False):
+ def parse_artifact(output):
+ for line in output.splitlines():
+ if line.startswith('artifact_name='):
+ return line[14:]
+ return None
+ if filesystem_root != '/':
+ parse_manually = True
+ if parse_manually:
+ # parse mender artifact manually
+ file = pathlib.Path(filesystem_root, 'etc/mender/artifact_info')
+ if not file.exists():
+ return 'FILE NOT FOUND'
+ return parse_artifact(file.read_text())
+ else:
+ output = subprocess.check_output(['/usr/bin/mender', '-show-artifact']).decode('utf-8')
+ return output.splitlines()[0]
+
+def get_fs_version(filesystem_root='/'):
+ file = pathlib.Path(filesystem_root, 'etc/version')
+ if not file.exists():
+ return 'FILE NOT FOUND'
+ return file.read_text().splitlines()[0]
+
+def get_opkg_status_date(date_only=False, filesystem_root='/'):
+ if date_only:
+ tformat = "%Y-%m-%d"
+ else:
+ tformat = "%Y-%m-%d %H:%M:%S"
+ file = pathlib.Path(filesystem_root, 'var/lib/opkg/status')
+ if not file.exists():
+ return 'FILE NOT FOUND'
+ return time.strftime(tformat, time.gmtime(file.stat().st_mtime))
+
+def get_opkg_status_md5sum(filesystem_root='/'):
+ file = pathlib.Path(filesystem_root, 'var/lib/opkg/status')
+ if not file.exists():
+ return 'FILE NOT FOUND'
+ return hashlib.md5sum(file.read_text()).hexdigest()