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@1088 | 6 | Copyright (C) 2016 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@1088 | 27 | for row in data: |
paul@1088 | 28 | print row or "" |
paul@1088 | 29 | |
paul@1088 | 30 | def show_object(data): |
paul@1088 | 31 | if data: |
paul@1088 | 32 | print Object(data).to_string() |
paul@1088 | 33 | |
paul@1088 | 34 | def show_periods(data): |
paul@1088 | 35 | for row in data: |
paul@1088 | 36 | print "\t".join(row.as_tuple(strings_only=True)) |
paul@1088 | 37 | |
paul@1088 | 38 | def show_tuples(data): |
paul@1088 | 39 | for row in data: |
paul@1088 | 40 | print "\t".join([(column or "") for column in row]) |
paul@1088 | 41 | |
paul@1088 | 42 | if __name__ == "__main__": |
paul@1088 | 43 | try: |
paul@1088 | 44 | store_type, store_dir, journal_dir, user, table = sys.argv[1:6] |
paul@1088 | 45 | args = sys.argv[6:] |
paul@1088 | 46 | except ValueError: |
paul@1088 | 47 | print >>sys.stderr, """\ |
paul@1088 | 48 | Need a store type, a store directory, a journal directory, a user URI, and a |
paul@1088 | 49 | table to show. Other arguments may be needed for certain tables. |
paul@1088 | 50 | """ |
paul@1088 | 51 | sys.exit(1) |
paul@1088 | 52 | |
paul@1088 | 53 | store = get_store(store_type, store_dir) |
paul@1088 | 54 | journal = get_journal(store_type, journal_dir) |
paul@1088 | 55 | |
paul@1088 | 56 | # Periods. |
paul@1088 | 57 | |
paul@1088 | 58 | if table == "entries": |
paul@1089 | 59 | group = args[0] |
paul@1089 | 60 | data = journal.get_entries(user, group) |
paul@1088 | 61 | show_periods(data) |
paul@1088 | 62 | |
paul@1088 | 63 | elif table == "freebusy": |
paul@1088 | 64 | data = store.get_freebusy(user) |
paul@1088 | 65 | show_periods(data) |
paul@1088 | 66 | |
paul@1088 | 67 | elif table == "freebusy_offers": |
paul@1088 | 68 | data = store.get_freebusy_offers(user) |
paul@1088 | 69 | show_periods(data) |
paul@1088 | 70 | |
paul@1088 | 71 | elif table == "freebusy_other": |
paul@1088 | 72 | other = args[0] |
paul@1088 | 73 | data = store.get_freebusy_for_other(user, other) |
paul@1088 | 74 | show_periods(data) |
paul@1088 | 75 | |
paul@1088 | 76 | # Tuples. |
paul@1088 | 77 | |
paul@1088 | 78 | elif table == "requests": |
paul@1088 | 79 | data = store.get_requests(user) |
paul@1088 | 80 | show_tuples(data) |
paul@1088 | 81 | |
paul@1089 | 82 | elif table == "freebusy_providers": |
paul@1089 | 83 | data = store.get_freebusy_providers(user) |
paul@1089 | 84 | show_tuples(data) |
paul@1089 | 85 | |
paul@1088 | 86 | # Objects. |
paul@1088 | 87 | |
paul@1088 | 88 | elif table == "countered_object": |
paul@1088 | 89 | uid = args[0] |
paul@1088 | 90 | other = args[1] |
paul@1088 | 91 | data = store.get_counter(user, other, uid) |
paul@1088 | 92 | show_object(data) |
paul@1088 | 93 | |
paul@1088 | 94 | elif table == "object": |
paul@1088 | 95 | uid = args[0] |
paul@1088 | 96 | data = store.get_event(user, uid) |
paul@1088 | 97 | show_object(data) |
paul@1088 | 98 | |
paul@1088 | 99 | elif table == "recurrence": |
paul@1088 | 100 | uid = args[0] |
paul@1088 | 101 | recurrenceid = args[1] |
paul@1088 | 102 | data = store.get_event(user, uid, recurrenceid) |
paul@1088 | 103 | show_object(data) |
paul@1088 | 104 | |
paul@1088 | 105 | elif table == "cancelled_recurrences": |
paul@1088 | 106 | uid = args[0] |
paul@1088 | 107 | data = store.get_cancelled_recurrences(user, uid) |
paul@1088 | 108 | show_list(data) |
paul@1088 | 109 | |
paul@1088 | 110 | # vim: tabstop=4 expandtab shiftwidth=4 |