# HG changeset patch # User Paul Boddie # Date 1463092126 -7200 # Node ID 3252084e96084160922e83b70a2bd8af7723c5cd # Parent d674245140c305c5f8f62e8b97b84a22e56f3a29 Renamed the quota tool and updated the documentation to illustrate the way it currently works. diff -r d674245140c3 -r 3252084e9608 docs/wiki/Resources --- a/docs/wiki/Resources Fri May 13 00:22:56 2016 +0200 +++ b/docs/wiki/Resources Fri May 13 00:28:46 2016 +0200 @@ -383,19 +383,34 @@ but a tool is also provided to set such limits. For example: {{{ -set_quota_limit.py 'mailto:resource-car-cadillac@example.com' \ - 'mailto:vincent.vole@example.com' PT10H +cat < - -This program is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free Software -Foundation; either version 3 of the License, or (at your option) any later -version. - -This program is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -FOR A PARTICULAR PURPOSE. See the GNU General Public License for more -details. - -You should have received a copy of the GNU General Public License along with -this program. If not, see . -""" - -from codecs import getreader -from os.path import abspath, split -import sys - -# Find the modules. - -try: - import imiptools -except ImportError: - parent = abspath(split(split(__file__)[0])[0]) - if split(parent)[1] == "imip-agent": - sys.path.append(parent) - -from imiptools import config -from imiptools.stores import get_journal -from imiptools.text import get_table_from_stream - -# Main program. - -if __name__ == "__main__": - - # Interpret the command line arguments. - - args = [] - store_type = [] - journal_dir = [] - - # Collect quota details first, switching to other arguments when encountering - # switches. - - l = args - - for arg in sys.argv[1:]: - if arg == "-T": - l = store_type - elif arg == "-j": - l = journal_dir - else: - l.append(arg) - - try: - quota, = args - except ValueError: - print >>sys.stderr, """\ -Usage: %s [ ] - -Read from standard input a list of group-to-limit mappings of the following -form: - - - -For example: - -* PT1H - -The values may be separated using any whitespace characters. - -General options: - --j Indicates the journal directory location --T Indicates the store type (the configured value if omitted) -""" % split(sys.argv[0])[1] - sys.exit(1) - - # Override defaults if indicated. - - getvalue = lambda value, default=None: value and value[0] or default - - store_type = getvalue(store_type, config.STORE_TYPE) - journal_dir = getvalue(journal_dir) - - # Obtain store-related objects. - - journal = get_journal(store_type, journal_dir) - f = getreader("utf-8")(sys.stdin) - limits = dict(get_table_from_stream(f, tab_separated=False)) - journal.set_limits(quota, limits) - -# vim: tabstop=4 expandtab shiftwidth=4 diff -r d674245140c3 -r 3252084e9608 tools/set_quota_limits.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/set_quota_limits.py Fri May 13 00:28:46 2016 +0200 @@ -0,0 +1,100 @@ +#!/usr/bin/env python + +""" +Set quota limits for a collection of user groups. + +Copyright (C) 2016 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +from codecs import getreader +from os.path import abspath, split +import sys + +# Find the modules. + +try: + import imiptools +except ImportError: + parent = abspath(split(split(__file__)[0])[0]) + if split(parent)[1] == "imip-agent": + sys.path.append(parent) + +from imiptools import config +from imiptools.stores import get_journal +from imiptools.text import get_table_from_stream + +# Main program. + +if __name__ == "__main__": + + # Interpret the command line arguments. + + args = [] + store_type = [] + journal_dir = [] + + # Collect quota details first, switching to other arguments when encountering + # switches. + + l = args + + for arg in sys.argv[1:]: + if arg == "-T": + l = store_type + elif arg == "-j": + l = journal_dir + else: + l.append(arg) + + try: + quota, = args + except ValueError: + print >>sys.stderr, """\ +Usage: %s [ ] + +Read from standard input a list of group-to-limit mappings of the following +form: + + + +For example: + +* PT1H + +The values may be separated using any whitespace characters. + +General options: + +-j Indicates the journal directory location +-T Indicates the store type (the configured value if omitted) +""" % split(sys.argv[0])[1] + sys.exit(1) + + # Override defaults if indicated. + + getvalue = lambda value, default=None: value and value[0] or default + + store_type = getvalue(store_type, config.STORE_TYPE) + journal_dir = getvalue(journal_dir) + + # Obtain store-related objects. + + journal = get_journal(store_type, journal_dir) + f = getreader("utf-8")(sys.stdin) + limits = dict(get_table_from_stream(f, tab_separated=False)) + journal.set_limits(quota, limits) + +# vim: tabstop=4 expandtab shiftwidth=4