forked from tabulapdf/tabula-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
36 lines (24 loc) · 871 Bytes
/
cli.py
File metadata and controls
36 lines (24 loc) · 871 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
35
36
from __future__ import annotations
import os
import subprocess
import sys
from pathlib import Path
def _runtime_dir() -> Path:
return Path(__file__).resolve().parent / "runtime"
def _java_bin(runtime_dir: Path) -> Path:
exe = "java.exe" if os.name == "nt" else "java"
return runtime_dir / "jre" / "bin" / exe
def main() -> int:
runtime_dir = _runtime_dir()
jar_path = runtime_dir / "tabula.jar"
java_path = _java_bin(runtime_dir)
if not jar_path.exists():
print(f"tabula-java bundle is missing: {jar_path}", file=sys.stderr)
return 1
if not java_path.exists():
print(f"Bundled java runtime is missing: {java_path}", file=sys.stderr)
return 1
cmd = [str(java_path), "-jar", str(jar_path), *sys.argv[1:]]
return subprocess.call(cmd)
if __name__ == "__main__":
raise SystemExit(main())