From 2227860a793dbde0b41e6ba1a720ac0d161ad784 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 21 Dec 2008 23:05:35 +0100 Subject: Fix more tests, improve repr() functions for various Python types. --- source4/scripting/python/samba/provision.py | 6 +++--- source4/scripting/python/samba/samba3.py | 15 ++++++++++----- 2 files changed, 13 insertions(+), 8 deletions(-) (limited to 'source4/scripting/python') diff --git a/source4/scripting/python/samba/provision.py b/source4/scripting/python/samba/provision.py index 9cd5c0e162..150e5c00df 100644 --- a/source4/scripting/python/samba/provision.py +++ b/source4/scripting/python/samba/provision.py @@ -80,6 +80,7 @@ class ProvisionPaths(object): self.olmmrserveridsconf = None self.olmmrsyncreplconf = None + class ProvisionNames(object): def __init__(self): self.rootdn = None @@ -362,7 +363,8 @@ def make_smbconf(smbconf, setup_path, hostname, domain, realm, serverrole, default_lp = param.LoadParm() #Load non-existant file - default_lp.load(smbconf) + if os.path.exists(smbconf): + default_lp.load(smbconf) if targetdir is not None: privatedir_line = "private dir = " + os.path.abspath(os.path.join(targetdir, "private")) @@ -920,8 +922,6 @@ def provision(setup_dir, message, session_info, if domainsid is None: domainsid = security.random_sid() - else: - domainsid = security.Sid(domainsid) if policyguid is None: policyguid = str(uuid.uuid4()) diff --git a/source4/scripting/python/samba/samba3.py b/source4/scripting/python/samba/samba3.py index 1dc90bfcf3..c8ddbc8864 100644 --- a/source4/scripting/python/samba/samba3.py +++ b/source4/scripting/python/samba/samba3.py @@ -666,12 +666,15 @@ class ParamFile(object): Does not use a parameter table, unlike the "normal". """ - def __init__(self): - self._sections = {} + def __init__(self, sections=None): + self._sections = sections or {} def _sanitize_name(self, name): return name.strip().lower().replace(" ","") + def __repr__(self): + return "ParamFile(%r)" % self._sections + def read(self, filename): """Read a file. @@ -683,7 +686,7 @@ class ParamFile(object): if not l: continue if l[0] == "[" and l[-1] == "]": - section = self._sanitize_name(l[1:-2]) + section = self._sanitize_name(l[1:-1]) self._sections.setdefault(section, {}) elif "=" in l: (k, v) = l.split("=", 1) @@ -704,7 +707,9 @@ class ParamFile(object): if not section in self._sections: return None param = self._sanitize_name(param) - return self._sections[section].get(param) + if not param in self._sections[section]: + return None + return self._sections[section][param].strip() def __getitem__(self, section): return self._sections[section] @@ -745,7 +750,7 @@ class Samba3(object): def get_sam_db(self): lp = self.get_conf() - backends = str(lp.get("passdb backend")).split(" ") + backends = (lp.get("passdb backend") or "").split(" ") if ":" in backends[0]: (name, location) = backends[0].split(":", 2) else: -- cgit