-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathutil.py
More file actions
27 lines (18 loc) · 727 Bytes
/
util.py
File metadata and controls
27 lines (18 loc) · 727 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
# Utilities.
import random
import datetime
def format_eta(elapsed_time, elapsed_steps, total_steps):
remaining_time = elapsed_time / elapsed_steps * (total_steps - elapsed_steps)
return str(remaining_time)
def random_id(length=5):
return "".join(random.choice("0123456789abcdef") for _ in range(length))
# Helper decorator that registers the baseclass under the 'subtypes' attribute
# of the given class.
def register(superclass):
def decorator(subclass):
superclass.subtypes[subclass.__name__] = subclass
return subclass
return decorator
def now():
'The current time as string, to be printed in log messages.'
return datetime.datetime.now().strftime("[%Y-%m-%d %H:%M:%S]")