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