-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdia_worker.py
More file actions
34 lines (27 loc) · 847 Bytes
/
Copy pathdia_worker.py
File metadata and controls
34 lines (27 loc) · 847 Bytes
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
#!/usr/bin/env python3
import argparse
import json
import sys
from pathlib import Path
import dia_backend
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--json", action="store_true")
args = parser.parse_args()
if not args.json:
print("Use --json and send a request JSON object on stdin.", file=sys.stderr)
return 2
try:
request = json.loads(sys.stdin.read())
result = dia_backend._generate_to_file_local(
request["diaText"],
Path(request["outputPath"]),
request.get("options") or {},
)
print(json.dumps(result), flush=True)
return 0
except Exception as exc:
print(json.dumps({"ok": False, "error": str(exc)}), flush=True)
return 1
if __name__ == "__main__":
raise SystemExit(main())