Get users zarafa-search index file location

From Zarafa wiki

Revision as of 09:58, 24 May 2013 by Ddebyttere (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Example: ./user2indexlocation.py username

Save as user2indexlocation.py:

#!/usr/bin/env python

from MAPI import *
from MAPI.Util import *
import sys
import re

def read_config(filename):
    """

    Get the value of a config file variable
    The value is separated by an equal character
    """
    r = re.compile(r'^\s*(\S+)\s*=\s*([^\n\r]*?)[\s\n\r]?$')
    l = []
    for line in open(filename, 'r'):
        if line.startswith('#'):
            continue
        m = r.match(line)
        if m:
            l.append(m.groups())
    return dict(l)

if len(sys.argv) < 2: # Check if username input is present, otherwise exit.
    sys.exit('Usage: %s username' % sys.argv[0])

indexPath = read_config('/etc/zarafa/search.cfg')['index_path'] # Read index_path variable from config.

s = OpenECSession(sys.argv[1], '', 'file:///var/run/zarafa') # Open new user session
st = GetDefaultStore(s) # Get the users default store

# Print the indexPath/PR_MAPPING_SIGNATURE-PR_RECORD_KEY.kct
# E.g. /var/lib/zarafa/index/7B722BFC3AA542C1BE4F0DE9CF92D1EB-9B003200E1944B6ABF15378C2FE90AB5.kct
print 'Index file is at:', indexPath+ st.GetProps([PR_MAPPING_SIGNATURE], 0)[0].Value.encode('hex').upper()+ "-" +st.GetProps([PR_RECORD_KEY], 0)[0].Value.encode('hex').upper()+ ".kct"
Personal tools