summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2012-02-18 23:59:48 +0100
committerJelmer Vernooij <jelmer@samba.org>2012-02-18 23:59:48 +0100
commita977de9fdfc2cad9724fd46995258a17f05d5b73 (patch)
tree431265ab6b0a0b5dd7538870d7124e164e242b9d /source4
parentc29e0258e0b9d4cbf05e1ff30f8787b314b23b04 (diff)
downloadsamba-a977de9fdfc2cad9724fd46995258a17f05d5b73.tar.gz
samba-a977de9fdfc2cad9724fd46995258a17f05d5b73.tar.bz2
samba-a977de9fdfc2cad9724fd46995258a17f05d5b73.zip
s4-python: Various formatting fixes.
Diffstat (limited to 'source4')
-rw-r--r--source4/scripting/python/samba/__init__.py11
-rw-r--r--source4/scripting/python/samba/common.py7
-rw-r--r--source4/scripting/python/samba/dbchecker.py59
-rw-r--r--source4/scripting/python/samba/tests/dcerpc/registry.py6
-rwxr-xr-xsource4/scripting/python/samba/tests/dcerpc/rpc_talloc.py3
-rw-r--r--source4/scripting/python/samba/tests/strings.py1
-rw-r--r--source4/scripting/python/samba/tests/upgrade.py9
-rw-r--r--source4/scripting/python/samba/tests/upgradeprovisionneeddc.py3
-rw-r--r--source4/scripting/python/samba/tests/xattr.py2
9 files changed, 42 insertions, 59 deletions
diff --git a/source4/scripting/python/samba/__init__.py b/source4/scripting/python/samba/__init__.py
index d81a25cbcf..20e6e70920 100644
--- a/source4/scripting/python/samba/__init__.py
+++ b/source4/scripting/python/samba/__init__.py
@@ -28,15 +28,17 @@ import os
import sys
import samba.param
+
def source_tree_topdir():
"""Return the top level source directory."""
- paths = [ "../../..", "../../../.." ]
+ paths = ["../../..", "../../../.."]
for p in paths:
topdir = os.path.normpath(os.path.join(os.path.dirname(__file__), p))
if os.path.exists(os.path.join(topdir, 'source4')):
return topdir
raise RuntimeError("unable to find top level source directory")
+
def in_source_tree():
"""Return True if we are running from within the samba source tree"""
try:
@@ -49,6 +51,7 @@ def in_source_tree():
import ldb
from samba._ldb import Ldb as _Ldb
+
class Ldb(_Ldb):
"""Simple Samba-specific LDB subclass that takes care
of setting up the modules dir, credentials pointers, etc.
@@ -166,7 +169,8 @@ class Ldb(_Ldb):
# Try to delete user/computer accounts to allow deletion of groups
self.erase_users_computers(basedn)
- # Delete the 'visible' records, and the invisble 'deleted' records (if this DB supports it)
+ # Delete the 'visible' records, and the invisble 'deleted' records (if
+ # this DB supports it)
for msg in self.search(basedn, ldb.SCOPE_SUBTREE,
"(&(|(objectclass=*)(distinguishedName=*))(!(distinguishedName=@BASEINFO)))",
[], controls=["show_deleted:0", "show_recycled:0"]):
@@ -178,7 +182,8 @@ class Ldb(_Ldb):
raise
res = self.search(basedn, ldb.SCOPE_SUBTREE,
- "(&(|(objectclass=*)(distinguishedName=*))(!(distinguishedName=@BASEINFO)))", [], controls=["show_deleted:0", "show_recycled:0"])
+ "(&(|(objectclass=*)(distinguishedName=*))(!(distinguishedName=@BASEINFO)))",
+ [], controls=["show_deleted:0", "show_recycled:0"])
assert len(res) == 0
# delete the specials
diff --git a/source4/scripting/python/samba/common.py b/source4/scripting/python/samba/common.py
index b67036cb1d..2ba60a0537 100644
--- a/source4/scripting/python/samba/common.py
+++ b/source4/scripting/python/samba/common.py
@@ -18,7 +18,10 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-import ldb, dsdb
+
+import ldb
+import dsdb
+
def confirm(msg, forced=False, allow_all=False):
"""confirm an action with the user
@@ -73,7 +76,7 @@ class dsdb_Dn(object):
syntax_oid = dsdb.DSDB_SYNTAX_STRING_DN
else:
syntax_oid = dsdb.DSDB_SYNTAX_OR_NAME
- if syntax_oid in [ dsdb.DSDB_SYNTAX_BINARY_DN, dsdb.DSDB_SYNTAX_STRING_DN ]:
+ if syntax_oid in [dsdb.DSDB_SYNTAX_BINARY_DN, dsdb.DSDB_SYNTAX_STRING_DN]:
# it is a binary DN
colons = dnstring.split(':')
if len(colons) < 4:
diff --git a/source4/scripting/python/samba/dbchecker.py b/source4/scripting/python/samba/dbchecker.py
index ff3fd6ee38..7f2c9799b0 100644
--- a/source4/scripting/python/samba/dbchecker.py
+++ b/source4/scripting/python/samba/dbchecker.py
@@ -27,11 +27,12 @@ from samba.ndr import ndr_unpack
from samba.dcerpc import drsblobs
from samba.common import dsdb_Dn
+
class dbcheck(object):
"""check a SAM database for errors"""
- def __init__(self, samdb, samdb_schema=None, verbose=False, fix=False, yes=False,
- quiet=False, in_transaction=False):
+ def __init__(self, samdb, samdb_schema=None, verbose=False, fix=False,
+ yes=False, quiet=False, in_transaction=False):
self.samdb = samdb
self.dict_oid_name = None
self.samdb_schema = (samdb_schema or samdb)
@@ -67,20 +68,14 @@ class dbcheck(object):
if error_count != 0 and not self.fix:
self.report("Please use --fix to fix these errors")
-
self.report('Checked %u objects (%u errors)' % (len(res), error_count))
-
return error_count
-
def report(self, msg):
'''print a message unless quiet is set'''
if not self.quiet:
print(msg)
-
- ################################################################
- # a local confirm function that obeys the --fix and --yes options
def confirm(self, msg, allow_all=False, forced=False):
'''confirm a change'''
if not self.fix:
@@ -114,7 +109,6 @@ class dbcheck(object):
return True
return c
-
def do_modify(self, m, controls, msg, validate=True):
'''perform a modify with optional verbose output'''
if self.verbose:
@@ -126,9 +120,6 @@ class dbcheck(object):
return False
return True
-
- ################################################################
- # handle empty attributes
def err_empty_attribute(self, dn, attrname):
'''fix empty attributes'''
self.report("ERROR: Empty attribute %s in %s" % (attrname, dn))
@@ -143,15 +134,13 @@ class dbcheck(object):
"Failed to remove empty attribute %s" % attrname, validate=False):
self.report("Removed empty attribute %s" % attrname)
-
- ################################################################
- # handle normalisation mismatches
def err_normalise_mismatch(self, dn, attrname, values):
'''fix attribute normalisation errors'''
self.report("ERROR: Normalisation error for attribute %s in %s" % (attrname, dn))
mod_list = []
for val in values:
- normalised = self.samdb.dsdb_normalise_attributes(self.samdb_schema, attrname, [val])
+ normalised = self.samdb.dsdb_normalise_attributes(
+ self.samdb_schema, attrname, [val])
if len(normalised) != 1:
self.report("Unable to normalise value '%s'" % val)
mod_list.append((val, ''))
@@ -168,7 +157,8 @@ class dbcheck(object):
(val, nval) = mod_list[i]
m['value_%u' % i] = ldb.MessageElement(val, ldb.FLAG_MOD_DELETE, attrname)
if nval != '':
- m['normv_%u' % i] = ldb.MessageElement(nval, ldb.FLAG_MOD_ADD, attrname)
+ m['normv_%u' % i] = ldb.MessageElement(nval, ldb.FLAG_MOD_ADD,
+ attrname)
if self.do_modify(m, ["relax:0", "show_recycled:1"],
"Failed to normalise attribute %s" % attrname,
@@ -179,10 +169,8 @@ class dbcheck(object):
'''see if a dsdb_Dn is the special Deleted Objects DN'''
return dsdb_dn.prefix == "B:32:18E2EA80684F11D2B9AA00C04F79F805:"
-
- ################################################################
- # handle a DN pointing to a deleted object
def err_deleted_dn(self, dn, attrname, val, dsdb_dn, correct_dn):
+ """handle a DN pointing to a deleted object"""
self.report("ERROR: target DN is deleted for %s in object %s - %s" % (attrname, dn, val))
self.report("Target GUID points at deleted DN %s" % correct_dn)
if not self.confirm_all('Remove DN link?', 'remove_all_deleted_DN_links'):
@@ -195,9 +183,8 @@ class dbcheck(object):
"Failed to remove deleted DN attribute %s" % attrname):
self.report("Removed deleted DN on attribute %s" % attrname)
- ################################################################
- # handle a missing target DN (both GUID and DN string form are missing)
def err_missing_dn_GUID(self, dn, attrname, val, dsdb_dn):
+ """handle a missing target DN (both GUID and DN string form are missing)"""
# check if its a backlink
linkID = self.samdb_schema.get_linkId_from_lDAPDisplayName(attrname)
if (linkID & 1 == 0) and str(dsdb_dn).find('DEL\\0A') == -1:
@@ -205,10 +192,8 @@ class dbcheck(object):
return
self.err_deleted_dn(dn, attrname, val, dsdb_dn, dsdb_dn)
-
- ################################################################
- # handle a missing GUID extended DN component
def err_incorrect_dn_GUID(self, dn, attrname, val, dsdb_dn, errstr):
+ """handle a missing GUID extended DN component"""
self.report("ERROR: %s component for %s in object %s - %s" % (errstr, attrname, dn, val))
controls=["extended_dn:1:1", "show_recycled:1"]
try:
@@ -236,10 +221,8 @@ class dbcheck(object):
"Failed to fix %s on attribute %s" % (errstr, attrname)):
self.report("Fixed %s on attribute %s" % (errstr, attrname))
-
- ################################################################
- # handle a DN string being incorrect
def err_dn_target_mismatch(self, dn, attrname, val, dsdb_dn, correct_dn, errstr):
+ """handle a DN string being incorrect"""
self.report("ERROR: incorrect DN string component for %s in object %s - %s" % (attrname, dn, val))
dsdb_dn.dn = correct_dn
@@ -254,8 +237,6 @@ class dbcheck(object):
"Failed to fix incorrect DN string on attribute %s" % attrname):
self.report("Fixed incorrect DN string on attribute %s" % (attrname))
- ################################################################
- # handle an unknown attribute error
def err_unknown_attribute(self, obj, attrname):
'''handle an unknown attribute error'''
self.report("ERROR: unknown attribute '%s' in %s" % (attrname, obj.dn))
@@ -269,9 +250,6 @@ class dbcheck(object):
"Failed to remove unknown attribute %s" % attrname):
self.report("Removed unknown attribute %s" % (attrname))
-
- ################################################################
- # handle a missing backlink
def err_missing_backlink(self, obj, attrname, val, backlink_name, target_dn):
'''handle a missing backlink value'''
self.report("ERROR: missing backlink attribute '%s' in %s for link %s in %s" % (backlink_name, target_dn, attrname, obj.dn))
@@ -286,9 +264,6 @@ class dbcheck(object):
"Failed to fix missing backlink %s" % backlink_name):
self.report("Fixed missing backlink %s" % (backlink_name))
-
- ################################################################
- # handle a orphaned backlink
def err_orphaned_backlink(self, obj, attrname, val, link_name, target_dn):
'''handle a orphaned backlink value'''
self.report("ERROR: orphaned backlink attribute '%s' in %s for link %s in %s" % (attrname, obj.dn, link_name, target_dn))
@@ -302,9 +277,6 @@ class dbcheck(object):
"Failed to fix orphaned backlink %s" % link_name):
self.report("Fixed orphaned backlink %s" % (link_name))
-
- ################################################################
- # specialised checking for a dn attribute
def check_dn(self, obj, attrname, syntax_oid):
'''check a DN attribute for correctness'''
error_count = 0
@@ -315,12 +287,13 @@ class dbcheck(object):
guid = dsdb_dn.dn.get_extended_component("GUID")
if guid is None:
error_count += 1
- self.err_incorrect_dn_GUID(obj.dn, attrname, val, dsdb_dn, "missing GUID")
+ self.err_incorrect_dn_GUID(obj.dn, attrname, val, dsdb_dn,
+ "missing GUID")
continue
guidstr = str(misc.GUID(guid))
- attrs=['isDeleted']
+ attrs = ['isDeleted']
linkID = self.samdb_schema.get_linkId_from_lDAPDisplayName(attrname)
reverse_link_name = self.samdb_schema.get_backlink_from_lDAPDisplayName(attrname)
if reverse_link_name is not None:
@@ -415,9 +388,6 @@ class dbcheck(object):
"Failed to fix metadata for attribute %s" % attr):
self.report("Fixed metadata for attribute %s" % attr)
-
- ################################################################
- # check one object - calls to individual error handlers above
def check_object(self, dn, attrs=['*']):
'''check one object'''
if self.verbose:
@@ -454,7 +424,6 @@ class dbcheck(object):
got_repl_property_meta_data = True
continue
-
# check for empty attributes
for val in obj[attrname]:
if val == '':
diff --git a/source4/scripting/python/samba/tests/dcerpc/registry.py b/source4/scripting/python/samba/tests/dcerpc/registry.py
index b5495c7015..c3b28520a8 100644
--- a/source4/scripting/python/samba/tests/dcerpc/registry.py
+++ b/source4/scripting/python/samba/tests/dcerpc/registry.py
@@ -27,15 +27,15 @@ class WinregTests(RpcInterfaceTestCase):
def setUp(self):
super(WinregTests, self).setUp()
- self.conn = winreg.winreg("ncalrpc:", self.get_loadparm(),
+ self.conn = winreg.winreg("ncalrpc:", self.get_loadparm(),
self.get_credentials())
def get_hklm(self):
- return self.conn.OpenHKLM(None,
+ return self.conn.OpenHKLM(None,
winreg.KEY_QUERY_VALUE | winreg.KEY_ENUMERATE_SUB_KEYS)
def test_hklm(self):
- handle = self.conn.OpenHKLM(None,
+ handle = self.conn.OpenHKLM(None,
winreg.KEY_QUERY_VALUE | winreg.KEY_ENUMERATE_SUB_KEYS)
self.conn.CloseKey(handle)
diff --git a/source4/scripting/python/samba/tests/dcerpc/rpc_talloc.py b/source4/scripting/python/samba/tests/dcerpc/rpc_talloc.py
index 9ee2850405..41286c6219 100755
--- a/source4/scripting/python/samba/tests/dcerpc/rpc_talloc.py
+++ b/source4/scripting/python/samba/tests/dcerpc/rpc_talloc.py
@@ -37,6 +37,7 @@ import talloc
talloc.enable_null_tracking()
+
class TallocTests(samba.tests.TestCase):
'''test talloc behaviour of pidl generated python code'''
@@ -54,7 +55,7 @@ class TallocTests(samba.tests.TestCase):
# we expect one block for the object, and one for the structure
self.check_blocks(partial_attribute_set, 2)
- attids = [ 1, 2, 3]
+ attids = [1, 2, 3]
partial_attribute_set.version = 1
partial_attribute_set.attids = attids
partial_attribute_set.num_attids = len(attids)
diff --git a/source4/scripting/python/samba/tests/strings.py b/source4/scripting/python/samba/tests/strings.py
index 0c96f5cb19..48ad24224e 100644
--- a/source4/scripting/python/samba/tests/strings.py
+++ b/source4/scripting/python/samba/tests/strings.py
@@ -67,6 +67,7 @@ class strcasecmp_m_Tests(samba.tests.TestCase):
class strstr_m_Tests(samba.tests.TestCase):
"""strstr_m tests in simple ASCII and unicode strings"""
+
def test_strstr_m(self):
# A, B, strstr_m(A, B)
cases = [('hello', 'hello', 'hello'),
diff --git a/source4/scripting/python/samba/tests/upgrade.py b/source4/scripting/python/samba/tests/upgrade.py
index f522831bfa..1348ca604d 100644
--- a/source4/scripting/python/samba/tests/upgrade.py
+++ b/source4/scripting/python/samba/tests/upgrade.py
@@ -22,6 +22,7 @@
from samba.upgrade import import_wins
from samba.tests import LdbTestCase
+
class WinsUpgradeTests(LdbTestCase):
def test_upgrade(self):
@@ -30,10 +31,12 @@ class WinsUpgradeTests(LdbTestCase):
}
import_wins(self.ldb, winsdb)
- self.assertEquals(['name=FOO,type=0x20'],
- [str(m.dn) for m in self.ldb.search(expression="(objectClass=winsRecord)")])
+ self.assertEquals(
+ ['name=FOO,type=0x20'],
+ [str(m.dn) for m in
+ self.ldb.search(expression="(objectClass=winsRecord)")])
def test_version(self):
import_wins(self.ldb, {})
- self.assertEquals("VERSION",
+ self.assertEquals("VERSION",
str(self.ldb.search(expression="(objectClass=winsMaxVersion)")[0]["cn"]))
diff --git a/source4/scripting/python/samba/tests/upgradeprovisionneeddc.py b/source4/scripting/python/samba/tests/upgradeprovisionneeddc.py
index 596cff6d3a..008622394e 100644
--- a/source4/scripting/python/samba/tests/upgradeprovisionneeddc.py
+++ b/source4/scripting/python/samba/tests/upgradeprovisionneeddc.py
@@ -161,7 +161,8 @@ class UpgradeProvisionWithLdbTestCase(TestCaseInTempDir):
self.assertNotEquals(oem, "")
def test_update_dns_account(self):
- update_dns_account_password(self.ldbs.sam, self.ldbs.secrets, self.names)
+ update_dns_account_password(self.ldbs.sam, self.ldbs.secrets,
+ self.names)
def test_updateOEMInfo(self):
realm = self.lp.get("realm")
diff --git a/source4/scripting/python/samba/tests/xattr.py b/source4/scripting/python/samba/tests/xattr.py
index f978ee5b2a..7b4627fdad 100644
--- a/source4/scripting/python/samba/tests/xattr.py
+++ b/source4/scripting/python/samba/tests/xattr.py
@@ -83,7 +83,7 @@ class XattrTests(TestCase):
ntacl.version = 1
open(tempf, 'w').write("empty")
try:
- self.assertRaises(IOError, samba.xattr_tdb.wrap_setxattr,
+ self.assertRaises(IOError, samba.xattr_tdb.wrap_setxattr,
os.path.join("nonexistent", "eadb.tdb"), tempf,
"user.unittests", ndr_pack(ntacl))
finally: