python: use '#!/usr/bin/env python' to cope with varying install locations
[mat/samba.git] / source4 / scripting / bin / enablerecyclebin
1 #!/usr/bin/env python
2 #
3 # enabled the Recycle Bin optional feature
4 #
5 import base64
6 import optparse
7 import os
8 import sys
9
10 # Find right directory when running from source tree
11 sys.path.insert(0, "bin/python")
12
13 import samba
14 from samba import getopt as options, Ldb
15 from ldb import SCOPE_SUBTREE, SCOPE_BASE, LdbError
16 import sys
17 import ldb
18 from samba.auth import system_session
19
20 parser = optparse.OptionParser("enablerecyclebin <URL>")
21 sambaopts = options.SambaOptions(parser)
22 parser.add_option_group(sambaopts)
23 credopts = options.CredentialsOptions(parser)
24 parser.add_option_group(credopts)
25 parser.add_option_group(options.VersionOptions(parser))
26
27 opts, args = parser.parse_args()
28 opts.dump_all = True
29
30 if len(args) != 1:
31     parser.print_usage()
32     sys.exit(1)
33
34 url = args[0]
35
36 lp_ctx = sambaopts.get_loadparm()
37
38 creds = credopts.get_credentials(lp_ctx)
39 sam_ldb = Ldb(url, session_info=system_session(), credentials=creds, lp=lp_ctx)
40
41 # get the rootDSE
42 res = sam_ldb.search(base="", expression="", scope=SCOPE_BASE, attrs=["configurationNamingContext"])
43 rootDse = res[0]
44
45 configbase=rootDse["configurationNamingContext"]
46
47 # enable the feature
48 msg = ldb.Message()
49 msg.dn = ldb.Dn(sam_ldb, "")
50 msg["enableOptionalFeature"] = ldb.MessageElement(
51                              "CN=Partitions," +  str(configbase) + ":766ddcd8-acd0-445e-f3b9-a7f9b6744f2a",
52                              ldb.FLAG_MOD_ADD, "enableOptionalFeature")
53 res = sam_ldb.modify(msg)
54
55 print "Recycle Bin feature enabled"