-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_license.py
More file actions
39 lines (28 loc) · 1.07 KB
/
Copy pathgenerate_license.py
File metadata and controls
39 lines (28 loc) · 1.07 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
39
from __future__ import annotations
import argparse
from datetime import date
from printer_tool.registration import generate_registration_token
def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(description="为指定机器码生成卡密。")
parser.add_argument("--machine-code", required=True, help="目标设备的机器码")
parser.add_argument(
"--expiry-date",
required=True,
type=parse_expiry_date,
help="卡密到期日,格式为 YYYY-MM-DD",
)
return parser.parse_args()
def parse_expiry_date(value: str) -> date:
try:
return date.fromisoformat(value)
except ValueError as exc:
raise argparse.ArgumentTypeError("到期日格式必须为 YYYY-MM-DD") from exc
def main() -> int:
args = parse_args()
token = generate_registration_token(args.machine_code, args.expiry_date)
print(f"机器码: {args.machine_code}")
print(f"到期日: {args.expiry_date:%Y-%m-%d}")
print(f"卡密: {token}")
return 0
if __name__ == "__main__":
raise SystemExit(main())