nodeocc 1.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
view/styles.py ADDED
@@ -0,0 +1,76 @@
1
+ def _format_to(st, width, dir='left'):
2
+ ts = str(st)[:width]
3
+ if dir == 'left':
4
+ return ts + ' ' * (width - len(ts))
5
+ else:
6
+ return ' ' * (width - len(ts)) + ts
7
+
8
+ def cmdstyle(color, string):
9
+ """
10
+ style formatting function for unix terminals
11
+ """
12
+ strings = string.split('\n')
13
+ styles = {
14
+ 'RED' : lambda x: '\033[31m' + str(x) + '\033[0m',
15
+ 'YELLOW' : lambda x: '\033[33m' + str(x) + '\033[0m',
16
+ 'GREEN' : lambda x: '\033[32m' + str(x) + '\033[0m',
17
+ 'MAGENTA' : lambda x: '\033[35m' + str(x) + '\033[0m',
18
+ 'BLUE' : lambda x: '\033[34m' + str(x) + '\033[0m',
19
+
20
+ 'LRED' : lambda x: '\033[91m' + str(x) + '\033[0m',
21
+ 'LYELLOW' : lambda x: '\033[93m' + str(x) + '\033[0m',
22
+ 'LGREEN' : lambda x: '\033[92m' + str(x) + '\033[0m',
23
+ 'LMAGENTA' : lambda x: '\033[95m' + str(x) + '\033[0m',
24
+ 'LBLUE' : lambda x: '\033[94m' + str(x) + '\033[0m',
25
+ 'LCYAN' : lambda x: '\033[96m' + str(x) + '\033[0m',
26
+ 'LWHITE' : lambda x: '\033[97m' + str(x) + '\033[0m',
27
+
28
+ 'CYAN' : lambda x: '\033[36m' + str(x) + '\033[0m',
29
+ 'BG_CYAN': lambda x: '\033[33m' + str(x) + '\033[0m',
30
+ 'WHITE' : lambda x: '\033[37m' + str(x) + '\033[0m',
31
+
32
+ 'BG_RED': lambda x: '\033[41m\033[37m' + str(x) + '\033[0m',
33
+ 'BG_GREEN': lambda x: '\033[42m\033[37m' + str(x) + '\033[0m',
34
+ 'BG_YELLOW': lambda x: '\033[43m' + str(x) + '\033[0m',
35
+ 'BG_MAGENTA': lambda x: '\033[45m\033[37m' + str(x) + '\033[0m'
36
+
37
+ }
38
+ return '\n'.join([styles[color](x) for x in strings])
39
+
40
+ def crsstyler(color, string):
41
+ """
42
+ custom style formatting function for curses applications
43
+ """
44
+ strings = string.split('\n')
45
+ styles = {
46
+ 'RED' : lambda x: '<*3~' + str(x) + ':*>',
47
+ 'YELLOW' : lambda x: '<*4~' + str(x) + ':*>',
48
+ 'GREEN' : lambda x: '<*5~' + str(x) + ':*>',
49
+ 'MAGENTA' : lambda x: '<*6~' + str(x) + ':*>',
50
+ 'BLUE' : lambda x: '<*7~' + str(x) + ':*>',
51
+
52
+ 'LRED' : str,
53
+ 'LYELLOW' : str,
54
+ 'LGREEN' : str,
55
+ 'LMAGENTA' : str,
56
+ 'LBLUE' : str,
57
+ 'LCYAN' : str,
58
+ 'LWHITE' : str,
59
+ 'LBG_CYAN' : str,
60
+
61
+ 'CYAN' : lambda x: '<*8~' + str(x) + ':*>',
62
+ 'BG_CYAN': lambda x: '<*15~' + str(x) + ':*>',
63
+ 'WHITE' : lambda x: '<*2~' + str(x) + ':*>',
64
+
65
+ 'BG_RED': lambda x: '<*10~' + str(x) + ':*>',
66
+ 'BG_GREEN': lambda x: '<*11~' + str(x) + ':*>',
67
+ 'BG_YELLOW': lambda x: '<*12~' + str(x) + ':*>',
68
+ 'BG_MAGENTA': lambda x: '<*13~' + str(x) + ':*>'
69
+ }
70
+ return '\n'.join([styles[color](x) for x in strings])
71
+
72
+ def mockstyler(color, string):
73
+ """
74
+ mock style formatting function for debug purposes
75
+ """
76
+ return string
view/utils.py ADDED
@@ -0,0 +1,60 @@
1
+ import numpy as np
2
+ import re
3
+
4
+
5
+ def is_student_viz(user):
6
+ return user.user_group in ('studenti', 'tesisti') and not is_cvcs_viz(user)
7
+
8
+
9
+ def is_cvcs_viz(user):
10
+ return re.search(r'cvcs|ai4a2023', user.account.lower()) is not None
11
+
12
+
13
+ def is_dev(job):
14
+ return job.partition == 'all_serial'
15
+
16
+
17
+ def is_prod(job):
18
+ return job.partition == 'all_usr_prod'
19
+
20
+
21
+ def to_datetime(time_str):
22
+ return np.datetime64(re.match(r'\d+\s+(.*)\n', str(time_str)).group(1))
23
+
24
+
25
+ def to_datetime(time_str):
26
+ return np.datetime64(re.match(r'\d+\s+(.*)\n', str(time_str)).group(1))
27
+
28
+
29
+ def maintenance_status(infrastructure):
30
+ onmain = False
31
+ waitString = ''
32
+ if len(infrastructure.maintenances):
33
+ # time format: '0 2023-12-04 14:00:00\nName: StartTime, dtype: datetime64[ns]'
34
+ next_maintenance = sorted(infrastructure.maintenances, key=lambda x: to_datetime(x['start_time']))[0]
35
+ start_time = to_datetime(next_maintenance['start_time'])
36
+ end_time = to_datetime(next_maintenance['end_time'])
37
+ time_to_maintenance = (start_time - np.datetime64('now')).astype(float)
38
+ # TODO: fix timezone
39
+ if time_to_maintenance < 0 and (end_time - np.datetime64('now')) > 0:
40
+ onmain = True
41
+ else:
42
+ tt_d = int(time_to_maintenance / (60 * 60 * 24))
43
+ tt_h = int(time_to_maintenance % (60 * 60 * 24) / (60 * 60))
44
+ tt_m = int(time_to_maintenance % (60 * 60) / 60)
45
+ if tt_d > 0:
46
+ waitString = '%dd' % tt_d
47
+ elif tt_h > 0:
48
+ waitString = '%dh' % tt_h
49
+ else:
50
+ waitString = '%dm' % tt_m
51
+ return onmain, waitString
52
+
53
+
54
+ numfont = '⁰¹²³⁴⁵⁶⁷⁸⁹'
55
+
56
+
57
+ def to_font(num):
58
+ if num < 0:
59
+ return '⁻' + to_font(-num)
60
+ return ''.join([numfont[int(i)] for i in str(num)])