Advertise filters param in discovery doc.
[arvados.git] / sdk / python / bin / arv-mount
1 #!/usr/bin/env python
2
3 from arvados.fuse import * 
4 import arvados
5 import subprocess
6 import argparse
7
8 if __name__ == '__main__':
9     # Handle command line parameters
10     parser = argparse.ArgumentParser(
11         description='Mount Keep data under the local filesystem.',
12         epilog="""
13 Note: When using the --exec feature, you must either specify the
14 mountpoint before --exec, or mark the end of your --exec arguments
15 with "--".
16 """)
17     parser.add_argument('mountpoint', type=str, help="""Mount point.""")
18     parser.add_argument('--collection', type=str, help="""Collection locator""")
19     parser.add_argument('--debug', action='store_true', help="""Debug mode""")
20     parser.add_argument('--exec', type=str, nargs=argparse.REMAINDER,
21                         dest="exec_args", metavar=('command', 'args', '...', '--'),
22                         help="""Mount, run a command, then unmount and exit""")
23
24     args = parser.parse_args()
25
26     # Create the request handler
27     operations = Operations(os.getuid(), os.getgid())
28
29     if args.collection != None:
30         # Set up the request handler with the collection at the root
31         e = operations.inodes.add_entry(Directory(llfuse.ROOT_INODE))
32         operations.inodes.load_collection(e, arvados.CollectionReader(arvados.Keep.get(args.collection)))
33     else:
34         # Set up the request handler with the 'magic directory' at the root
35         operations.inodes.add_entry(MagicDirectory(llfuse.ROOT_INODE, operations.inodes))
36
37     # FUSE options, see mount.fuse(8)
38     opts = []
39
40     # Enable FUSE debugging (logs each FUSE request)
41     if args.debug:
42         opts += ['debug']    
43     
44     # Initialize the fuse connection
45     llfuse.init(operations, args.mountpoint, opts)
46
47     if args.exec_args:
48         t = threading.Thread(None, lambda: llfuse.main())
49         t.start()
50
51         # wait until the driver is finished initializing
52         operations.initlock.wait()
53
54         try:
55             rc = subprocess.call(args.exec_args, shell=False)
56         except:
57             rc = 255
58         finally:
59             subprocess.call(["fusermount", "-u", "-z", args.mountpoint])
60
61         exit(rc)
62     else:
63         llfuse.main()