forked from kkabt/blendgit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.py
50 lines (31 loc) · 1.05 KB
/
common.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import os
import re
# common functions
get_git_context = lambda context: context.window_manager.git_context
get_addon_prefs = lambda context: context.preferences.addons[__package__].preferences
get_subpath = lambda *paths: os.path.join(os.path.dirname(__file__), *paths)
def extract_hash(text):
PTN = r'(\*.*?|commit )\b(?P<commit_hash>[0-9a-f]{7,})\b'
m = re.search(PTN, text)
return m.group('commit_hash') if m else ""
def spaced_label(layout, text):
layout.label(text=text.replace('\t', ' '*8))
def alert(layout, text):
row = layout.row()
row.alert = True
row.label(text=text, icon='ERROR', translate=False)
return row
def get_archive_path(context):
gcon = get_git_context(context)
prefs = get_addon_prefs(context)
if prefs.archive_dir:
# [archive_dir]/<project>
dirpath = os.path.join([
prefs.archive_dir,
bpy.path.basename(gcon.rootdir),
])
else:
# <project>/archive
dirpath = os.path.join(gcon.rootdir, "archive")
return dirpath
__all__ = []