diff --git a/src/__init__.py b/src/__init__.py index 0334b3af8d09c5f06867fccc809935406a507b44..d989a6097c28719a442426f303642bb0ff73b5b3 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -14,7 +14,6 @@ # # You should have received a copy of the GNU General Public License # along with allocbench. If not, see <http://www.gnu.org/licenses/>. - """A framework linking allocators to applications""" __author__ = "Florian Fischer" diff --git a/src/benchmarks/__init__.py b/src/benchmarks/__init__.py index f7cc8d7215ff232df71010d91929e68b861280c4..68b5e56585f538c9c5b5eb1df09bef809594affd 100644 --- a/src/benchmarks/__init__.py +++ b/src/benchmarks/__init__.py @@ -14,5 +14,4 @@ # # You should have received a copy of the GNU General Public License # along with allocbench. If not, see <http://www.gnu.org/licenses/>. - """allocbench benchmark definitions""" diff --git a/src/facter.py b/src/facter.py index c3c95cda8d4c6412a3a937c6893fea3bc9b9c703..fe0b316803ad33fa716a03a663f51fb3469265d1 100644 --- a/src/facter.py +++ b/src/facter.py @@ -14,7 +14,6 @@ # # You should have received a copy of the GNU General Public License # along with allocbench. If not, see <http://www.gnu.org/licenses/>. - """Collect facts about the benchmark environment""" import ctypes @@ -53,6 +52,7 @@ def collect_facts(): starttime = starttime[:starttime.rfind(':')] gv.facts["starttime"] = starttime + def store_facts(path=None): """Store facts to file""" if not path: @@ -66,6 +66,7 @@ def store_facts(path=None): with open(filename, "w") as f: json.dump(gv.facts, f) + def load_facts(path=None): """Load facts from file""" if not path: @@ -86,10 +87,12 @@ def load_facts(path=None): with open(filename, "rb") as f: gv.facts = pickle.load(f) else: - raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), filename) + raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), + filename) print_info(f"Loading facts from: {filename}") + # Copied from pip. # https://github.com/pypa/pip/blob/master/src/pip/_internal/utils/glibc.py # Licensed under MIT. @@ -148,10 +151,12 @@ def libc_ver(executable=None): return ("glibc", glibc_version) + def exe_version(executable, version_flag="--version"): """Return version of executable""" proc = subprocess.run([executable, version_flag], - universal_newlines=True, stdout=subprocess.PIPE) + universal_newlines=True, + stdout=subprocess.PIPE) if proc.returncode != 0: print_warning(f"failed to get version of {executable}") diff --git a/src/util.py b/src/util.py index c5fa1627b46663bf079028b0e8c2fe4d313445c5..7992084bf8aa44322ab58461e42e080357dcf86e 100644 --- a/src/util.py +++ b/src/util.py @@ -14,7 +14,6 @@ # # You should have received a copy of the GNU General Public License # along with allocbench. If not, see <http://www.gnu.org/licenses/>. - """Helper functions for allocbench""" import hashlib @@ -24,6 +23,7 @@ import sys import src.globalvars + def is_exe(fpath): """Check if the given path is an exexutable file""" return os.path.isfile(fpath) and os.access(fpath, os.X_OK) @@ -75,9 +75,11 @@ def allocbench_msg(color, *objects, sep=' ', end='\n', file=sys.stdout): if src.globalvars.verbosity < 0: return - color = {"YELLOW": "\x1b[33m", - "GREEN": "\x1b[32m", - "RED": "\x1b[31m"}[color] + color = { + "YELLOW": "\x1b[33m", + "GREEN": "\x1b[32m", + "RED": "\x1b[31m" + }[color] is_atty = sys.stdout.isatty() if is_atty: @@ -137,14 +139,16 @@ def print_error(*objects, sep=' ', end='\n', file=sys.stderr): def print_license_and_exit(): """Print GPL info and Copyright before exit""" print("Copyright (C) 2018-2019 Florian Fischer") - print("License GPLv3: GNU GPL version 3 <http://gnu.org/licenses/gpl.html>") + print( + "License GPLv3: GNU GPL version 3 <http://gnu.org/licenses/gpl.html>") exit(0) def print_version_and_exit(): """Print current commit info before exit""" proc = subprocess.run(["git", "rev-parse", "HEAD"], - universal_newlines=True, stdout=subprocess.PIPE) + universal_newlines=True, + stdout=subprocess.PIPE) if proc.returncode != 0: print_error("git rev-parse failed") @@ -152,7 +156,8 @@ def print_version_and_exit(): commit = proc.stdout[:-1] proc = subprocess.run(["git", "status", "--porcelain"], - universal_newlines=True, stdout=subprocess.PIPE) + universal_newlines=True, + stdout=subprocess.PIPE) if proc.returncode != 0: print_error("git status --porcelain failed") @@ -163,12 +168,13 @@ def print_version_and_exit(): print(f"{commit}{dirty}") exit(0) + def sha1sum(filename): """Return sha1sum of a file""" - sha1 = hashlib.sha1() - barray = bytearray(64*1024) + sha1 = hashlib.sha1() + barray = bytearray(64 * 1024) view = memoryview(barray) with open(filename, 'rb', buffering=0) as f: - for n in iter(lambda : f.readinto(view), 0): + for n in iter(lambda: f.readinto(view), 0): sha1.update(view[:n]) return sha1.hexdigest()