Created
April 4, 2012 14:22
-
-
Save mitchellrj/2301536 to your computer and use it in GitHub Desktop.
Clear WebDAV locks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def unlockAllObjects(app, path): | |
lockedobjs = findLockedObjects(app, path) | |
for (o, p, i) in lockedobjs: | |
errs = False | |
for l in [li['token'] for li in i]: | |
try: | |
o.wl_delLock(l) | |
except: | |
errs = True | |
if errs: | |
# Only run clearLocks if we can't delete all locks normally | |
o.wl_clearLocks() | |
################################################################################ | |
# Stolen from App.DavLockManager: | |
################################# | |
def findLockedObjects(app, frompath=''): | |
if frompath: | |
if frompath[0] == '/': frompath = frompath[1:] | |
# since the above will turn '/' into an empty string, check | |
# for truth before chopping a final slash | |
if frompath and frompath[-1] == '/': frompath= frompath[:-1] | |
# Now we traverse to the node specified in the 'frompath' if | |
# the user chose to filter the search, and run a ZopeFind with | |
# the expression 'wl_isLocked()' to find locked objects. | |
obj = app.unrestrictedTraverse(frompath) | |
lockedobjs = __findapply(obj, path=frompath) | |
return lockedobjs | |
# Changed original function to return object, rather than the path | |
def __findapply(obj, result=None, path=''): | |
# recursive function to actually dig through and find the locked | |
# objects. | |
if result is None: | |
result = [] | |
base = aq_base(obj) | |
if not hasattr(base, 'objectItems'): | |
return result | |
try: items = obj.objectItems() | |
except: return result | |
addresult = result.append | |
for id, ob in items: | |
if path: p = '%s/%s' % (path, id) | |
else: p = id | |
dflag = hasattr(ob, '_p_changed') and (ob._p_changed == None) | |
bs = aq_base(ob) | |
if wl_isLocked(ob): | |
li = [] | |
addlockinfo = li.append | |
for token, lock in ob.wl_lockItems(): | |
addlockinfo({'owner':lock.getCreatorPath(), | |
'token':token}) | |
addresult((ob, p, li)) | |
dflag = 0 | |
if hasattr(bs, 'objectItems'): | |
__findapply(ob, result, p) | |
if dflag: ob._p_deactivate() | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment