-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathutils.py
More file actions
38 lines (26 loc) · 770 Bytes
/
utils.py
File metadata and controls
38 lines (26 loc) · 770 Bytes
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
import yaml
import time
from datetime import datetime
from queue import Queue
try:
from termcolor import colored
except ImportError:
def colored(x, *args, **kwargs):
return x
with open('endpoints.yaml') as fh:
ENDPOINTS = yaml.safe_load(fh)
MAX_CONCURRENT_TRANSFERS = 15
def avg(x):
if isinstance(x, Queue):
x = x.queue
return sum(x) / len(x)
def fmt_time(t=None, fmt='%H:%M:%S'):
return datetime.fromtimestamp(t or time.time()).strftime(fmt)
def endpoint_name(endpoint):
name = ENDPOINTS[endpoint]['name']
return '{:22}'.format(name)
def endpoint_id(name):
for e, info in ENDPOINTS.items():
if info['name'] == name:
return e
raise KeyError('No endpoint with name {}'.format(name))