-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathutils.py
More file actions
30 lines (24 loc) · 1 KB
/
utils.py
File metadata and controls
30 lines (24 loc) · 1 KB
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
import random
import string
import datetime
import hashlib
from base64 import b64encode
def hash_nt_passwd(passwd_utf16le):
nt_password = b64encode(hashlib.new('md4', passwd_utf16le).digest())
return nt_password
def random_string(N):
return ''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for i in range(N))
def sizeof_fmt(num, suffix='B'):
for unit in ['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi']:
if abs(num) < 1024.0:
return "%3.2f %s%s" % (num, unit, suffix)
num /= 1024.0
return "%.2f %s%s" % (num, 'Yi', suffix)
def next_semester_end(extra_years=0):
today = datetime.date.today()
if today.month < 3:
return datetime.date(today.year + extra_years, 9, 1) + datetime.timedelta(days=-1)
elif today.month < 9:
return datetime.date(today.year + extra_years + 1, 3, 1) + datetime.timedelta(days=-1)
else:
return datetime.date(today.year + extra_years + 1, 9, 1) + datetime.timedelta(days=-1)