예제 #1
0
    def doIt(self, txn):

        rid = raw_input("Resource-ID: ")
        try:
            int(rid)
        except ValueError:
            print('Resource ID must be an integer')
            returnValue(None)
        uids = yield self.getEvents(txn, rid)

        # Print table of results
        table = tables.Table()
        table.addHeader((
            "Type",
            "UID",
            "Resource Name",
            "Resource ID",
        ))
        for caltype, caluid, rname, rid in sorted(uids, key=lambda x: x[1]):
            table.addRow((
                caltype,
                caluid,
                rname,
                rid,
            ))

        print("\n")
        print("Calendar events (total=%d):\n" % (len(uids), ))
        table.printTable()
예제 #2
0
    def eventsInTimeRange(self, calendar, uid, timerange):

        # Create fake filter element to match time-range
        filter = caldavxml.Filter(
            caldavxml.ComponentFilter(
                caldavxml.ComponentFilter(
                    timerange,
                    name=("VEVENT", ),
                ),
                name="VCALENDAR",
            ))
        filter = Filter(filter)
        filter.settimezone(None)

        matches = yield calendar.search(filter, useruid=uid, fbtype=False)
        if matches is None:
            returnValue(None)
        for name, _ignore_uid, _ignore_type in matches:
            event = yield calendar.calendarObjectWithName(name)
            ical_data = yield event.componentForUser()
            ical_data.stripStandardTimezones()

            table = tables.Table()
            table.addRow((
                "Calendar:",
                calendar.name(),
            ))
            table.addRow(("Resource Name:", name))
            table.addRow(("Resource ID:", event._resourceID))
            table.addRow(("Created", event.created()))
            table.addRow(("Modified", event.modified()))
            print("\n")
            table.printTable()
            print(ical_data.getTextWithoutTimezones())
예제 #3
0
    def doIt(self, txn):

        uid = raw_input("Owner UID/Name: ")
        uid = yield UIDFromInput(txn, uid)
        uids = yield self.getCalendars(txn, uid)

        # Print table of results
        table = tables.Table()
        table.addHeader(
            ("Owner UID", "Short Name", "Calendars", "ID", "Resources"))
        totals = [
            0,
            0,
        ]
        for uid, calname, resid, count in sorted(uids, key=lambda x: x[1]):
            shortname = yield UserNameFromUID(txn, uid)
            table.addRow((
                uid if totals[0] == 0 else "",
                shortname if totals[0] == 0 else "",
                calname,
                resid,
                count,
            ))
            totals[0] += 1
            totals[1] += count
        table.addFooter(("Total", "", totals[0], "", totals[1]))

        print("\n")
        print("Calendars with resource count (total=%d):\n" % (len(uids), ))
        table.printTable()
예제 #4
0
 def printEventDetails(self, txn, details):
     owner, calendar, resource_id, resource, created, modified, data = details
     shortname = UserNameFromUID(txn, owner)
     table = tables.Table()
     table.addRow(("Owner UID:", owner,))
     table.addRow(("User Name:", shortname,))
     table.addRow(("Calendar:", calendar,))
     table.addRow(("Resource Name:", resource))
     table.addRow(("Resource ID:", resource_id))
     table.addRow(("Created", created))
     table.addRow(("Modified", modified))
     print("\n")
     table.printTable()
     print(data)
예제 #5
0
    def doIt(self, txn):

        uids = yield self.getCalendars(txn)

        # Print table of results
        table = tables.Table()
        table.addHeader(("Owner UID", "Short Name", "Calendar", "Resources"))
        for uid, calname, count in sorted(uids, key=lambda x: (x[0], x[1])):
            shortname = yield UserNameFromUID(txn, uid)
            table.addRow((uid, shortname, calname, count))

        print("\n")
        print("Calendars with resource count (total=%d):\n" % (len(uids), ))
        table.printTable()
예제 #6
0
    def _printReport(self, title, attr, colFormat):
        table = tables.Table()

        print(title)
        headers = ["Sharees"] + self.requestLabels
        table.addHeader(headers)
        formats = [tables.Table.ColumnFormat("%d", tables.Table.ColumnFormat.RIGHT_JUSTIFY)] + \
            [tables.Table.ColumnFormat(colFormat, tables.Table.ColumnFormat.RIGHT_JUSTIFY)] * len(self.requestLabels)
        table.setDefaultColumnFormats(formats)
        for k in sorted(self.results.keys()):
            row = [k] + [getattr(self.results[k][item], attr) for item in self.requestLabels]
            table.addRow(row)
        os = StringIO()
        table.printTable(os=os)
        print(os.getvalue())
        print("")
예제 #7
0
    def doIt(self, txn):

        uids = yield self.getEvents(txn)

        # Print table of results
        table = tables.Table()
        table.addHeader(
            ("Owner UID", "Short Name", "Calendar", "ID", "Type", "UID"))
        for uid, calname, id, caltype, caluid in sorted(uids,
                                                        key=lambda x:
                                                        (x[0], x[1])):
            shortname = yield UserNameFromUID(txn, uid)
            table.addRow((uid, shortname, calname, id, caltype, caluid))

        print("\n")
        print("Calendar events (total=%d):\n" % (len(uids), ))
        table.printTable()
예제 #8
0
    def doIt(self, txn):

        uids = yield self.getCalendars(txn)

        results = {}
        for uid, calname, count in sorted(uids, key=lambda x: x[0]):
            totalname, totalcount = results.get(uid, (
                0,
                0,
            ))
            if calname != "inbox":
                totalname += 1
                totalcount += count
                results[uid] = (
                    totalname,
                    totalcount,
                )

        # Print table of results
        table = tables.Table()
        table.addHeader(("Owner UID", "Short Name", "Calendars", "Resources"))
        totals = [0, 0, 0]
        for uid in sorted(results.keys()):
            shortname = yield UserNameFromUID(txn, uid)
            table.addRow((
                uid,
                shortname,
                results[uid][0],
                results[uid][1],
            ))
            totals[0] += 1
            totals[1] += results[uid][0]
            totals[2] += results[uid][1]
        table.addFooter(("Total", totals[0], totals[1], totals[2]))
        table.addFooter((
            "Average",
            "",
            "%.2f" % ((1.0 * totals[1]) / totals[0] if totals[0] else 0, ),
            "%.2f" % ((1.0 * totals[2]) / totals[0] if totals[0] else 0, ),
        ))

        print("\n")
        print("Calendars with resource count (total=%d):\n" % (len(results), ))
        table.printTable()
예제 #9
0
    def doIt(self, txn):

        uids = yield self.getAllHomeUIDs(txn)

        # Print table of results
        missing = 0
        table = tables.Table()
        table.addHeader(("Owner UID", "Short Name"))
        for uid in sorted(uids):
            shortname = UserNameFromUID(txn, uid)
            if shortname.startswith("("):
                missing += 1
            table.addRow((
                uid,
                shortname,
            ))

        print("\n")
        print("Calendar Homes (total=%d, missing=%d):\n" % (len(uids), missing,))
        table.printTable()
예제 #10
0
    def doIt(self, txn):

        results = []
        for dbtable in schema.model.tables: #@UndefinedVariable
            dbtable = getattr(schema, dbtable.name)
            count = yield self.getTableSize(txn, dbtable)
            results.append((dbtable.model.name, count,))

        # Print table of results
        table = tables.Table()
        table.addHeader(("Table", "Row Count"))
        for dbtable, count in sorted(results):
            table.addRow((
                dbtable,
                count,
            ))

        print("\n")
        print("Database Tables (total=%d):\n" % (len(results),))
        table.printTable()
예제 #11
0
    def _dryRunSummary(self, orphans, dropbox, managed):

        if self.verbose:
            byuser = {}
            ByUserData = collections.namedtuple(
                'ByUserData',
                ['quota', 'orphanSize', 'orphanCount', 'dropboxSize', 'dropboxCount', 'managedSize', 'managedCount']
            )
            for user, quota, size, count in orphans:
                byuser[user] = ByUserData(quota=quota, orphanSize=size, orphanCount=count, dropboxSize=0, dropboxCount=0, managedSize=0, managedCount=0)
            for user, quota, size, count in dropbox:
                if user in byuser:
                    byuser[user] = byuser[user]._replace(dropboxSize=size, dropboxCount=count)
                else:
                    byuser[user] = ByUserData(quota=quota, orphanSize=0, orphanCount=0, dropboxSize=size, dropboxCount=count, managedSize=0, managedCount=0)
            for user, quota, size, count in managed:
                if user in byuser:
                    byuser[user] = byuser[user]._replace(managedSize=size, managedCount=count)
                else:
                    byuser[user] = ByUserData(quota=quota, orphanSize=0, orphanCount=0, dropboxSize=0, dropboxCount=0, managedSize=size, managedCount=count)

            # Print table of results
            table = tables.Table()
            table.addHeader(("User", "Current Quota", "Orphan Size", "Orphan Count", "Dropbox Size", "Dropbox Count", "Managed Size", "Managed Count", "Total Size", "Total Count"))
            table.setDefaultColumnFormats((
                tables.Table.ColumnFormat("%s", tables.Table.ColumnFormat.LEFT_JUSTIFY),
                tables.Table.ColumnFormat("%d", tables.Table.ColumnFormat.RIGHT_JUSTIFY),
                tables.Table.ColumnFormat("%d", tables.Table.ColumnFormat.RIGHT_JUSTIFY),
                tables.Table.ColumnFormat("%d", tables.Table.ColumnFormat.RIGHT_JUSTIFY),
                tables.Table.ColumnFormat("%d", tables.Table.ColumnFormat.RIGHT_JUSTIFY),
                tables.Table.ColumnFormat("%d", tables.Table.ColumnFormat.RIGHT_JUSTIFY),
                tables.Table.ColumnFormat("%d", tables.Table.ColumnFormat.RIGHT_JUSTIFY),
                tables.Table.ColumnFormat("%d", tables.Table.ColumnFormat.RIGHT_JUSTIFY),
                tables.Table.ColumnFormat("%d", tables.Table.ColumnFormat.RIGHT_JUSTIFY),
                tables.Table.ColumnFormat("%d", tables.Table.ColumnFormat.RIGHT_JUSTIFY),
            ))

            totals = [0] * 8
            for user, data in sorted(byuser.items(), key=lambda x: x[0]):
                cols = (
                    data.orphanSize,
                    data.orphanCount,
                    data.dropboxSize,
                    data.dropboxCount,
                    data.managedSize,
                    data.managedCount,
                    data.orphanSize + data.dropboxSize + data.managedSize,
                    data.orphanCount + data.dropboxCount + data.managedCount,
                )
                table.addRow((user, data.quota,) + cols)
                for ctr, value in enumerate(cols):
                    totals[ctr] += value
            table.addFooter(("Total:", "",) + tuple(totals))
            total = totals[7]

            print("\n")
            print("Orphaned/Old Attachments by User:\n")
            table.printTable()
        else:
            total = sum([x[3] for x in orphans]) + sum([x[3] for x in dropbox]) + sum([x[3] for x in managed])

        return total