Move python modules from source4/scripting/python/ to python/.
[samba.git] / python / samba / netcmd / time.py
1 # time
2 #
3 # Copyright Jelmer Vernooij 2010 <jelmer@samba.org>
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 #
18
19 import samba.getopt as options
20 import common
21 from samba.net import Net
22
23 from samba.netcmd import (
24     Command,
25     )
26
27 class cmd_time(Command):
28     """Retrieve the time on a server.
29
30 This command returns the date and time of the Active Directory server specified on the command.  The server name specified may be the local server or a remote server.  If the servername is not specified, the command returns the time and date of the local AD server.
31
32 Example1:
33 samba-tool time samdom.example.com
34
35 Example1 returns the date and time of the server samdom.example.com.
36
37 Example2:
38 samba-tool time
39
40 Example2 return the date and time of the local server.
41 """
42     synopsis = "%prog [server-name] [options]"
43
44     takes_optiongroups = {
45         "sambaopts": options.SambaOptions,
46         "credopts": options.CredentialsOptions,
47         "versionopts": options.VersionOptions,
48         }
49
50     takes_args = ["server_name?"]
51
52     def run(self, server_name=None, credopts=None, sambaopts=None,
53             versionopts=None):
54         lp = sambaopts.get_loadparm()
55         creds = credopts.get_credentials(lp, fallback_machine=True)
56         net = Net(creds, lp, server=credopts.ipaddress)
57         if server_name is None:
58             server_name = common.netcmd_dnsname(lp)
59         self.outf.write(net.time(server_name)+"\n")