-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflux-config
executable file
·71 lines (59 loc) · 1.71 KB
/
flux-config
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
#!/usr/bin/env python3
import os
import subprocess
def find_binary_in_path(binary_name):
for path in os.environ["PATH"].split(os.pathsep):
full_path = os.path.join(path, binary_name)
if os.path.isfile(full_path) and os.access(full_path, os.X_OK):
return full_path
return None
def ldd_binary(binary_path):
try:
result = subprocess.run(['ldd', binary_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
result.check_returncode()
return result.stdout.decode()
except subprocess.CalledProcessError as e:
print(f"ldd failed: {e}")
return None
def find_library_paths(binary_path, libraries):
result = []
ldd_output = ldd_binary(binary_path)
for line in ldd_output.splitlines():
parts = line.split()
if len(parts) >= 3:
for lib in libraries:
if parts[0].startswith(lib):
result.append(parts[2])
return result
def main():
# Default mounts
mount_paths = [
os.getcwd(),
os.getenv("HOME"),
"/usr/bin/flux",
"/usr/etc/flux",
"/usr/lib/flux/",
"/usr/include/flux/",
"/usr/libexec/flux/",
"/usr/lib64/python3.6/site-packages/"
]
flux_path = find_binary_in_path("flux")
if not flux_path:
print(f"{binary_name} not found in PATH.")
return
# Add Flux libraries to mounts
mount_paths += find_library_paths(flux_path,
["libflux-core.so", "libflux-optparse.so", "libflux-security.so"])
# Add Flux socket
flux_uri = os.getenv("FLUX_URI")
if not flux_uri.startswith("local://"):
raise Error("Only supports local flux sockets (check FLUX_URI)")
flux_uri_file = flux_uri[8:]
mount_paths.append(flux_uri_file)
print(f"-e FLUX_URI={flux_uri}", end=' ')
# Output mount options
for path in mount_paths:
print(f"-v {path}:{path}", end=' ')
print()
if __name__ == "__main__":
main()