#!/usr/bin/env python # -*- coding: utf-8 -*- import json import os import subprocess import sys def main(): """Main entry point""" if (len(sys.argv) != 2): sys.exit('Invalid parameter. Usage: {0} \n'.format( sys.argv[0])) cstm_error = '' try: cstm_error = 'Could not open config (~/.smount.json)' with open(os.path.expanduser('~/.smount.json')) as fp: config_dict = json.load(fp) cstm_error = 'Invalid / nonexistent mapping: {0}'.format(sys.argv[1]) data = config_dict[sys.argv[1]] cstm_error = 'system() error' args = ['/usr/bin/sshfs'] if data.get('options'): for opt in data.get('options'): args.extend(['-o', opt]) args.extend([data['src'], data['dest']]) subprocess.check_call(args) except subprocess.CalledProcessError as e: print('Execution error: {0}'.format(e), file=sys.stderr, flush=True) except Exception: print('Error: {0}'.format(cstm_error), file=sys.stderr, flush=True) if __name__ == '__main__': main()