-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathver.py
More file actions
executable file
·38 lines (32 loc) · 1.06 KB
/
ver.py
File metadata and controls
executable file
·38 lines (32 loc) · 1.06 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
31
32
33
34
35
36
37
38
#!/usr/bin/env python3
import argparse
from datetime import datetime
def v_today():
now = datetime.now()
return now.strftime("v%Y%m%d")
parser = argparse.ArgumentParser()
parser.add_argument("-i", "--inc", help="updates VERSION.txt", action="store_true")
parser.add_argument("-n", "--dry_run", help="prints what would happen", action="store_true")
args = parser.parse_args()
with open("VERSION.txt") as f:
try:
ver, date = f.readline().strip().split("_")
if args.inc:
# increment ver
major, minor, patch = map(int, ver.split("."))
patch += 1
ver = ".".join(map(str, [major, minor, patch]))
# increment date
date = v_today()
except ValueError:
ver, date = ("0.0.1", v_today())
verstr = f"{ver}_{date}\n"
if args.inc and not args.dry_run:
with open("VERSION.txt", "w") as f:
f.write(verstr)
f.flush()
with open("VERSION.txt") as f:
for line in f.readlines():
print(line, end="")
else:
print(verstr, end="")