forked from akuhnet/w-colab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mountdrive.py
31 lines (22 loc) · 866 Bytes
/
mountdrive.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
def MountGDrive():
from os import environ as env
from google.colab import drive
config = env['CLOUDSDK_CONFIG']
addr = env['TBE_CREDS_ADDR']
! runuser -l $user -c "yes | python3 -m pip install --user google-colab" > /dev/null 2>&1
mount = """from os import environ as env
from google.colab import drive
env['CLOUDSDK_CONFIG'] = '{config}'
env['TBE_CREDS_ADDR'] = '{addr}'
drive.mount('{mountpoint}')""".format(config=config, addr=addr, mountpoint=mountpoint)
with open('/content/mount.py', 'w') as script:
script.write(mount)
! runuser -l $user -c "python3 /content/mount.py"
try:
mountpoint = f"/home/{username}/drive"
user = username
except NameError:
print("username variable not found, mounting at `/content/drive' using `root'")
mountpoint = '/content/drive'
user = 'akuhnet'
MountGDrive()