uptodateness: add new module and migrate functions from visualize
authorJoe Guo <joeg@catalyst.net.nz>
Wed, 3 Oct 2018 09:21:54 +0000 (22:21 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 18 Oct 2018 04:15:24 +0000 (06:15 +0200)
Both visualize and drs cmd will have uptodateness functions.
Create a new module to reuse code.

Signed-off-by: Joe Guo <joeg@catalyst.net.nz>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13658

python/samba/netcmd/visualize.py
python/samba/uptodateness.py [new file with mode: 0644]

index 8292802326b23cc92bb73478e817bb4cbed6d265..568d111830b53eb166d1598eacc7da864f9fd902 100644 (file)
@@ -39,6 +39,10 @@ import re
 from samba.kcc import KCC, ldif_import_export
 from samba.kcc.kcc_utils import KCCError
 from samba.compat import text_type
+from samba.uptodateness import (
+    get_partition_maps,
+    get_partition,
+)
 
 COMMON_OPTIONS = [
     Option("-H", "--URL", help="LDB URL for database or target server",
@@ -207,36 +211,6 @@ def colour_hash(x):
     return '#%06x' % c
 
 
-def get_partition_maps(samdb):
-    """Generate dictionaries mapping short partition names to the
-    appropriate DNs."""
-    base_dn = samdb.domain_dn()
-    short_to_long = {
-        "DOMAIN": base_dn,
-        "CONFIGURATION": str(samdb.get_config_basedn()),
-        "SCHEMA": "CN=Schema,%s" % samdb.get_config_basedn(),
-        "DNSDOMAIN": "DC=DomainDnsZones,%s" % base_dn,
-        "DNSFOREST": "DC=ForestDnsZones,%s" % base_dn
-    }
-
-    long_to_short = {}
-    for s, l in short_to_long.items():
-        long_to_short[l] = s
-
-    return short_to_long, long_to_short
-
-
-def get_partition(samdb, part):
-    # Allow people to say "--partition=DOMAIN" rather than
-    # "--partition=DC=blah,DC=..."
-    if part is not None:
-        short_partitions, long_partitions = get_partition_maps(samdb)
-        part = short_partitions.get(part.upper(), part)
-        if part not in long_partitions:
-            raise CommandError("unknown partition %s" % part)
-    return part
-
-
 class cmd_reps(GraphCommand):
     "repsFrom/repsTo from every DSA"
 
diff --git a/python/samba/uptodateness.py b/python/samba/uptodateness.py
new file mode 100644 (file)
index 0000000..06e8f17
--- /dev/null
@@ -0,0 +1,50 @@
+# Uptodateness utils
+#
+# Copyright (C) Andrew Bartlett 2015, 2018
+# Copyright (C) Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
+# Copyright (C) Joe Guo <joeg@catalyst.net.nz>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+from samba.netcmd import CommandError
+
+
+def get_partition_maps(samdb):
+    """Generate dictionaries mapping short partition names to the
+    appropriate DNs."""
+    base_dn = samdb.domain_dn()
+    short_to_long = {
+        "DOMAIN": base_dn,
+        "CONFIGURATION": str(samdb.get_config_basedn()),
+        "SCHEMA": "CN=Schema,%s" % samdb.get_config_basedn(),
+        "DNSDOMAIN": "DC=DomainDnsZones,%s" % base_dn,
+        "DNSFOREST": "DC=ForestDnsZones,%s" % base_dn
+    }
+
+    long_to_short = {}
+    for s, l in short_to_long.items():
+        long_to_short[l] = s
+
+    return short_to_long, long_to_short
+
+
+def get_partition(samdb, part):
+    # Allow people to say "--partition=DOMAIN" rather than
+    # "--partition=DC=blah,DC=..."
+    if part is not None:
+        short_partitions, long_partitions = get_partition_maps(samdb)
+        part = short_partitions.get(part.upper(), part)
+        if part not in long_partitions:
+            raise CommandError("unknown partition %s" % part)
+    return part