paul@1089 | 1 | #!/usr/bin/env python |
paul@1089 | 2 | |
paul@1089 | 3 | """ |
paul@1089 | 4 | Set a quota limit for a user group. |
paul@1089 | 5 | |
paul@1089 | 6 | Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk> |
paul@1089 | 7 | |
paul@1089 | 8 | This program is free software; you can redistribute it and/or modify it under |
paul@1089 | 9 | the terms of the GNU General Public License as published by the Free Software |
paul@1089 | 10 | Foundation; either version 3 of the License, or (at your option) any later |
paul@1089 | 11 | version. |
paul@1089 | 12 | |
paul@1089 | 13 | This program is distributed in the hope that it will be useful, but WITHOUT |
paul@1089 | 14 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
paul@1089 | 15 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
paul@1089 | 16 | details. |
paul@1089 | 17 | |
paul@1089 | 18 | You should have received a copy of the GNU General Public License along with |
paul@1089 | 19 | this program. If not, see <http://www.gnu.org/licenses/>. |
paul@1089 | 20 | """ |
paul@1089 | 21 | |
paul@1140 | 22 | from os.path import abspath, split |
paul@1089 | 23 | import sys |
paul@1089 | 24 | |
paul@1089 | 25 | # Find the modules. |
paul@1089 | 26 | |
paul@1089 | 27 | try: |
paul@1089 | 28 | import imiptools |
paul@1089 | 29 | except ImportError: |
paul@1140 | 30 | parent = abspath(split(split(__file__)[0])[0]) |
paul@1089 | 31 | if split(parent)[1] == "imip-agent": |
paul@1089 | 32 | sys.path.append(parent) |
paul@1089 | 33 | |
paul@1089 | 34 | from imiptools import config |
paul@1089 | 35 | from imiptools.stores import get_journal |
paul@1089 | 36 | |
paul@1089 | 37 | # Main program. |
paul@1089 | 38 | |
paul@1089 | 39 | if __name__ == "__main__": |
paul@1089 | 40 | |
paul@1089 | 41 | # Interpret the command line arguments. |
paul@1089 | 42 | |
paul@1089 | 43 | args = [] |
paul@1089 | 44 | store_type = [] |
paul@1089 | 45 | journal_dir = [] |
paul@1089 | 46 | |
paul@1089 | 47 | # Collect quota details first, switching to other arguments when encountering |
paul@1089 | 48 | # switches. |
paul@1089 | 49 | |
paul@1089 | 50 | l = args |
paul@1089 | 51 | |
paul@1089 | 52 | for arg in sys.argv[1:]: |
paul@1089 | 53 | if arg == "-T": |
paul@1089 | 54 | l = store_type |
paul@1089 | 55 | elif arg == "-j": |
paul@1089 | 56 | l = journal_dir |
paul@1089 | 57 | else: |
paul@1089 | 58 | l.append(arg) |
paul@1089 | 59 | |
paul@1089 | 60 | try: |
paul@1089 | 61 | quota, group, limit = args |
paul@1089 | 62 | except ValueError: |
paul@1089 | 63 | print >>sys.stderr, """\ |
paul@1089 | 64 | Usage: %s <quota> <group> <limit> [ <options> ] |
paul@1089 | 65 | |
paul@1089 | 66 | General options: |
paul@1089 | 67 | |
paul@1089 | 68 | -j Indicates the journal directory location |
paul@1089 | 69 | -T Indicates the store type (the configured value if omitted) |
paul@1089 | 70 | """ % split(sys.argv[0])[1] |
paul@1089 | 71 | sys.exit(1) |
paul@1089 | 72 | |
paul@1089 | 73 | # Override defaults if indicated. |
paul@1089 | 74 | |
paul@1089 | 75 | getvalue = lambda value, default=None: value and value[0] or default |
paul@1089 | 76 | |
paul@1089 | 77 | store_type = getvalue(store_type, config.STORE_TYPE) |
paul@1089 | 78 | journal_dir = getvalue(journal_dir) |
paul@1089 | 79 | |
paul@1089 | 80 | # Obtain store-related objects. |
paul@1089 | 81 | |
paul@1089 | 82 | journal = get_journal(store_type, journal_dir) |
paul@1089 | 83 | journal.set_limit(quota, group, limit) |
paul@1089 | 84 | |
paul@1089 | 85 | # vim: tabstop=4 expandtab shiftwidth=4 |