3 # Samba-specific bits for optparse
4 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 from credentials import Credentials
23 class SambaOptions(optparse.OptionGroup):
24 def __init__(self, parser):
25 optparse.OptionGroup.__init__(self, parser, "Samba Common Options")
26 self.add_option("-s", "--configfile", type="string", metavar="FILE",
27 help="Configuration file")
30 class VersionOptions(optparse.OptionGroup):
31 def __init__(self, parser):
32 optparse.OptionGroup.__init__(self, parser, "Version Options")
35 class CredentialsOptions(optparse.OptionGroup):
36 def __init__(self, parser):
37 optparse.OptionGroup.__init__(self, parser, "Credentials Options")
38 self.add_option("--simple-bind-dn", metavar="DN", action="callback",
39 callback=self._set_simple_bind_dn, type=str,
40 help="DN to use for a simple bind")
41 self.add_option("--password", metavar="PASSWORD", action="callback",
42 help="Password", type=str, callback=self._set_password)
43 self.add_option("-U", "--username", metavar="USERNAME",
44 action="callback", type=str,
45 help="Username", callback=self._parse_username)
46 self.add_option("-W", "--workgroup", metavar="WORKGROUP",
47 action="callback", type=str,
48 help="Workgroup", callback=self._parse_workgroup)
49 self.creds = Credentials()
51 def _parse_username(self, option, opt_str, arg, parser):
52 self.creds.parse_string(arg)
54 def _parse_workgroup(self, option, opt_str, arg, parser):
55 self.creds.set_domain(arg)
57 def _set_password(self, option, opt_str, arg, parser):
58 self.creds.set_password(arg)
60 def _set_simple_bind_dn(self, option, opt_str, arg, parser):
61 self.creds.set_bind_dn(arg)
63 def get_credentials(self):