Skip to content

Commit

Permalink
Update mountdrive.py
Browse files Browse the repository at this point in the history
  • Loading branch information
akuhnet authored Oct 5, 2021
1 parent 9f7cca0 commit d3ac374
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion mountdrive.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,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
drive.mount("/content/drive", force_remount=True)
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 = 'root'

MountGDrive()

0 comments on commit d3ac374

Please sign in to comment.