-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathmisc.py
More file actions
40 lines (34 loc) · 923 Bytes
/
misc.py
File metadata and controls
40 lines (34 loc) · 923 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
39
40
import os
VERSION = "1.3.0"
def bundle_path(path):
return os.path.abspath(os.path.join(os.path.realpath(__file__), "..", path))
def get_mtime(path):
"""return mtime, or 0 when not exists"""
if os.path.exists(path):
try:
return os.stat(path).st_mtime
except FileNotFoundError:
pass
return 0
def force_remove(path):
try:
os.remove(path)
except FileNotFoundError:
pass
def version_compare(a: str, b: str):
"""
compare version string
return 1 if a > b
return 0 if a == b
return -1 if a < b
"""
a_parts = a.split(".")
b_parts = b.split(".")
for i in range(max(len(a_parts), len(b_parts))):
a_i = int(a_parts[i]) if i < len(a_parts) else 0
b_i = int(b_parts[i]) if i < len(b_parts) else 0
if a_i > b_i:
return 1
elif a_i < b_i:
return -1
return 0