aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/cgit/repos/utils.py
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2021-03-27 22:09:05 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2021-03-29 00:45:48 +0300
commit96ccf79d46adb2d6b49c67e3e6ad59512d67da65 (patch)
tree30d924907a180c465799d7c575b0b833f51a676c /cgit/repos/utils.py
parentdedupe the code a bit (diff)
downloadcgitize-96ccf79d46adb2d6b49c67e3e6ad59512d67da65.tar.gz
cgitize-96ccf79d46adb2d6b49c67e3e6ad59512d67da65.zip
rename the project to "cgitize"
Diffstat (limited to 'cgit/repos/utils.py')
-rw-r--r--cgit/repos/utils.py43
1 files changed, 0 insertions, 43 deletions
diff --git a/cgit/repos/utils.py b/cgit/repos/utils.py
deleted file mode 100644
index 84337e8..0000000
--- a/cgit/repos/utils.py
+++ /dev/null
@@ -1,43 +0,0 @@
-# Copyright (c) 2018 Egor Tensin <Egor.Tensin@gmail.com>
-# This file is part of the "cgit repos" project.
-# For details, see https://github.com/egor-tensin/cgit-repos.
-# Distributed under the MIT License.
-
-import contextlib
-import logging
-import os
-import subprocess
-
-
-def check_output(*args, stdout=subprocess.PIPE, **kwargs):
- try:
- result = subprocess.run(args, stdout=stdout, stderr=subprocess.STDOUT,
- encoding='utf-8', check=True, **kwargs)
- if stdout != subprocess.DEVNULL:
- if result.stdout is None:
- logging.debug('%s', args)
- else:
- logging.debug('%s\n%s', args, result.stdout)
- return result.returncode == 0, result.stdout
- except subprocess.CalledProcessError as e:
- if stdout != subprocess.DEVNULL:
- logging.error('%s\n%s', e, e.output)
- return e.returncode == 0, e.output
-
-
-def run(*args, discard_output=False, **kwargs):
- if discard_output:
- success, _ = check_output(*args, stdout=subprocess.DEVNULL, **kwargs)
- else:
- success, _ = check_output(*args, **kwargs)
- return success
-
-
-@contextlib.contextmanager
-def chdir(new_cwd):
- old_cwd = os.getcwd()
- os.chdir(new_cwd)
- try:
- yield
- finally:
- os.chdir(old_cwd)