paul@1088 | 1 | #!/usr/bin/env python |
paul@1088 | 2 | |
paul@1088 | 3 | """ |
paul@1088 | 4 | Show the contents of a table. |
paul@1088 | 5 | |
paul@1232 | 6 | Copyright (C) 2016, 2017 Paul Boddie <paul@boddie.org.uk> |
paul@1088 | 7 | |
paul@1088 | 8 | This program is free software; you can redistribute it and/or modify it under |
paul@1088 | 9 | the terms of the GNU General Public License as published by the Free Software |
paul@1088 | 10 | Foundation; either version 3 of the License, or (at your option) any later |
paul@1088 | 11 | version. |
paul@1088 | 12 | |
paul@1088 | 13 | This program is distributed in the hope that it will be useful, but WITHOUT |
paul@1088 | 14 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
paul@1088 | 15 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
paul@1088 | 16 | details. |
paul@1088 | 17 | |
paul@1088 | 18 | You should have received a copy of the GNU General Public License along with |
paul@1088 | 19 | this program. If not, see <http://www.gnu.org/licenses/>. |
paul@1088 | 20 | """ |
paul@1088 | 21 | |
paul@1088 | 22 | from imiptools.data import Object |
paul@1088 | 23 | from imiptools.stores import get_store, get_journal |
paul@1088 | 24 | import sys |
paul@1088 | 25 | |
paul@1088 | 26 | def show_list(data): |
paul@1196 | 27 | if data: |
paul@1196 | 28 | for row in data: |
paul@1196 | 29 | print row or "" |
paul@1088 | 30 | |
paul@1232 | 31 | def show_object(obj): |
paul@1232 | 32 | if obj: |
paul@1232 | 33 | print obj.to_string(line_length=1000) |
paul@1088 | 34 | |
paul@1088 | 35 | def show_periods(data): |
paul@1196 | 36 | if data: |
paul@1196 | 37 | for row in data: |
paul@1196 | 38 | print "\t".join(row.as_tuple(strings_only=True)) |
paul@1088 | 39 | |
paul@1088 | 40 | def show_tuples(data): |
paul@1196 | 41 | if data: |
paul@1196 | 42 | for row in data: |
paul@1196 | 43 | print "\t".join([(column or "") for column in row]) |
paul@1088 | 44 | |
paul@1088 | 45 | if __name__ == "__main__": |
paul@1088 | 46 | try: |
paul@1088 | 47 | store_type, store_dir, journal_dir, user, table = sys.argv[1:6] |
paul@1088 | 48 | args = sys.argv[6:] |
paul@1088 | 49 | except ValueError: |
paul@1088 | 50 | print >>sys.stderr, """\ |
paul@1088 | 51 | Need a store type, a store directory, a journal directory, a user URI, and a |
paul@1088 | 52 | table to show. Other arguments may be needed for certain tables. |
paul@1088 | 53 | """ |
paul@1088 | 54 | sys.exit(1) |
paul@1088 | 55 | |
paul@1088 | 56 | store = get_store(store_type, store_dir) |
paul@1088 | 57 | journal = get_journal(store_type, journal_dir) |
paul@1088 | 58 | |
paul@1088 | 59 | # Periods. |
paul@1088 | 60 | |
paul@1088 | 61 | if table == "entries": |
paul@1089 | 62 | group = args[0] |
paul@1089 | 63 | data = journal.get_entries(user, group) |
paul@1088 | 64 | show_periods(data) |
paul@1088 | 65 | |
paul@1088 | 66 | elif table == "freebusy": |
paul@1088 | 67 | data = store.get_freebusy(user) |
paul@1088 | 68 | show_periods(data) |
paul@1088 | 69 | |
paul@1088 | 70 | elif table == "freebusy_offers": |
paul@1088 | 71 | data = store.get_freebusy_offers(user) |
paul@1088 | 72 | show_periods(data) |
paul@1088 | 73 | |
paul@1088 | 74 | elif table == "freebusy_other": |
paul@1088 | 75 | other = args[0] |
paul@1088 | 76 | data = store.get_freebusy_for_other(user, other) |
paul@1088 | 77 | show_periods(data) |
paul@1088 | 78 | |
paul@1088 | 79 | # Tuples. |
paul@1088 | 80 | |
paul@1088 | 81 | elif table == "requests": |
paul@1088 | 82 | data = store.get_requests(user) |
paul@1088 | 83 | show_tuples(data) |
paul@1088 | 84 | |
paul@1089 | 85 | elif table == "freebusy_providers": |
paul@1089 | 86 | data = store.get_freebusy_providers(user) |
paul@1089 | 87 | show_tuples(data) |
paul@1089 | 88 | |
paul@1196 | 89 | elif table == "journal_freebusy_providers": |
paul@1196 | 90 | data = journal.get_freebusy_providers(user) |
paul@1196 | 91 | show_tuples(data) |
paul@1196 | 92 | |
paul@1088 | 93 | # Objects. |
paul@1088 | 94 | |
paul@1088 | 95 | elif table == "countered_object": |
paul@1088 | 96 | uid = args[0] |
paul@1088 | 97 | other = args[1] |
paul@1232 | 98 | obj = store.get_counter(user, other, uid) |
paul@1232 | 99 | show_object(obj) |
paul@1088 | 100 | |
paul@1088 | 101 | elif table == "object": |
paul@1088 | 102 | uid = args[0] |
paul@1232 | 103 | obj = store.get_event(user, uid) |
paul@1232 | 104 | show_object(obj) |
paul@1088 | 105 | |
paul@1196 | 106 | elif table == "journal_object": |
paul@1196 | 107 | uid = args[0] |
paul@1232 | 108 | obj = journal.get_event(user, uid) |
paul@1232 | 109 | show_object(obj) |
paul@1196 | 110 | |
paul@1088 | 111 | elif table == "recurrence": |
paul@1088 | 112 | uid = args[0] |
paul@1088 | 113 | recurrenceid = args[1] |
paul@1232 | 114 | obj = store.get_event(user, uid, recurrenceid) |
paul@1232 | 115 | show_object(obj) |
paul@1088 | 116 | |
paul@1088 | 117 | elif table == "cancelled_recurrences": |
paul@1088 | 118 | uid = args[0] |
paul@1088 | 119 | data = store.get_cancelled_recurrences(user, uid) |
paul@1088 | 120 | show_list(data) |
paul@1088 | 121 | |
paul@1088 | 122 | # vim: tabstop=4 expandtab shiftwidth=4 |