-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsmith_share
More file actions
executable file
·94 lines (80 loc) · 3.55 KB
/
smith_share
File metadata and controls
executable file
·94 lines (80 loc) · 3.55 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
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env python3
# Author: Kurt Irvin Rojas
# https://github.com/kimrojas/smith_utils
"""
SMITH SHARE
- Mounts the smith filesystem (only your home direcory) to your local machine
effectively making smith just a network drive.
- With this you can now use local resources and environments
for example:
using visual studio code to open smith files (quick edits)
using python environment and jupyterlab
running processing codes without using smith login node
USING XCYSDEN WITHOUT LAG WHEN CONNECTION OUTSIDE THE UNIVERSITY (OMG!)
Usage: `smith_share [ mount | unmount ]` to mount/unmount
"""
import sys, os, subprocess
sys.dont_write_bytecode = True
from smith_user_parse import user
import smith_check
import smith_spinner as ss
from smith_output import blue, green, warning, fail, bold, underline, cyan
def init():
print(green(f"MOUNTING SMITH SERVER TO LOCAL ({user['smith_username']})"))
print(green(f"{'-'*53}"))
def dir_avail():
avail = os.path.isdir(user['smith_server_mount'])
if avail:
print(f"Mount location available: ", user['smith_server_mount'])
else:
print(warning(f"Mount location not available"))
print(f"Creating mount location ... ", end = "")
os.makedirs(user['smith_server_mount'])
avail = os.path.isdir(user['smith_server_mount'])
if not avail: sys.exit(fail("Mount location creation failed ! (IDK, but maybe you don't have permission to make a folder there)"))
print("Success")
print(f"Mount location available: ", user['smith_server_mount'])
def errorcode():
helpme = "Usage: `smith_share [ mount | unmount ]` to mount/unmount"
if len(sys.argv) != 2: sys.exit(helpme)
if sys.argv[1] not in ['mount', 'unmount']: sys.exit(helpme)
def connect():
init()
dir_avail()
if os.listdir(user['smith_server_mount']): sys.exit(fail("SMITH SERVER LOCATION STILL MOUNTED / NOT EMPTY."))
print(f"Connecting to: {user['smith_server_home']}")
method = smith_check.check()
main_options = ['follow_symlinks','allow_other',
'ConnectTimeout=3','ConnectionAttempts=1',
'ServerAliveInterval=3', 'ServerAliveCountMax=1',
'reconnect']
if method == 'UseLocal':
srvr = f"{user['smith_username']}@{user['smith_ip']}:{user['smith_server_home']}"
main_options.append(f"port={user['smith_port']}")
option = ','.join(main_options)
if method == 'UseGlobal':
srvr = f"{user['smith_username']}@localhost:{user['smith_server_home']}"
main_options.append(f"port={user['smith_univ_port']}")
option = ','.join(main_options)
bashCommand = f"sshfs -C {srvr} {user['smith_server_mount']} -o {option}"
output = subprocess.run(bashCommand.split())
empty("connect", os.listdir(user['smith_server_mount']))
def disconnect():
if 'linux' in sys.platform:
bashCommand = f"fusermount -zu {user['smith_server_mount']}"
if 'darwin' in sys.platform:
bashCommand = f"diskutil unmount force {user['smith_server_mount']}"
output = subprocess.run(bashCommand.split())
empty("disconnect", not os.listdir(user['smith_server_mount']))
def empty(proc, condition):
if condition :
print(bold(cyan(f"SMITH SERVER mount successfully {proc.upper()}ED.")))
else:
print(bold(fail(f"SMITH SERVER mount failed to {proc.upper()}.")))
## MAIN
errorcode()
if sys.argv[1] == 'mount':
connect()
print(green(f"{'-'*53}"))
elif sys.argv[1] == 'unmount':
disconnect()