-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsetup.py
More file actions
82 lines (61 loc) · 2.43 KB
/
setup.py
File metadata and controls
82 lines (61 loc) · 2.43 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import platform
import subprocess
import shutil
import os
WINDOWS: str = "windows"
LINUX: str = "linux"
OSX: str = "osx"
def setup(args: dict) -> None:
print("Setting up mouse-tracker")
print("Building release library for OS {}".format(args.os), flush=True)
subprocess.run(["cargo", "build", "--release", "--lib",
"--manifest-path=rust/Cargo.toml"], check=True)
print("Finished building release library", flush=True)
print("Copying library")
if args.os == "windows":
shutil.copyfile("rust/target/release/mouse_poller.dll",
"mouse-poller/mouse_poller.dll")
elif args.os == "linux":
shutil.copyfile("rust/target/release/libmouse_poller.so",
"mouse-poller/libmouse_poller.so")
elif args.os == "osx":
print("""\nWARNING\nmouse-poller not yet implemented on osx""")
else:
raise Exception("Unhandled os: {}".format(args.os))
if args.export:
shutil.rmtree("rust")
if os.path.isdir("__pycache__"):
shutil.rmtree("__pycache__")
shutil.rmtree(".github")
print("Finished setting up mouse-tracker")
def clean(_args: dict) -> None:
print("Cleaning up mouse-tracker")
print("Running cargo clean", flush=True)
subprocess.run(
["cargo", "clean", "--manifest-path=rust/Cargo.toml"], check=True)
print("Finished running cargo clean", flush=True)
print("Finished cleaning up mouse-tracker")
if __name__ == "__main__":
os.chdir(os.path.dirname(os.path.realpath(__file__)))
from argparse import ArgumentParser
parser = ArgumentParser()
subparsers = parser.add_subparsers()
setup_parser = subparsers.add_parser("setup")
setup_parser.add_argument(
"--os", choices=["windows", "linux", "osx"], default="")
setup_parser.add_argument("--export", action="store_true")
setup_parser.set_defaults(func=setup)
clean_parser = subparsers.add_parser("clean")
clean_parser.set_defaults(func=clean)
args = parser.parse_args()
if not args.os:
args.os = platform.system()
if args.os == "Windows":
args.os = WINDOWS
elif args.os == "Linux":
args.os = LINUX
elif args.os == "Darwin":
args.os = OSX
else:
raise Exception("Unhandled OS: {}".format(args.os))
args.func(args)