-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.py
executable file
·44 lines (35 loc) · 1.17 KB
/
install.py
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
41
42
43
#!/usr/bin/env python3
import argparse
from os import makedirs
from os.path import exists, join
import subprocess
import shutil
from sys import stderr
APP_NAME = "xibao-gen"
parser = argparse.ArgumentParser(description="Installer script for xibao-gen. ")
parser.add_argument(
"--prefix",
default="/usr/local/",
help="Directory to install into. "
)
args = parser.parse_args()
install_prefix = args.prefix
bin_prefix = join(install_prefix, "bin")
share_prefix = join(install_prefix, "share")
def installation():
if not exists(install_prefix):
makedirs(install_prefix, exist_ok=True)
if not exists(bin_prefix):
makedirs(bin_prefix, exist_ok=True)
if not exists(share_prefix):
makedirs(share_prefix, exist_ok=True)
status = subprocess.run(["cargo", "build", "--release"])
if status.returncode != 0:
raise Exception("failed to build the project. ")
shutil.copyfile(f"target/release/{APP_NAME}", join(bin_prefix, APP_NAME))
shutil.copytree("resource", join(share_prefix, APP_NAME))
if __name__ == "__main__":
try:
installation()
except BaseException as e:
print("Fatal Error: ", e.args, file=stderr)