[PR PATCH] [Closed]: python: Add argparse samba options

github at samba.org github at samba.org
Thu Dec 13 08:48:09 UTC 2018


There's a closed pull request on the Samba Samba Github repository

python: Add argparse samba options
https://github.com/samba-team/samba/pull/178
Description: Creates samba.getarg, which mirrors the options in samba.getopt, accept these options work with the newer python argparse module (since optparse has been deprecated for some time).

import argparse
from samba import getarg as options
parser = argparse.ArgumentParser('program')
sambaopts = options.SambaOptions(parser)
credopts = options.CredentialsOptions(parser)
options.add_argument_group(parser, sambaopts)
options.add_argument_group(parser, credopts)
options.add_argument_group(parser, options.VersionOptions(parser))

There is nothing like optparse.add_option_group() anymore, argparse.add_argument_group() only accepts the parameters to the _ArgumentGroup class, instead of an instance of _ArgumentGroup. This is the reason for options.add_argument_group().
Also, the only way to write a callback is to implement an Action in argparse, hence the store() and store_true() generators.


More information about the samba-technical mailing list