1.1 --- a/docs/wiki/Resources Fri May 13 00:22:56 2016 +0200
1.2 +++ b/docs/wiki/Resources Fri May 13 00:28:46 2016 +0200
1.3 @@ -383,19 +383,34 @@
1.4 but a tool is also provided to set such limits. For example:
1.5
1.6 {{{
1.7 -set_quota_limit.py 'mailto:resource-car-cadillac@example.com' \
1.8 - 'mailto:vincent.vole@example.com' PT10H
1.9 +cat <<EOF | set_quota_limits.py 'mailto:resource-car-cadillac@example.com'
1.10 +mailto:vincent.vole@example.com PT10H
1.11 +EOF
1.12 }}}
1.13
1.14 -This indicates that the given user may only reserve 10 hours of events or less
1.15 -within the given quota (corresponding to a specific resource in the above
1.16 -example). Attempts to schedule more time will be declined.
1.17 +{{{#!wiki tip
1.18 +In the above example, shell syntax is used to indicate a
1.19 +[[http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_07_04|here document]]
1.20 +providing a kind of "inline" file that is terminated by the final `EOF`.
1.21 +The contents of this file are piped to the tool with a single argument given
1.22 +indicating the quota involved.
1.23 +
1.24 +You could also just invoke the tool and then enter the limit descriptions,
1.25 +ending the input with Ctrl-D or equivalent end-of-file keystroke, or save
1.26 +the descriptions in a file and then use input redirection with the filename.
1.27 +}}}
1.28 +
1.29 +The above example indicates that the given user may only reserve 10 hours
1.30 +of events or less time within the given quota (corresponding to a specific
1.31 +resource in the above example). Attempts to schedule more time will be
1.32 +declined.
1.33
1.34 To impose a general quota, the special `*` identity can be used:
1.35
1.36 {{{
1.37 -set_quota_limit.py 'mailto:resource-car-cadillac@example.com' \
1.38 - '*' PT10H
1.39 +cat <<EOF | set_quota_limits.py 'mailto:resource-car-cadillac@example.com'
1.40 +* PT10H
1.41 +EOF
1.42 }}}
1.43
1.44 When a user identity is not listed and no general quota is defined, that
2.1 --- a/tests/common.sh Fri May 13 00:22:56 2016 +0200
2.2 +++ b/tests/common.sh Fri May 13 00:28:46 2016 +0200
2.3 @@ -24,7 +24,7 @@
2.4 SET_DELEGATES="$BASE_DIR/tools/set_delegates.py"
2.5 SET_DELEGATES_ARGS="-T $STORE_TYPE -j $JOURNAL"
2.6
2.7 -SET_QUOTA_LIMIT="$BASE_DIR/tools/set_quota_limit.py"
2.8 +SET_QUOTA_LIMIT="$BASE_DIR/tools/set_quota_limits.py"
2.9 SET_QUOTA_LIMIT_ARGS="-T $STORE_TYPE -j $JOURNAL"
2.10
2.11 TAB=`printf '\t'`
3.1 --- a/tools/install.sh Fri May 13 00:22:56 2016 +0200
3.2 +++ b/tools/install.sh Fri May 13 00:28:46 2016 +0200
3.3 @@ -103,7 +103,7 @@
3.4
3.5 # Tools
3.6
3.7 -TOOLS="copy_store.py fix.sh init.sh init_user.sh make_freebusy.py set_delegates.py set_quota_limit.py update_quotas.py update_scheduling_modules.py"
3.8 +TOOLS="copy_store.py fix.sh init.sh init_user.sh make_freebusy.py set_delegates.py set_quota_limits.py update_quotas.py update_scheduling_modules.py"
3.9
3.10 if [ ! -e "$INSTALL_DIR/tools" ]; then
3.11 mkdir -p "$INSTALL_DIR/tools"
4.1 --- a/tools/set_quota_limit.py Fri May 13 00:22:56 2016 +0200
4.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
4.3 @@ -1,100 +0,0 @@
4.4 -#!/usr/bin/env python
4.5 -
4.6 -"""
4.7 -Set quota limits for a collection of user groups.
4.8 -
4.9 -Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk>
4.10 -
4.11 -This program is free software; you can redistribute it and/or modify it under
4.12 -the terms of the GNU General Public License as published by the Free Software
4.13 -Foundation; either version 3 of the License, or (at your option) any later
4.14 -version.
4.15 -
4.16 -This program is distributed in the hope that it will be useful, but WITHOUT
4.17 -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
4.18 -FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
4.19 -details.
4.20 -
4.21 -You should have received a copy of the GNU General Public License along with
4.22 -this program. If not, see <http://www.gnu.org/licenses/>.
4.23 -"""
4.24 -
4.25 -from codecs import getreader
4.26 -from os.path import abspath, split
4.27 -import sys
4.28 -
4.29 -# Find the modules.
4.30 -
4.31 -try:
4.32 - import imiptools
4.33 -except ImportError:
4.34 - parent = abspath(split(split(__file__)[0])[0])
4.35 - if split(parent)[1] == "imip-agent":
4.36 - sys.path.append(parent)
4.37 -
4.38 -from imiptools import config
4.39 -from imiptools.stores import get_journal
4.40 -from imiptools.text import get_table_from_stream
4.41 -
4.42 -# Main program.
4.43 -
4.44 -if __name__ == "__main__":
4.45 -
4.46 - # Interpret the command line arguments.
4.47 -
4.48 - args = []
4.49 - store_type = []
4.50 - journal_dir = []
4.51 -
4.52 - # Collect quota details first, switching to other arguments when encountering
4.53 - # switches.
4.54 -
4.55 - l = args
4.56 -
4.57 - for arg in sys.argv[1:]:
4.58 - if arg == "-T":
4.59 - l = store_type
4.60 - elif arg == "-j":
4.61 - l = journal_dir
4.62 - else:
4.63 - l.append(arg)
4.64 -
4.65 - try:
4.66 - quota, = args
4.67 - except ValueError:
4.68 - print >>sys.stderr, """\
4.69 -Usage: %s <quota> [ <options> ]
4.70 -
4.71 -Read from standard input a list of group-to-limit mappings of the following
4.72 -form:
4.73 -
4.74 -<user or group> <limit>
4.75 -
4.76 -For example:
4.77 -
4.78 -* PT1H
4.79 -
4.80 -The values may be separated using any whitespace characters.
4.81 -
4.82 -General options:
4.83 -
4.84 --j Indicates the journal directory location
4.85 --T Indicates the store type (the configured value if omitted)
4.86 -""" % split(sys.argv[0])[1]
4.87 - sys.exit(1)
4.88 -
4.89 - # Override defaults if indicated.
4.90 -
4.91 - getvalue = lambda value, default=None: value and value[0] or default
4.92 -
4.93 - store_type = getvalue(store_type, config.STORE_TYPE)
4.94 - journal_dir = getvalue(journal_dir)
4.95 -
4.96 - # Obtain store-related objects.
4.97 -
4.98 - journal = get_journal(store_type, journal_dir)
4.99 - f = getreader("utf-8")(sys.stdin)
4.100 - limits = dict(get_table_from_stream(f, tab_separated=False))
4.101 - journal.set_limits(quota, limits)
4.102 -
4.103 -# vim: tabstop=4 expandtab shiftwidth=4
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/tools/set_quota_limits.py Fri May 13 00:28:46 2016 +0200
5.3 @@ -0,0 +1,100 @@
5.4 +#!/usr/bin/env python
5.5 +
5.6 +"""
5.7 +Set quota limits for a collection of user groups.
5.8 +
5.9 +Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk>
5.10 +
5.11 +This program is free software; you can redistribute it and/or modify it under
5.12 +the terms of the GNU General Public License as published by the Free Software
5.13 +Foundation; either version 3 of the License, or (at your option) any later
5.14 +version.
5.15 +
5.16 +This program is distributed in the hope that it will be useful, but WITHOUT
5.17 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
5.18 +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
5.19 +details.
5.20 +
5.21 +You should have received a copy of the GNU General Public License along with
5.22 +this program. If not, see <http://www.gnu.org/licenses/>.
5.23 +"""
5.24 +
5.25 +from codecs import getreader
5.26 +from os.path import abspath, split
5.27 +import sys
5.28 +
5.29 +# Find the modules.
5.30 +
5.31 +try:
5.32 + import imiptools
5.33 +except ImportError:
5.34 + parent = abspath(split(split(__file__)[0])[0])
5.35 + if split(parent)[1] == "imip-agent":
5.36 + sys.path.append(parent)
5.37 +
5.38 +from imiptools import config
5.39 +from imiptools.stores import get_journal
5.40 +from imiptools.text import get_table_from_stream
5.41 +
5.42 +# Main program.
5.43 +
5.44 +if __name__ == "__main__":
5.45 +
5.46 + # Interpret the command line arguments.
5.47 +
5.48 + args = []
5.49 + store_type = []
5.50 + journal_dir = []
5.51 +
5.52 + # Collect quota details first, switching to other arguments when encountering
5.53 + # switches.
5.54 +
5.55 + l = args
5.56 +
5.57 + for arg in sys.argv[1:]:
5.58 + if arg == "-T":
5.59 + l = store_type
5.60 + elif arg == "-j":
5.61 + l = journal_dir
5.62 + else:
5.63 + l.append(arg)
5.64 +
5.65 + try:
5.66 + quota, = args
5.67 + except ValueError:
5.68 + print >>sys.stderr, """\
5.69 +Usage: %s <quota> [ <options> ]
5.70 +
5.71 +Read from standard input a list of group-to-limit mappings of the following
5.72 +form:
5.73 +
5.74 +<user or group> <limit>
5.75 +
5.76 +For example:
5.77 +
5.78 +* PT1H
5.79 +
5.80 +The values may be separated using any whitespace characters.
5.81 +
5.82 +General options:
5.83 +
5.84 +-j Indicates the journal directory location
5.85 +-T Indicates the store type (the configured value if omitted)
5.86 +""" % split(sys.argv[0])[1]
5.87 + sys.exit(1)
5.88 +
5.89 + # Override defaults if indicated.
5.90 +
5.91 + getvalue = lambda value, default=None: value and value[0] or default
5.92 +
5.93 + store_type = getvalue(store_type, config.STORE_TYPE)
5.94 + journal_dir = getvalue(journal_dir)
5.95 +
5.96 + # Obtain store-related objects.
5.97 +
5.98 + journal = get_journal(store_type, journal_dir)
5.99 + f = getreader("utf-8")(sys.stdin)
5.100 + limits = dict(get_table_from_stream(f, tab_separated=False))
5.101 + journal.set_limits(quota, limits)
5.102 +
5.103 +# vim: tabstop=4 expandtab shiftwidth=4