#NEWLINE# def command_setup( self , * args ) : #NEWLINE# #INDENT# 'Defines a new sftp file system configuration or edits an old one with the same id.\n        Usage: sftpman setup {options}\n        Available {options}:\n            --id={unique system identifier}\n                You use this to recognize and manage this sftp system.\n                It determines what the local mount point is.\n                If `--id=example`, the filesystem will be mounted to: `/mnt/sshfs/example`\n            --host={host to connect to}\n            --port={port to connect to} [default: 22]\n            --user={username to authenticate with} [default: current user]\n            --mount_opt={option to pass to sshfs} [optional] [can be passed more than once]\n                Example: --mount_opt="follow_symlinks" --mount_opt="workaround=rename"\n                `sshfs --help` tells you what sshfs options are available\n            --mount_point={remote path to mount}\n            --auth_method={method}\n                Specifies the authentication method.\n                Can be `password` or `publickey`. [default: publickey]\n            --ssh_key={path to the ssh key to use for authentication}\n                Only applies if auth_method is `publickey`.\n            --cmd_before_mount={command to run before mounting} [default: /bin/true]\n                Allows you to run a custom command every time this system is mounted.\n        ' #NEWLINE# def usage( ) : #NEWLINE# #INDENT# print ( self . command_setup . __doc__ ) #NEWLINE# sys . exit ( 1 ) #NEWLINE# #UNINDENT# if ( len ( args ) == 0 ) : #NEWLINE# #INDENT# usage ( ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# fields = [ 'id' , 'host' , 'port' , 'user' , 'mount_opt' , 'mount_point' , 'ssh_key' , 'cmd_before_mount' , 'auth_method' ] #NEWLINE# ( opts , _ ) = getopt . getopt ( args , '' , [ ( '%s=' % s ) for s in fields ] ) #NEWLINE# #UNINDENT# except getopt . GetoptError as e : #NEWLINE# #INDENT# sys . stderr . write ( ( 'Error: %s\n\n' % e ) ) #NEWLINE# usage ( ) #NEWLINE# #UNINDENT# system = SystemModel ( ) #NEWLINE# mount_opts = [ ] #NEWLINE# for ( name , value ) in opts : #NEWLINE# #INDENT# name = name . lstrip ( '-' ) #NEWLINE# if ( not hasattr ( system , name ) ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if ( name == 'mount_opt' ) : #NEWLINE# #INDENT# mount_opts . append ( value ) #NEWLINE# continue #NEWLINE# #UNINDENT# setattr ( system , name , value ) #NEWLINE# #UNINDENT# system . mount_opts = mount_opts #NEWLINE# ( is_valid , errors ) = system . validate ( ) #NEWLINE# if ( not is_valid ) : #NEWLINE# #INDENT# sys . stderr . write ( 'Invalid data found:\n' ) #NEWLINE# for ( field_name , msg ) in errors : #NEWLINE# #INDENT# sys . stderr . write ( ( ' - %s / %s\n' % ( field_name , msg ) ) ) #NEWLINE# #UNINDENT# sys . stderr . write ( '\n' ) #NEWLINE# usage ( ) #NEWLINE# sys . exit ( 1 ) #NEWLINE# #UNINDENT# system . save ( self . environment ) #NEWLINE# print ( 'Configuration created.' ) #NEWLINE# print ( ( 'You can try mounting now: `sftpman mount %s`' % system . id ) )