python: bulk replace dict.iteritems to items for py3
[kai/samba-autobuild/.git] / python / samba / netcmd / main.py
1 # Unix SMB/CIFS implementation.
2 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2011
3 #
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 #
17
18 """The main samba-tool command implementation."""
19
20 from samba import getopt as options
21
22 from samba.netcmd import SuperCommand
23
24 class cache_loader(dict):
25     """
26     We only load subcommand tools if they are actually used.
27     This significantly reduces the amount of time spent starting up
28     samba-tool
29     """
30     def __getitem__(self, attr):
31         item = dict.__getitem__(self, attr)
32         if item is None:
33             package = 'nettime' if attr == 'time' else attr
34             self[attr] = getattr(__import__('samba.netcmd.%s' % package,
35                                             fromlist=['cmd_%s' % attr]),
36                                  'cmd_%s' % attr)()
37         return dict.__getitem__(self, attr)
38
39     def get(self, attr, default=None):
40         try:
41             return self[attr]
42         except KeyError:
43             return default
44
45     def items(self):
46         for key in self:
47             yield (key, self[key])
48
49
50 class cmd_sambatool(SuperCommand):
51     """Main samba administration tool."""
52
53     takes_optiongroups = {
54         "versionopts": options.VersionOptions,
55         }
56
57     subcommands = cache_loader()
58
59     subcommands["computer"] = None
60     subcommands["dbcheck"] = None
61     subcommands["delegation"] = None
62     subcommands["dns"] = None
63     subcommands["domain"] = None
64     subcommands["drs"] = None
65     subcommands["dsacl"] = None
66     subcommands["fsmo"] = None
67     subcommands["gpo"] = None
68     subcommands["group"] = None
69     subcommands["ldapcmp"] = None
70     subcommands["ntacl"] = None
71     subcommands["rodc"] = None
72     subcommands["sites"] = None
73     subcommands["spn"] = None
74     subcommands["testparm"] = None
75     subcommands["time"] = None
76     subcommands["user"] = None
77     subcommands["ou"] = None
78     subcommands["processes"] = None
79     subcommands["visualize"] = None