From ddac8f78026bfbca1aabf2f7623daf430f1d4a5d Mon Sep 17 00:00:00 2001 From: o9000 Date: Sun, 17 Sep 2017 15:20:38 +0200 Subject: [PATCH] Battery: add data gathering script --- test/gather-battery-data.py | 45 +++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100755 test/gather-battery-data.py diff --git a/test/gather-battery-data.py b/test/gather-battery-data.py new file mode 100755 index 0000000..22efc42 --- /dev/null +++ b/test/gather-battery-data.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python + +import os +import os.path +import tarfile +try: + from StringIO import StringIO +except ImportError: + from io import StringIO + + +class TarWriter: + def __init__(self, out_name): + print("Creating: " + out_name) + self.tar = tarfile.open(out_name, "w") + + def add(self, path): + print("Adding: " + path) + if os.path.isfile(path): + metadata = self.tar.gettarinfo(path) + try: + with open(path) as f: + buf = f.read() + fbuf = StringIO(buf) + metadata.size = len(buf) + self.tar.addfile(metadata, fbuf) + fbuf.close() + except: + fbuf = StringIO() + metadata.size = 0 + self.tar.addfile(metadata, fbuf) + fbuf.close() + + def close(self): + self.tar.close() + + +writer = TarWriter("battery.tar") +for root, dirs, files in os.walk("/sys/class/power_supply"): + for device in dirs: + for root2, dirs2, files2 in os.walk(root + "/" + device): + for f in files2: + writer.add(root2 + "/" + f) +writer.close() +print("Finished.")