예제 #1
0
def summarizeRecords(directory, records):
    table = Table()

    table.addHeader((
        "UID",
        "Record Type",
        "Short Names",
        "Email Addresses",
        "Full Name",
    ))

    def formatItems(items):
        if items:
            return ", ".join(items)
        else:
            return None

    for record in records:
        table.addRow((
            record.uid,
            record.recordType,
            formatItems(record.shortNames),
            formatItems(record.emailAddresses),
            record.fullName,
        ))

    if table.rows:
        return succeed(table.toString())
    else:
        return succeed(None)
예제 #2
0
def summarizeRecords(directory, records):
    table = Table()

    table.addHeader((
        "UID",
        "Record Type",
        "Short Names",
        "Email Addresses",
        "Full Name",
    ))

    def formatItems(items):
        if items:
            return ", ".join(items)
        else:
            return None

    for record in records:
        table.addRow((
            record.uid,
            record.recordType,
            formatItems(record.shortNames),
            formatItems(record.emailAddresses),
            record.fullName,
        ))

    if table.rows:
        return succeed(table.toString())
    else:
        return succeed(None)
예제 #3
0
def tableString(rows, header=None):
    table = Table()
    if header:
        table.addHeader(header)
    for row in rows:
        table.addRow(row)

    output = StringIO()
    table.printTable(os=output)
    return output.getvalue()
예제 #4
0
파일: vfs.py 프로젝트: nunb/calendarserver
def tableString(rows, header=None):
    table = Table()
    if header:
        table.addHeader(header)
    for row in rows:
        table.addRow(row)

    output = StringIO()
    table.printTable(os=output)
    return output.getvalue()
예제 #5
0
def recordProxyAccessInfo(directory, record):
    """
    Group membership info for a record.
    """

    # FIXME: This proxy finding logic should be in DirectoryRecord.

    def meAndMyGroups(record=record, groups=set((record, ))):
        for group in record.groups():
            groups.add(group)
            meAndMyGroups(group, groups)
        return groups

    # FIXME: This module global is really gross.
    from twistedcaldav.directory.calendaruserproxy import ProxyDBService

    rows = []
    proxyInfoSeen = set()
    for record in meAndMyGroups():
        proxyUIDs = (yield ProxyDBService.getMemberships(record.uid))

        for proxyUID in proxyUIDs:
            # These are of the form: F153A05B-FF27-4B6C-BD6D-D1239D0082B0#calendar-proxy-read
            # I don't know how to get DirectoryRecord objects for the proxyUID here, so, let's cheat for now.
            proxyUID, proxyType = proxyUID.split("#")
            if (proxyUID, proxyType) not in proxyInfoSeen:
                proxyRecord = yield directory.recordWithUID(proxyUID)
                rows.append((proxyUID, proxyRecord.recordType,
                             proxyRecord.shortNames[0], proxyRecord.fullName,
                             proxyType))
                proxyInfoSeen.add((proxyUID, proxyType))

    if not rows:
        returnValue(None)

    rows = sorted(rows, key=lambda row: (row[1], row[2], row[4]))

    table = Table()
    table.addHeader(
        ("UID", "Record Type", "Short Name", "Full Name", "Access"))
    for row in rows:
        table.addRow(row)

    returnValue(table.toString())
예제 #6
0
def recordProxyAccessInfo(directory, record):
    """
    Group membership info for a record.
    """
    # FIXME: This proxy finding logic should be in DirectoryRecord.

    def meAndMyGroups(record=record, groups=set((record,))):
        for group in record.groups():
            groups.add(group)
            meAndMyGroups(group, groups)
        return groups

    # FIXME: This module global is really gross.
    from twistedcaldav.directory.calendaruserproxy import ProxyDBService

    rows = []
    proxyInfoSeen = set()
    for record in meAndMyGroups():
        proxyUIDs = (yield ProxyDBService.getMemberships(record.uid))

        for proxyUID in proxyUIDs:
            # These are of the form: F153A05B-FF27-4B6C-BD6D-D1239D0082B0#calendar-proxy-read
            # I don't know how to get DirectoryRecord objects for the proxyUID here, so, let's cheat for now.
            proxyUID, proxyType = proxyUID.split("#")
            if (proxyUID, proxyType) not in proxyInfoSeen:
                proxyRecord = yield directory.recordWithUID(proxyUID)
                rows.append((proxyUID, proxyRecord.recordType, proxyRecord.shortNames[0], proxyRecord.fullName, proxyType))
                proxyInfoSeen.add((proxyUID, proxyType))

    if not rows:
        returnValue(None)

    rows = sorted(
        rows,
        key=lambda row: (row[1], row[2], row[4])
    )

    table = Table()
    table.addHeader(("UID", "Record Type", "Short Name", "Full Name", "Access"))
    for row in rows:
        table.addRow(row)

    returnValue(table.toString())
예제 #7
0
def recordGroupMembershipInfo(directory, record):
    """
    Group membership info for a record.
    """
    rows = []

    for group in record.groups():
        rows.append((group.uid, group.shortNames[0], group.fullName))

    if not rows:
        return succeed(None)

    rows = sorted(rows, key=lambda row: (row[1], row[2]))

    table = Table()
    table.addHeader(("UID", "Short Name", "Full Name"))
    for row in rows:
        table.addRow(row)

    return succeed(table.toString())
예제 #8
0
def recordGroupMembershipInfo(directory, record):
    """
    Group membership info for a record.
    """
    rows = []

    for group in record.groups():
        rows.append((group.uid, group.shortNames[0], group.fullName))

    if not rows:
        return succeed(None)

    rows = sorted(rows,
        key = lambda row: (row[1], row[2])
    )

    table = Table()
    table.addHeader(("UID", "Short Name", "Full Name"))
    for row in rows:
        table.addRow(row)

    return succeed(table.toString())