diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2020-03-28 23:01:09 +0000 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2020-03-28 23:54:46 +0000 |
commit | c58a3787eca9c0c4a7f376ba841cd7e39ab95ece (patch) | |
tree | 709b5ab8385bbb952912206ae561fbe5e1e752d8 /project/utils.py | |
parent | project.boost: factor out BoostVersion (diff) | |
download | cmake-common-c58a3787eca9c0c4a7f376ba841cd7e39ab95ece.tar.gz cmake-common-c58a3787eca9c0c4a7f376ba841cd7e39ab95ece.zip |
project.boost: factor out everything else
I finally snapped. This starts to resemble sensible structure though.
Diffstat (limited to 'project/utils.py')
-rw-r--r-- | project/utils.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/project/utils.py b/project/utils.py new file mode 100644 index 0000000..a766f90 --- /dev/null +++ b/project/utils.py @@ -0,0 +1,50 @@ +# Copyright (c) 2020 Egor Tensin <Egor.Tensin@gmail.com> +# This file is part of the "cmake-common" project. +# For details, see https://github.com/egor-tensin/cmake-common. +# Distributed under the MIT License. + +from contextlib import contextmanager +import logging +import os.path +import platform +import subprocess + + +def normalize_path(s): + return os.path.abspath(os.path.normpath(s)) + + +@contextmanager +def setup_logging(): + logging.basicConfig( + format='%(asctime)s | %(levelname)s | %(message)s', + datefmt='%Y-%m-%d %H:%M:%S', + level=logging.INFO) + try: + yield + except Exception as e: + logging.exception(e) + raise + + +@contextmanager +def cd(path): + cwd = os.getcwd() + os.chdir(path) + try: + yield + finally: + os.chdir(cwd) + + +def run(cmd_line): + logging.info('Running executable: %s', cmd_line) + return subprocess.run(cmd_line, check=True) + + +def on_windows(): + return platform.system() == 'Windows' + + +def on_linux(): + return not on_windows() |