Skip to content

Instantly share code, notes, and snippets.

@akinazuki
Created June 17, 2022 06:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akinazuki/2b5647f8819a3738c46f9dc7090c0765 to your computer and use it in GitHub Desktop.
Save akinazuki/2b5647f8819a3738c46f9dc7090c0765 to your computer and use it in GitHub Desktop.

Require Library pexpect

Run pip install pexpect to install it
import pexpect
import argparse
import os.path
import os
if os.uname().sysname != 'Darwin':
exit('This script is only for MacOS')
parser = argparse.ArgumentParser(description='Mount webdav')
parser.add_argument('-s', type=str, default='http://10.0.0.3:8080',help='Server address e.g. http://10.0.0.3:8080')
parser.add_argument('-t', default='/tmp/WebDav', type=str, help='Target directory')
parser.add_argument('-u', type=str, default='root',help='Username')
parser.add_argument('-p', type=str, default='root',help='Password' )
args = parser.parse_args()
if os.path.isdir(args.t) == False:
print("Target directory [%s] does not exist, creating" % args.t)
os.makedirs(args.t)
webdav = pexpect.spawn("/sbin/mount_webdav -i " + args.s + " " + args.t)
webdav.expect("Username:")
webdav.sendline(args.u + "\n")
webdav.expect("Password:")
webdav.sendline(args.p + "\n")
webdav.interact()
webdav.close()
exit_code = webdav.exitstatus
if exit_code == 0:
print("WebDav mounted on [%s]" % args.t)
elif exit_code == 16:
print("WebDav already mounted on [%s]" % args.t)
else:
print("WebDav not mounted [%d]" % exit_code)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment