| 28 | import sys |
| 29 | |
| 30 | from pykota import version |
| 31 | from pykota.tool import PyKotaTool, PyKotaToolError |
| 32 | |
| 33 | __doc__ = """edpykota v%s (C) 2003 C@LL - Conseil Internet & Logiciels Libres |
| 34 | A Print Quota editor for PyKota. |
| 35 | |
| 36 | command line usage : |
| 37 | |
| 38 | edpykota [-u] [-p username] [-f printername] username ... |
| 39 | edpykota -g [-p groupname] [-f printername] groupname ... |
| 40 | |
| 41 | options : |
| 42 | |
| 43 | -v | --version Prints edpykota's version number then exits. |
| 44 | -h | --help Prints this message then exits. |
| 45 | |
| 46 | -a | --add Adds users and/or printers if they don't |
| 47 | exist on the Quota Storage Server. |
| 48 | |
| 49 | -u | --users Edit users print quotas, this is the default. |
| 50 | |
| 51 | -P | --printer p Edit quotas on printer p only. |
| 52 | |
| 53 | -g | --groups Edit groups print quotas instead of users. |
| 54 | |
| 55 | -p | --prototype u|g Uses user u or group g as a prototype to set |
| 56 | print quotas |
| 57 | |
| 58 | -S | --softlimit sl Sets the quota soft limit to sl pages. |
| 59 | |
| 60 | -H | --hardlimit hl Sets the quota hard limit to hl pages. |
| 61 | |
| 62 | examples : |
| 63 | |
| 64 | $ edpykota -p jerome john paul george ringo |
| 65 | |
| 66 | This will set print quotas for the users john, paul, george and ringo |
| 67 | to the same values than user jerome. User jerome must exist. |
| 68 | |
| 69 | $ edpykota --printer lp -S 50 -H 60 jerome |
| 70 | |
| 71 | This will set jerome's print quota on the lp printer to a soft limit |
| 72 | of 50 pages, and a hard limit of 60 pages. If either user jerome or |
| 73 | printer lp doesn't exist on the Quota Storage Server then nothing is done. |
| 74 | |
| 75 | $ edpykota --add --printer lp -S 50 -H 60 jerome |
| 76 | |
| 77 | Same as above, but if either user jerome or printer lp doesn't exist |
| 78 | on the Quota Storage Server they are automatically added. |
| 79 | WARNING : the CUPS PPD file for this printer must still be modified |
| 80 | manually, as well as pykota's configuration file for a |
| 81 | new printer to be managed successfully. |
| 82 | |
| 83 | $ edpykota -g -S 500 -H 550 financial support |
| 84 | |
| 85 | This will set print quota soft limit to 500 pages and hard limit |
| 86 | to 550 pages for groups financial and support on all printers. |
| 87 | |
| 88 | This program is free software; you can redistribute it and/or modify |
| 89 | it under the terms of the GNU General Public License as published by |
| 90 | the Free Software Foundation; either version 2 of the License, or |
| 91 | (at your option) any later version. |
| 92 | |
| 93 | This program is distributed in the hope that it will be useful, |
| 94 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 95 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 96 | GNU General Public License for more details. |
| 97 | |
| 98 | You should have received a copy of the GNU General Public License |
| 99 | along with this program; if not, write to the Free Software |
| 100 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. |
| 101 | |
| 102 | Please e-mail bugs to: %s""" % (version.__version__, version.__author__) |
| 103 | |
| 104 | def main(arguments, options) : |
| 105 | """Edit user or group quotas.""" |
| 106 | pass |
| 107 | |
| 108 | if __name__ == "__main__" : |
| 109 | try : |
| 110 | tool = PyKotaTool(doc=__doc__) |
| 111 | |
| 112 | defaults = { \ |
| 113 | "users" : 1, \ |
| 114 | "groups" : 0, \ |
| 115 | } |
| 116 | short_options = "vhaugp:P:S:H:" |
| 117 | long_options = ["help", "version", "add", "users", "groups", "prototype=", "printer=", "softlimit=", "hardlimit="] |
| 118 | |
| 119 | # Initializes the command line tool |
| 120 | tool = PyKotaTool(doc=__doc__) |
| 121 | |
| 122 | # parse and checks the command line |
| 123 | (options, args) = tool.parseCommandline(sys.argv[1:], short_options, long_options) |
| 124 | |
| 125 | # sets long options |
| 126 | options["help"] = options["h"] or options["help"] |
| 127 | options["version"] = options["v"] or options["version"] |
| 128 | options["add"] = options["a"] or options["add"] |
| 129 | options["users"] = options["u"] or options["users"] or defaults["users"] |
| 130 | options["groups"] = options["g"] or options["groups"] or defaults["groups"] |
| 131 | options["prototype"] = options["p"] or options["prototype"] |
| 132 | options["printer"] = options["P"] or options["printer"] |
| 133 | options["softlimit"] = options["S"] or options["softlimit"] |
| 134 | options["hardlimit"] = options["H"] or options["hardlimit"] |
| 135 | |
| 136 | if options["help"] : |
| 137 | tool.display_usage_and_quit() |
| 138 | elif options["version"] : |
| 139 | tool.display_version_and_quit() |
| 140 | elif options["users"] and options["groups"] : |
| 141 | raise PyKotaToolError, "edpykota: options --users and --groups are incompatible.\n" |
| 142 | elif options["groups"] : # TODO : add support for group quotas |
| 143 | raise PyKotaToolError, "edpykota: group quotas are currently not implemented, sorry.\n" |
| 144 | else : |
| 145 | apply(main, args, options) |
| 146 | except PyKotaToolError, msg : |
| 147 | sys.stderr.write("%s\n" % msg) |
| 148 | sys.stderr.flush() |
| 149 | sys.exit(-1) |
| 150 | |