-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.py
69 lines (50 loc) · 1.69 KB
/
functions.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import logging
log = logging.getLogger('app')
def shorten_label(string, length=20):
if not string:
return None
if string.startswith('[') and ']' in string:
project = string[0:string.index(']') + 1] + '\n'
string = string[string.index(']') + 2:]
else:
project = ''
if len(string) <= length:
return project + string
n_2 = int(length / 2) - 3
n_1 = length - n_2 - 3
try:
shorten = f'{string[:n_1]}...{string[-n_2:]}'
except Exception as err:
log.error(err)
return string
return project + shorten
def add_node(elements, path, shape='ellipse', url='', hidden_notes='', icon='#', type='default-node', id=None):
if not id:
id = path
for element in elements:
if 'id' in element['data'] and element['data']['id'] == id:
return
elements.append(
{'data': {'id': id,
'label': path,
'short_label': shorten_label(path, 20),
'shape': shape,
'url': url,
'hidden_notes': hidden_notes,
'icon': icon,
'type': type}})
def get_icon(node_text):
base_url = 'https://fonts.gstatic.com/s/i/short-term/release/materialsymbolsoutlined/__iconname__/default/24px.svg'
if '[cronicle]' in node_text:
return base_url.replace('__iconname__', 'schedule')
return base_url.replace('__iconname__', 'folder_special')
def get_color(text):
if 'NOK' == text:
return 'red'
if 'OK' == text:
return 'lightgreen'
return 'lightblue'
def get_type(text):
if '[cronicle]' in text:
return 'Cronicle Job'
return 'default'