@add_argument('<STR_LIT>',<EOL>metavar='<STR_LIT>',<EOL>help="<STR_LIT>"<EOL>"<STR_LIT>")<EOL>@add_argument('<STR_LIT>',<EOL>help="<STR_LIT>"<EOL>"<STR_LIT>")<EOL>@add_argument('<STR_LIT>', '<STR_LIT>',<EOL>dest='<STR_LIT>',<EOL>action='<STR_LIT:store_true>',<EOL>default=False,<EOL>help="<STR_LIT>")<EOL>@add_argument('<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>',<EOL>dest='<STR_LIT>',<EOL>action='<STR_LIT:store_true>',<EOL>default=False,<EOL>help="<STR_LIT>"<EOL>"<STR_LIT>")<EOL>@add_argument('<STR_LIT>', '<STR_LIT>',<EOL>dest='<STR_LIT>',<EOL>action='<STR_LIT>',<EOL>default=True,<EOL>help="<STR_LIT>")<EOL>@add_argument('<STR_LIT>', '<STR_LIT>',<EOL>dest='<STR_LIT>',<EOL>action='<STR_LIT>',<EOL>const='<STR_LIT>',<EOL>help="<STR_LIT>"<EOL>"<STR_LIT>")<EOL>@add_argument('<STR_LIT>', '<STR_LIT>',<EOL>dest='<STR_LIT>',<EOL>metavar='<STR_LIT>',<EOL>type=float,<EOL>action='<STR_LIT:store>',<EOL>help="<STR_LIT>"<EOL>"<STR_LIT>")<EOL>def setup_limits(conf_file, limits_file, do_reload=True,<EOL>dry_run=False, debug=False):
<EOL>if dry_run:<EOL><INDENT>debug = True<EOL><DEDENT>conf = config.Config(conf_file=conf_file)<EOL>db = conf.get_database()<EOL>limits_key = conf['<STR_LIT>'].get('<STR_LIT>', '<STR_LIT>')<EOL>control_channel = conf['<STR_LIT>'].get('<STR_LIT>', '<STR_LIT>')<EOL>limits_tree = etree.parse(limits_file)<EOL>lims = []<EOL>for idx, lim in enumerate(limits_tree.getroot()):<EOL><INDENT>if lim.tag != '<STR_LIT>':<EOL><INDENT>warnings.warn("<STR_LIT>" %<EOL>(lim.tag, idx))<EOL>continue<EOL><DEDENT>try:<EOL><INDENT>lims.append(parse_limit_node(db, idx, lim))<EOL><DEDENT>except Exception as exc:<EOL><INDENT>warnings.warn("<STR_LIT>" %<EOL>(idx, exc))<EOL>continue<EOL><DEDENT><DEDENT>if debug:<EOL><INDENT>print("<STR_LIT>", file=sys.stderr)<EOL>for lim in lims:<EOL><INDENT>print("<STR_LIT>" % lim, file=sys.stderr)<EOL><DEDENT><DEDENT>if not dry_run:<EOL><INDENT>database.limit_update(db, limits_key, lims)<EOL><DEDENT>if do_reload is False:<EOL><INDENT>return<EOL><DEDENT>params = []<EOL>if do_reload is True:<EOL><INDENT>pass<EOL><DEDENT>elif (isinstance(do_reload, (int, float)) or<EOL>(isinstance(do_reload, str) and do_reload.isdigit())):<EOL><INDENT>params = ['<STR_LIT>', do_reload]<EOL><DEDENT>else:<EOL><INDENT>params = [str(do_reload)]<EOL><DEDENT>if debug:<EOL><INDENT>cmd = ['<STR_LIT>']<EOL>cmd.extend(params)<EOL>print(("<STR_LIT>" %<EOL>'<STR_LIT:U+0020>'.join(str(c) for c in cmd)), file=sys.stderr)<EOL><DEDENT>if not dry_run:<EOL><INDENT>database.command(db, control_channel, '<STR_LIT>', *params)<EOL><DEDENT>
Set up or update limits in the Redis database.

:param conf_file: Name of the configuration file, for connecting
                  to the Redis database.
:param limits_file: Name of the XML file describing the limits to
                    configure.
:param do_reload: Controls reloading behavior.  If True (the
                  default), a reload command is issued.  If False,
                  no reload command is issued.  String values
                  result in a reload command of the given load
                  type, and integer or float values result in a
                  reload command of type 'spread' with the given
                  spread interval.
:param dry_run: If True, no changes are made to the database.
                Implies debug=True.
:param debug: If True, debugging messages are emitted while
              loading the limits and updating the database.