From da875eda6a65f283492497f57df06c7ff57562a3 Mon Sep 17 00:00:00 2001 From: Joe Guo Date: Wed, 3 Oct 2018 22:21:54 +1300 Subject: [PATCH] uptodateness: add new module and migrate functions from visualize Both visualize and drs cmd will have uptodateness functions. Create a new module to reuse code. Signed-off-by: Joe Guo Reviewed-by: Douglas Bagnall Reviewed-by: Andrew Bartlett BUG: https://bugzilla.samba.org/show_bug.cgi?id=13658 --- python/samba/netcmd/visualize.py | 34 +++------------------- python/samba/uptodateness.py | 50 ++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 30 deletions(-) create mode 100644 python/samba/uptodateness.py diff --git a/python/samba/netcmd/visualize.py b/python/samba/netcmd/visualize.py index 8292802326b..568d111830b 100644 --- a/python/samba/netcmd/visualize.py +++ b/python/samba/netcmd/visualize.py @@ -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 index 00000000000..06e8f175b5c --- /dev/null +++ b/python/samba/uptodateness.py @@ -0,0 +1,50 @@ +# Uptodateness utils +# +# Copyright (C) Andrew Bartlett 2015, 2018 +# Copyright (C) Douglas Bagnall +# Copyright (C) Joe Guo +# +# 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 . + +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 -- 2.34.1