summaryrefslogtreecommitdiff
path: root/tomlplusplus/tools/utils.py
diff options
context:
space:
mode:
authorMehmet Samet Duman <yongdohyun@projecttick.org>2026-04-02 18:44:05 +0300
committerMehmet Samet Duman <yongdohyun@projecttick.org>2026-04-02 18:44:05 +0300
commit0b24459ac12b6cf9fd5a401d647796ca254a8fa8 (patch)
treef2fd66e2476976a51e2a51330fd95dc6e87b24c1 /tomlplusplus/tools/utils.py
parentb85e90fc3480da0e6a48da73201a0b22488cc650 (diff)
parent1c8b7466e4946fcc3bf20484c0e1d001202cca5a (diff)
downloadProject-Tick-0b24459ac12b6cf9fd5a401d647796ca254a8fa8.tar.gz
Project-Tick-0b24459ac12b6cf9fd5a401d647796ca254a8fa8.zip
Add 'tomlplusplus/' from commit '1c8b7466e4946fcc3bf20484c0e1d001202cca5a'
git-subtree-dir: tomlplusplus git-subtree-mainline: b85e90fc3480da0e6a48da73201a0b22488cc650 git-subtree-split: 1c8b7466e4946fcc3bf20484c0e1d001202cca5a
Diffstat (limited to 'tomlplusplus/tools/utils.py')
-rw-r--r--tomlplusplus/tools/utils.py55
1 files changed, 55 insertions, 0 deletions
diff --git a/tomlplusplus/tools/utils.py b/tomlplusplus/tools/utils.py
new file mode 100644
index 0000000000..eda553a954
--- /dev/null
+++ b/tomlplusplus/tools/utils.py
@@ -0,0 +1,55 @@
+#!/usr/bin/env python3
+# This file is a part of toml++ and is subject to the the terms of the MIT license.
+# Copyright (c) Mark Gillard <mark.gillard@outlook.com.au>
+# See https://github.com/marzer/tomlplusplus/blob/master/LICENSE for the full license text.
+# SPDX-License-Identifier: MIT
+
+import sys
+import subprocess
+from pathlib import Path
+from misk import *
+
+
+def repeat_pattern(pattern, count):
+ if len(pattern) == 1:
+ return pattern * count
+ text = ''
+ for i in range(0, count):
+ text = text + pattern[i % len(pattern)]
+ return text
+
+
+
+def make_divider(text = None, text_col = 40, pattern = '-', line_length = 120):
+ if (text is None):
+ return "//" + repeat_pattern(pattern, line_length-2)
+ else:
+ text = "//{} {} ".format(repeat_pattern(pattern, text_col - 2), text);
+ if (len(text) < line_length):
+ return text + repeat_pattern(pattern, line_length - len(text))
+ else:
+ return text
+
+
+
+def apply_clang_format(text, cwd=None):
+ return subprocess.run(
+ 'clang-format --style=file'.split(),
+ check=True,
+ capture_output=True,
+ cwd=str(Path.cwd() if cwd is None else cwd),
+ encoding='utf-8',
+ input=text
+ ).stdout
+
+
+def run(main_func, verbose=False):
+ try:
+ result = main_func()
+ if result is None:
+ sys.exit(0)
+ else:
+ sys.exit(int(result))
+ except Exception as err:
+ print_exception(err, include_type=verbose, include_traceback=verbose, skip_frames=1)
+ sys.exit(-1)