Created
August 19, 2011 19:47
-
-
Save jamesob/1157814 to your computer and use it in GitHub Desktop.
sshfs mnt utility
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
#!/usr/local/bin/python | |
import argparse | |
import os | |
# User configuration | |
# ------------------ | |
_MNT_DIR = "~/mnt/dev" # e.g. mount at ~/mnt/dev6 | |
# ------------------ | |
_desc = "A utility for mounting and unmounting phase2 dev machines." | |
_USER = os.environ["USER"] | |
def mnt(num): | |
return \ | |
"sshfs {0}@dev{1}.fayze2.com:/opt/development/{0} {2}{1}".format(_USER, num, _MNT_DIR) | |
def umnt(num): | |
return "diskutil umount force {1}{0}".format(num, _MNT_DIR) | |
def rmnt(num): | |
cwd = os.getcwd() | |
return "%s && %s && cd && sleep 1 && cd %s" % (umnt(num), mnt(num), cwd) | |
parser = argparse.ArgumentParser(description=_desc) | |
parser.add_argument('devNum', | |
action='store', | |
type=int, | |
help='Machine dev_, i.e. "6" for dev6.') | |
parser.add_argument('-m', | |
action='store_true', default=False, | |
dest='mount', | |
help='Mount the sshfs drive.') | |
parser.add_argument('-u', | |
action='store_true', default=False, | |
dest='unmount', | |
help='Unmount the sshfs drive.') | |
parser.add_argument('-r', | |
action='store_true', default=False, | |
dest='remount', | |
help='Remount the sshfs drive.') | |
args = vars(parser.parse_args()) | |
hotFunc = None | |
if args["mount"]: | |
hotFunc = mnt | |
elif args["unmount"]: | |
hotFunc = umnt | |
elif args["remount"]: | |
hotFunc = rmnt | |
if hotFunc is not None: | |
os.system(hotFunc(args['devNum'])) | |
else: | |
print "No operation specified." | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment