Created
June 10, 2016 08:02
-
-
Save RaD/9455ad58f73684eed2faaa82fd6aac7d to your computer and use it in GitHub Desktop.
This file contains hidden or 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/bin/env python | |
| import gtk | |
| import os | |
| import subprocess | |
| clipboard = gtk.clipboard_get() | |
| stand_info = clipboard.wait_for_contents('TEXT').data.strip().split('\n') | |
| product_url = stand_info[0] | |
| if not product_url.startswith('https://'): | |
| print('Select stand info first!') | |
| os.sys.exit(1) | |
| home_dir = os.path.expanduser('~') | |
| remote_dir = 'remote' | |
| stand_dir = product_url.split('//')[1] | |
| target_dir = os.path.join(home_dir, remote_dir, stand_dir) | |
| key_dir = os.path.join(home_dir, '.ssh') | |
| if not os.path.isdir(target_dir): | |
| os.makedirs(target_dir) | |
| print('Product URL is {}'.format(product_url)) | |
| print('Available private keys:') | |
| print('\tdefault') | |
| for filename in os.listdir(key_dir): | |
| with open(os.path.join(key_dir, filename)) as f: | |
| if 'PRIVATE' in f.readline(): | |
| print('\t{}'.format(filename)) | |
| key_name = raw_input('Choose the key: ') | |
| key_path = os.path.join(key_dir, key_name) | |
| for host in stand_info[1:]: | |
| hostip, hostname = host.split() | |
| print('Create sshfs mount point for {}'.format(hostname)) | |
| mount_dir = os.path.join(target_dir, hostname) | |
| if not os.path.isdir(mount_dir): | |
| os.makedirs(mount_dir) | |
| if key_name == 'default': | |
| tpl = 'sshfs autotest@{ip}:/ {mount}' | |
| else: | |
| tpl = 'sshfs -o IdentityFile={key} autotest@{ip}:/ {mount}' | |
| command = tpl.format(key=key_path, mount=mount_dir, ip=hostip) | |
| subprocess.call(command.split()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment