-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.py
More file actions
21 lines (19 loc) · 789 Bytes
/
utils.py
File metadata and controls
21 lines (19 loc) · 789 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import re
import subprocess
# https://stackoverflow.com/questions/241327/remove-c-and-c-comments-using-python/1294188#1294188
def cpp_comment_remover(text):
def replacer(match):
s = match.group(0)
if s.startswith('/'):
return " " # note: a space and not an empty string
else:
return s
pattern = re.compile(
r'//.*?$|/\*.*?\*/|\'(?:\\.|[^\\\'])*\'|"(?:\\.|[^\\"])*"',
re.DOTALL | re.MULTILINE
)
return re.sub(pattern, replacer, text)
def get_git_info(dir_path=None):
git_hash = subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=dir_path).decode().strip()
status = subprocess.check_output(['git', 'status', '--porcelain'], cwd=dir_path).decode()
return {'hash': git_hash, 'status': status}