It took me a while to figure how to add custom arguments in python-fuse, so I want to document how I got it to work. Maybe it would have been compeltely clear to someone who is not so new to python, but the examples didn’t seem complete or obvious to me.
An important thing that helped me, buried in the python-fuse api docs, is the “basic usage” statement for the Fuse class:
- add options to parser
- call parse
- call main
Here’s an example of the code that adds a new option:
(Note: This is in the
main() function in the FedoraFs.py file; and server is an instance of the FedoraFS class. This follows the structure of all the examples and tutorials I saw.)
Now when I run ./FedoraFs.py -h I get an additional option:
-o host=HOSTNAME fedora server host name [default: localhost]
The thing I couldn’t figure out from the documentation and examples was how to actually use the values passed in on the command line. Here’s how I got it to work (there may be other or better ways):
- Add the new options as variables to my fuse class and set the defaults in my init function, e.g. ``self.host = “localhost”
- Instruct parse to set option values in the current instance of FedoraFS fuse class:
- Use options variables in fuse class main function, after they have been set (rather than in the init). In this case, it looks like this:
Note that in the initial code sample where I am adding the option, I’m using the server variable server.host (unlike all the examples, which seem to use plaintext defaults here), so that I only have to define my default values once. Perhaps it would also work to define the server variables in the init but leave them blank and let the parser set all the values (it’s not clear to me if the parser sets all the values, including defaults, or only the non-defaults that are set by the user).