Changeset 3413 for pykota/trunk/bin/repykota
- Timestamp:
- 09/27/08 22:02:37 (16 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/bin/repykota
r3411 r3413 9 9 # the Free Software Foundation, either version 3 of the License, or 10 10 # (at your option) any later version. 11 # 11 # 12 12 # This program is distributed in the hope that it will be useful, 13 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 15 # GNU General Public License for more details. 16 # 16 # 17 17 # You should have received a copy of the GNU General Public License 18 18 # along with this program. If not, see <http://www.gnu.org/licenses/>. … … 36 36 from pykota.tool import PyKotaTool 37 37 from pykota import reporter 38 39 class RePyKota(PyKotaTool) : 38 39 class RePyKota(PyKotaTool) : 40 40 """A class for repykota.""" 41 41 def main(self, ugnames, options) : … … 43 43 if options.ingroups and options.groups : 44 44 raise PyKotaCommandLineError, _("Incompatible options, see help.") 45 45 46 46 if self.config.isAdmin : 47 47 # PyKota administrator … … 49 49 # no username, means all usernames 50 50 ugnames = [ "*" ] 51 51 52 52 if options.ingroups : 53 53 groupsnames = options.ingroups.split(",") … … 57 57 if not group.Exists : 58 58 self.printInfo("Group %s doesn't exist." % group.Name, "warn") 59 else : 59 else : 60 60 for user in self.storage.getGroupMembers(group) : 61 61 members[user.Name] = user 62 62 ugnames = [ m for m in members.keys() if self.matchString(m, ugnames) ] 63 else : 63 else : 64 64 # reports only the current user 65 65 if options.ingroups : 66 66 raise PyKotaCommandLineError, _("Option --ingroups is reserved to PyKota Administrators.") 67 67 68 68 username = pwd.getpwuid(os.geteuid())[0] 69 69 if options.groups : … … 71 71 if user.Exists : 72 72 ugnames = [ g.Name for g in self.storage.getUserGroups(user) ] 73 else : 73 else : 74 74 ugnames = [ ] 75 75 else : 76 76 ugnames = [ username ] 77 77 78 78 printers = self.storage.getMatchingPrinters(options.printer) 79 79 if not printers : 80 80 raise PyKotaCommandLineError, _("There's no printer matching %s") % options.printer 81 81 82 82 self.reportingtool = reporter.openReporter(self, "text", printers, ugnames, options.groups) 83 83 print self.reportingtool.generateReport() 84 85 if __name__ == "__main__" : 84 85 if __name__ == "__main__" : 86 86 parser = PyKotaOptionParser(description=_("Minimalist print accounting reports for PyKota. If not launched by a PyKota administrator, additionnal arguments representing users or groups names are ignored, limiting the scope of the reports to the current user."), 87 87 usage="repykota [options] [usernames|groupnames]") … … 97 97 default="*", 98 98 help=_("Acts on this printer only. You can specify several printer names by separating them with commas. The default value is '%default', which means all printers.")) 99 99 100 100 parser.add_example('', 101 101 _("This would generate a report for all users on all printers.")) … … 104 104 parser.add_example('--printer "laser*,*pson" jerome "jo*"', 105 105 _("This would generate a report for all users named 'jerome' or whose name begins with 'jo', on all printers which name begins with 'laser' or ends with 'pson'.")) 106 106 107 107 run(parser, RePyKota)