from samba.samdb import SamDB
from io import StringIO
from samba.netcmd.main import cmd_sambatool
+from optparse import OptionParser
+import samba.getopt as options
import samba.tests
def getSamDB(*argv):
"""a convenience function to get a samdb instance so that we can query it"""
- # We build a fake command to get the options created the same
- # way the command classes do it. It would be better if the command
- # classes had a way to more cleanly do this, but this lets us write
- # tests for now
- cmd = cmd_sambatool.subcommands["user"].subcommands["setexpiry"]
- parser, optiongroups = cmd._create_parser("user")
+ parser = OptionParser()
+ sambaopts = options.SambaOptions(parser)
+ credopts = options.CredentialsOptions(parser)
+ parser.add_option("-H", "--URL",
+ help="LDB URL for database or target server",
+ type=str, metavar="URL", dest="H")
opts, args = parser.parse_args(list(argv))
- # Filter out options from option groups
- args = args[1:]
- kwargs = dict(opts.__dict__)
- for option_group in parser.option_groups:
- for option in option_group.option_list:
- if option.dest is not None:
- del kwargs[option.dest]
- kwargs.update(optiongroups)
-
- H = kwargs.get("H", None)
- sambaopts = kwargs.get("sambaopts", None)
- credopts = kwargs.get("credopts", None)
lp = sambaopts.get_loadparm()
creds = credopts.get_credentials(lp, fallback_machine=True)
- samdb = SamDB(url=H, session_info=system_session(),
- credentials=creds, lp=lp)
- return samdb
+ return SamDB(url=opts.H, session_info=system_session(),
+ credentials=creds, lp=lp)
def _run(self, *argv):
"""run a samba-tool command"""