xref: /OK3568_Linux_fs/yocto/poky/meta/recipes-devtools/python/python3-cryptography/check-memfree.py (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun#!/usr/bin/env python3
2*4882a593Smuzhiyun# https://stackoverflow.com/questions/22102999/get-total-physical-memory-in-python/28161352
3*4882a593Smuzhiyunimport sys
4*4882a593Smuzhiyunmeminfo = dict((i.split()[0].rstrip(':'),int(i.split()[1])) for i in open('/proc/meminfo').readlines())
5*4882a593Smuzhiyunmem_free = meminfo['MemTotal']/1024./1024.
6*4882a593Smuzhiyunif mem_free < 2.:
7*4882a593Smuzhiyun    raise RuntimeError("Insufficient free memory({:.3f}): requires > 2 GB".format(mem_free))
8*4882a593Smuzhiyun    sys.exit(1)
9*4882a593Smuzhiyunelse:
10*4882a593Smuzhiyun    print("Free memory: {:.3f} GB".format(mem_free))
11