Created
June 17, 2022 06:48
-
-
Save akinazuki/2b5647f8819a3738c46f9dc7090c0765 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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