mirror of
https://github.com/samba-team/samba.git
synced 2025-07-15 16:59:09 +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
|
cp setup/display-specifiers/*.txt $SETUPDIR/display-specifiers || exit 1
|
||||||
|
|
||||||
echo "Installing sbin scripts from setup/*"
|
echo "Installing sbin scripts from setup/*"
|
||||||
for p in domainlevel enableaccount newuser provision setexpiry setpassword
|
for p in enableaccount newuser provision setexpiry setpassword
|
||||||
do
|
do
|
||||||
cp setup/$p $SBINDIR || exit 1
|
cp setup/$p $SBINDIR || exit 1
|
||||||
chmod a+x $SBINDIR/$p
|
chmod a+x $SBINDIR/$p
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
import optparse
|
import optparse
|
||||||
from samba import getopt as options, Ldb
|
from samba import getopt as options, Ldb
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
class Option(optparse.Option):
|
class Option(optparse.Option):
|
||||||
@ -82,7 +83,11 @@ class Command(object):
|
|||||||
if len(args) < len(self.takes_args):
|
if len(args) < len(self.takes_args):
|
||||||
self.usage(args)
|
self.usage(args)
|
||||||
return -1
|
return -1
|
||||||
return self.run(*args, **kwargs)
|
try:
|
||||||
|
return self.run(*args, **kwargs)
|
||||||
|
except CommandError, e:
|
||||||
|
print >>sys.stderr, "ERROR: %s" % e
|
||||||
|
return -1
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
"""Run the command. This should be overriden by all subclasses."""
|
"""Run the command. This should be overriden by all subclasses."""
|
||||||
@ -97,11 +102,7 @@ class SuperCommand(Command):
|
|||||||
def run(self, subcommand, *args, **kwargs):
|
def run(self, subcommand, *args, **kwargs):
|
||||||
if not subcommand in subcommands:
|
if not subcommand in subcommands:
|
||||||
print >>sys.stderr, "ERROR: No such subcommand '%s'" % subcommand
|
print >>sys.stderr, "ERROR: No such subcommand '%s'" % subcommand
|
||||||
try:
|
|
||||||
return subcommands[subcommand].run(*args, **kwargs)
|
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):
|
def usage(self, subcommand=None, *args, **kwargs):
|
||||||
if subcommand is None:
|
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 (*usage_fn)(struct net_context *ctx, int argc, const char **argv))
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
PyObject *py_cmds, *py_cmd;
|
|
||||||
|
|
||||||
if (argc == 0) {
|
if (argc == 0) {
|
||||||
return usage_fn(ctx, argc, argv);
|
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);
|
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]);
|
d_printf("No command: %s\n", argv[0]);
|
||||||
return usage_fn(ctx, argc, argv);
|
return usage_fn(ctx, argc, argv);
|
||||||
}
|
}
|
||||||
@ -288,6 +276,7 @@ static int binary_net(int argc, const char **argv)
|
|||||||
int opt,i;
|
int opt,i;
|
||||||
int rc;
|
int rc;
|
||||||
int argc_new;
|
int argc_new;
|
||||||
|
PyObject *py_cmds, *py_cmd;
|
||||||
const char **argv_new;
|
const char **argv_new;
|
||||||
struct tevent_context *ev;
|
struct tevent_context *ev;
|
||||||
struct net_context *ctx = NULL;
|
struct net_context *ctx = NULL;
|
||||||
@ -352,6 +341,19 @@ static int binary_net(int argc, const char **argv)
|
|||||||
Py_Initialize();
|
Py_Initialize();
|
||||||
py_update_path("bin"); /* FIXME: Can't assume this is always the case */
|
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,
|
rc = net_run_function(ctx, argc_new-1, argv_new+1, net_functable,
|
||||||
net_usage);
|
net_usage);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user