mirror of
https://github.com/samba-team/samba.git
synced 2025-08-02 00:22:11 +03:00
s4/net: Pass all arguments through to the Python commands.
This commit is contained in:
committed by
Jelmer Vernooij
parent
e60a40e287
commit
433f58f5a7
@ -49,7 +49,7 @@ cp setup/ad-schema/*.txt $SETUPDIR/ad-schema || exit 1
|
||||
cp setup/display-specifiers/*.txt $SETUPDIR/display-specifiers || exit 1
|
||||
|
||||
echo "Installing sbin scripts from setup/*"
|
||||
for p in domainlevel enableaccount newuser provision setexpiry setpassword
|
||||
for p in enableaccount newuser provision setexpiry setpassword
|
||||
do
|
||||
cp setup/$p $SBINDIR || exit 1
|
||||
chmod a+x $SBINDIR/$p
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
import optparse
|
||||
from samba import getopt as options, Ldb
|
||||
import sys
|
||||
|
||||
|
||||
class Option(optparse.Option):
|
||||
@ -82,7 +83,11 @@ class Command(object):
|
||||
if len(args) < len(self.takes_args):
|
||||
self.usage(args)
|
||||
return -1
|
||||
try:
|
||||
return self.run(*args, **kwargs)
|
||||
except CommandError, e:
|
||||
print >>sys.stderr, "ERROR: %s" % e
|
||||
return -1
|
||||
|
||||
def run(self):
|
||||
"""Run the command. This should be overriden by all subclasses."""
|
||||
@ -97,11 +102,7 @@ class SuperCommand(Command):
|
||||
def run(self, subcommand, *args, **kwargs):
|
||||
if not subcommand in subcommands:
|
||||
print >>sys.stderr, "ERROR: No such subcommand '%s'" % subcommand
|
||||
try:
|
||||
return subcommands[subcommand].run(*args, **kwargs)
|
||||
except CommandError, e:
|
||||
print >>sys.stderr, "ERROR: %s" % e.message
|
||||
return -1
|
||||
|
||||
def usage(self, subcommand=None, *args, **kwargs):
|
||||
if subcommand is None:
|
||||
|
@ -130,7 +130,6 @@ int net_run_function(struct net_context *ctx,
|
||||
int (*usage_fn)(struct net_context *ctx, int argc, const char **argv))
|
||||
{
|
||||
int i;
|
||||
PyObject *py_cmds, *py_cmd;
|
||||
|
||||
if (argc == 0) {
|
||||
return usage_fn(ctx, argc, argv);
|
||||
@ -144,17 +143,6 @@ int net_run_function(struct net_context *ctx,
|
||||
return functable[i].fn(ctx, argc-1, argv+1);
|
||||
}
|
||||
|
||||
py_cmds = py_commands();
|
||||
if (py_cmds == NULL) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
py_cmd = PyDict_GetItemString(py_cmds, argv[0]);
|
||||
if (py_cmd != NULL) {
|
||||
return py_call_with_string_args(py_cmd, "_run",
|
||||
argc-1, argv+1);
|
||||
}
|
||||
|
||||
d_printf("No command: %s\n", argv[0]);
|
||||
return usage_fn(ctx, argc, argv);
|
||||
}
|
||||
@ -288,6 +276,7 @@ static int binary_net(int argc, const char **argv)
|
||||
int opt,i;
|
||||
int rc;
|
||||
int argc_new;
|
||||
PyObject *py_cmds, *py_cmd;
|
||||
const char **argv_new;
|
||||
struct tevent_context *ev;
|
||||
struct net_context *ctx = NULL;
|
||||
@ -352,6 +341,19 @@ static int binary_net(int argc, const char **argv)
|
||||
Py_Initialize();
|
||||
py_update_path("bin"); /* FIXME: Can't assume this is always the case */
|
||||
|
||||
py_cmds = py_commands();
|
||||
if (py_cmds == NULL) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
py_cmd = PyDict_GetItemString(py_cmds, argv[1]);
|
||||
if (py_cmd != NULL) {
|
||||
rc = py_call_with_string_args(py_cmd, "_run",
|
||||
argc-2, argv+2);
|
||||
talloc_free(ev);
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = net_run_function(ctx, argc_new-1, argv_new+1, net_functable,
|
||||
net_usage);
|
||||
|
||||
|
Reference in New Issue
Block a user