diff options
Diffstat (limited to 'smount.py')
| -rwxr-xr-x | smount.py | 20 |
1 files changed, 11 insertions, 9 deletions
| @@ -1,5 +1,4 @@ | |||
| 1 | #!/usr/bin/env python | 1 | #!/usr/bin/env python |
| 2 | # -*- coding: utf-8 -*- | ||
| 3 | 2 | ||
| 4 | import json | 3 | import json |
| 5 | import os | 4 | import os |
| @@ -9,27 +8,30 @@ import sys | |||
| 9 | 8 | ||
| 10 | def main(): | 9 | def main(): |
| 11 | """Main entry point""" | 10 | """Main entry point""" |
| 12 | if (len(sys.argv) != 2): | 11 | if len(sys.argv) != 2: |
| 13 | sys.exit('Invalid parameter. Usage: {0} <mapping>\n'.format( | 12 | sys.exit(f'Invalid parameter. Usage: {sys.argv[0]} <mapping>\n') |
| 14 | sys.argv[0])) | 13 | |
| 15 | cstm_error = '' | 14 | cstm_error = '' |
| 15 | |||
| 16 | try: | 16 | try: |
| 17 | cstm_error = 'Could not open config (~/.smount.json)' | 17 | cstm_error = 'Could not open config (~/.smount.json)' |
| 18 | |||
| 18 | with open(os.path.expanduser('~/.smount.json')) as fp: | 19 | with open(os.path.expanduser('~/.smount.json')) as fp: |
| 19 | config_dict = json.load(fp) | 20 | config_dict = json.load(fp) |
| 20 | cstm_error = 'Invalid / nonexistent mapping: {0}'.format(sys.argv[1]) | 21 | |
| 22 | cstm_error = f'Invalid / nonexistent mapping: {sys.argv[1]}' | ||
| 21 | data = config_dict[sys.argv[1]] | 23 | data = config_dict[sys.argv[1]] |
| 22 | cstm_error = 'system() error' | 24 | cstm_error = 'subprocess error' |
| 23 | args = ['/usr/bin/sshfs'] | 25 | args = ['/usr/bin/sshfs'] |
| 24 | if data.get('options'): | 26 | if data.get('options'): |
| 25 | for opt in data.get('options'): | 27 | for opt in data.get('options'): |
| 26 | args.extend(['-o', opt]) | 28 | args.extend(['-o', opt]) |
| 27 | args.extend([data['src'], data['dest']]) | 29 | args.extend([data['src'], data['dest']]) |
| 28 | subprocess.check_call(args) | 30 | subprocess.check_call(args) |
| 29 | except subprocess.CalledProcessError as e: | 31 | except subprocess.CalledProcessError as err: |
| 30 | print('Execution error: {0}'.format(e), file=sys.stderr, flush=True) | 32 | print(f'Execution error: {err}', file=sys.stderr, flush=True) |
| 31 | except Exception: | 33 | except Exception: |
| 32 | print('Error: {0}'.format(cstm_error), file=sys.stderr, flush=True) | 34 | print(f'Error: {cstm_error}', file=sys.stderr, flush=True) |
| 33 | 35 | ||
| 34 | 36 | ||
| 35 | if __name__ == '__main__': | 37 | if __name__ == '__main__': |
