-
Notifications
You must be signed in to change notification settings - Fork 0
/
bob.py
executable file
·277 lines (215 loc) · 6.93 KB
/
bob.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
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
#!/usr/bin/env python3
import argparse
from argparse import Namespace
import subprocess
from os import path
def styled_print(message):
print(f"[🦺 Bob]: {message}")
def linkage_dir():
return path.dirname(path.abspath(__file__))
def home_dir():
return path.expanduser("~")
def cargo_build(cargo_path=None, package=None, release=False):
cargo = "cargo" if not cargo_path else cargo_path
args = [cargo, "build"]
if package:
args.append(f"--package={package}")
if release:
args.append("--release")
subprocess.run(args, cwd=linkage_dir())
def cargo_run(cargo_path=None, package=None, release=False):
cargo = "cargo" if not cargo_path else cargo_path
args = [cargo, "run"]
if package:
args.append(f"--package={package}")
if release:
args.append("--release")
subprocess.run(args, cwd=linkage_dir())
def init(no_npm_install):
if not no_npm_install:
subprocess.run(["pnpm", "install"])
def format():
styled_print("Formatting entire project...")
styled_print("Running prettier...")
subprocess.run(
[
"npx",
"prettier",
"--write",
"--config",
".prettierrc.json",
"{**/*,*}.{js,ts,json,css,scss,sass,html,d.ts,svelte}",
]
)
styled_print("Running black...")
subprocess.run(["black", "."])
styled_print("Running rustfmt...")
subprocess.run(["cargo", "fmt"])
styled_print("Done!")
exit(0)
def lint():
styled_print("Linting entire project...")
styled_print("Running eslint...")
subprocess.run(["npx", "eslint", "."])
styled_print("Running cargo clippy...")
subprocess.run(["cargo", "clippy"])
styled_print("Done!")
exit(0)
def build_cockpit():
styled_print("Building frontend...")
subprocess.run(["pnpm", "install"], cwd="cockpit")
subprocess.run(["pnpm", "run", "tauri", "build"], cwd="cockpit")
def build_carburetor(cargo_path=None, release=False):
styled_print("Building Carburetor...")
cargo_build(cargo_path, "carburetor", release=release)
def build(args: Namespace):
if args.part == "all":
styled_print("Building all parts...")
cargo_build(release=args.release)
build_cockpit()
elif args.part == "cockpit":
styled_print("Building cockpit frontend and backend...")
build_cockpit()
elif args.part == "carburetor":
build_carburetor(release=args.release)
else:
styled_print("ERROR: Part '{unknown}' not recognized")
styled_print("Done!")
exit(0)
def deploy_carburetor(host):
styled_print("Deploying Carburetor...")
subprocess.run(["./deploy.sh", host], cwd="carburetor")
def deploy_gauge(host):
styled_print("Deploying Gauge...")
subprocess.run(["./deploy.sh", host], cwd="gauge")
def deploy_example(host, example):
styled_print("Deploying Example...")
subprocess.run(["./deploy.sh", host, example], cwd="lib/linkage-rs")
def deploy(args: Namespace):
if args.part == "all":
styled_print("Deploying all parts...")
deploy_carburetor(args.host)
deploy_gauge(args.host)
deploy_example(args.host, "simple_tankdrive")
elif args.part == "carburetor":
deploy_carburetor(args.host)
elif args.part == "example":
deploy_example(args.host, "simple_tankdrive")
elif args.part == "gauge":
deploy_gauge(args.host)
else:
styled_print("ERROR: Part '{unknown}' not recognized")
def run_carburetor(release=False, no_build=False):
if not no_build:
build_carburetor(release=release)
styled_print("Running Carburetor")
cargo_run(package="carburetor", release=release)
def run_cockpit(release=False):
if release:
build_cockpit()
else:
styled_print("Running Cockpit")
subprocess.run(["pnpm", "run", "tauri", "dev"], cwd="cockpit")
def run(args: Namespace):
if args.part == "carburetor":
run_carburetor(release=args.release, no_build=args.no_build)
elif args.part == "cockpit":
run_cockpit(release=args.release)
else:
styled_print("ERROR: Part '{unknown}' not recognized")
styled_print("Done!")
exit(0)
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Manager script for the many moving parts of Linkage",
epilog="Koen Westendorp & Bauke Westendorp, 2023",
)
subparsers = parser.add_subparsers(
title="subarguments", dest="subcommand", required=True
)
# Init subcommand
init_subcommand = subparsers.add_parser("init", help="initializes the project")
init_subcommand.add_argument(
"--no-npm-install",
help="initialize the project without running npm install",
action="store_true",
)
# Format subcommand
format_subcommand = subparsers.add_parser("format", help="format all files")
# Lint subcommand
lint_subcommand = subparsers.add_parser("lint", help="lints all files")
# Build subcommand
build_subcommand = subparsers.add_parser(
"build", help="build the moving parts of linkage"
)
build_subcommand.add_argument(
"part",
help="the part of linkage to build",
choices=[
"all",
"cockpit",
"gauge",
"carburetor",
],
)
build_subcommand.add_argument(
"--release",
"-r",
help="compile rust binaries in release mode",
action="store_true",
)
# Deploy subcommand
deploy_subcommand = subparsers.add_parser(
"deploy",
help="deploy the moving parts of linkage",
)
deploy_subcommand.add_argument(
"host",
help="the host to deploy to",
)
deploy_subcommand.add_argument(
"part",
help="the part of linkage to deploy",
choices=["all", "carburetor", "gauge", "example"],
)
# Run subcommand
run_subcommand = subparsers.add_parser(
"run",
help="run moving parts of linkage",
)
run_subcommand.add_argument(
"part",
help="the part of linkage to run",
choices=[
"cockpit",
"carburetor",
"gauge",
],
)
run_subcommand.add_argument(
"--release",
"-r",
help="compile rust binaries in release mode",
action="store_true",
)
run_subcommand.add_argument(
"--no-build",
help="don't build part before running",
action="store_true",
)
# Parsing
args = parser.parse_args()
if args.subcommand == "init":
init(no_npm_install=args.no_npm_install)
elif args.subcommand == "format":
format()
elif args.subcommand == "lint":
lint()
elif args.subcommand == "build":
build(args)
elif args.subcommand == "deploy":
deploy(args)
elif args.subcommand == "run":
run(args)
else:
styled_print("ERROR: Unknown subcommond '{args.subcommand}'")