38 | | |
39 | | __doc__ = N_("""pkturnkey v%(__version__)s (c) %(__years__)s %(__author__)s |
40 | | |
41 | | A turn key tool for PyKota. When launched, this command will initialize |
42 | | PyKota's database with all existing print queues and some or all users. |
43 | | For now, no prices or limits are set, so printing is fully accounted |
44 | | for, but not limited. That's why you'll probably want to also use |
45 | | edpykota once the database has been initialized. |
46 | | |
47 | | command line usage : |
48 | | |
49 | | pkturnkey [options] [printqueues names] |
50 | | |
51 | | options : |
52 | | |
53 | | -v | --version Prints pkturnkey version number then exits. |
54 | | -h | --help Prints this message then exits. |
55 | | |
56 | | -c | --doconf Give hints about what to put into pykota.conf |
57 | | |
58 | | -d | --dousers Manages users accounts as well. |
59 | | |
60 | | -D | --dogroups Manages users groups as well. |
61 | | Implies -d | --dousers. |
62 | | |
63 | | -e | --emptygroups Includes empty groups. |
64 | | |
65 | | -f | --force Modifies the database instead of printing what |
66 | | it would do. |
67 | | |
68 | | -u | --uidmin uid Only adds users whose uid is greater than or equal to |
69 | | uid. You can pass an username there as well, and its |
70 | | uid will be used automatically. |
71 | | If not set, 0 will be used automatically. |
72 | | Implies -d | --dousers. |
73 | | |
74 | | -U | --uidmax uid Only adds users whose uid is lesser than or equal to |
75 | | uid. You can pass an username there as well, and its |
76 | | uid will be used automatically. |
77 | | If not set, a large value will be used automatically. |
78 | | Implies -d | --dousers. |
79 | | |
80 | | -g | --gidmin gid Only adds groups whose gid is greater than or equal to |
81 | | gid. You can pass a groupname there as well, and its |
82 | | gid will be used automatically. |
83 | | If not set, 0 will be used automatically. |
84 | | Implies -D | --dogroups. |
85 | | |
86 | | -G | --gidmax gid Only adds groups whose gid is lesser than or equal to |
87 | | gid. You can pass a groupname there as well, and its |
88 | | gid will be used automatically. |
89 | | If not set, a large value will be used automatically. |
90 | | Implies -D | --dogroups. |
91 | | |
92 | | examples : |
93 | | |
94 | | $ pkturnkey --dousers --uidmin jerome |
95 | | |
96 | | Will simulate the initialization of PyKota's database will all existing |
97 | | printers and print accounts for all users whose uid is greater than |
98 | | or equal to jerome's one. Won't manage any users group. |
99 | | |
100 | | To REALLY initialize the database instead of simulating it, please |
101 | | use the -f | --force command line switch. |
102 | | |
103 | | You can limit the initialization to only a subset of the existing |
104 | | printers, by passing their names at the end of the command line. |
105 | | """) |
484 | | retcode = 0 |
485 | | try : |
486 | | short_options = "hvdDefu:U:g:G:c" |
487 | | long_options = ["help", "version", "dousers", "dogroups", \ |
488 | | "emptygroups", "force", "uidmin=", "uidmax=", \ |
489 | | "gidmin=", "gidmax=", "doconf"] |
490 | | |
491 | | # Initializes the command line tool |
492 | | manager = PKTurnKey(doc=__doc__) |
493 | | manager.deferredInit() |
494 | | |
495 | | # parse and checks the command line |
496 | | (options, args) = manager.parseCommandline(sys.argv[1:], \ |
497 | | short_options, \ |
498 | | long_options, \ |
499 | | allownothing=1) |
500 | | |
501 | | # sets long options |
502 | | options["help"] = options["h"] or options["help"] |
503 | | options["version"] = options["v"] or options["version"] |
504 | | options["dousers"] = options["d"] or options["dousers"] |
505 | | options["dogroups"] = options["D"] or options["dogroups"] |
506 | | options["emptygroups"] = options["e"] or options["emptygroups"] |
507 | | options["force"] = options["f"] or options["force"] |
508 | | options["uidmin"] = options["u"] or options["uidmin"] |
509 | | options["uidmax"] = options["U"] or options["uidmax"] |
510 | | options["gidmin"] = options["g"] or options["gidmin"] |
511 | | options["gidmax"] = options["G"] or options["gidmax"] |
512 | | options["doconf"] = options["c"] or options["doconf"] |
513 | | |
514 | | if options["uidmin"] or options["uidmax"] : |
515 | | if not options["dousers"] : |
516 | | manager.printInfo(_("The --uidmin or --uidmax command line option implies --dousers as well."), "warn") |
517 | | options["dousers"] = 1 |
518 | | |
519 | | if options["gidmin"] or options["gidmax"] : |
520 | | if not options["dogroups"] : |
521 | | manager.printInfo(_("The --gidmin or --gidmax command line option implies --dogroups as well."), "warn") |
522 | | options["dogroups"] = 1 |
523 | | |
524 | | if options["dogroups"] : |
525 | | if not options["dousers"] : |
526 | | manager.printInfo(_("The --dogroups command line option implies --dousers as well."), "warn") |
527 | | options["dousers"] = 1 |
528 | | |
529 | | if options["help"] : |
530 | | manager.display_usage_and_quit() |
531 | | elif options["version"] : |
532 | | manager.display_version_and_quit() |
533 | | else : |
534 | | retcode = manager.main(args, options) |
535 | | except KeyboardInterrupt : |
536 | | logerr("\nInterrupted with Ctrl+C !\n") |
537 | | retcode = -3 |
538 | | except PyKotaCommandLineError, msg : |
539 | | logerr("%s : %s\n" % (sys.argv[0], msg)) |
540 | | retcode = -2 |
541 | | except SystemExit : |
542 | | pass |
543 | | except : |
544 | | try : |
545 | | manager.crashed("pkturnkey failed") |
546 | | except : |
547 | | crashed("pkturnkey failed") |
548 | | retcode = -1 |
549 | | |
550 | | try : |
551 | | manager.storage.close() |
552 | | except (TypeError, NameError, AttributeError) : |
553 | | pass |
554 | | |
555 | | sys.exit(retcode) |
| 433 | parser = PyKotaOptionParser(description=_("A turn key tool for PyKota. When launched, this command will initialize PyKota's database with all existing print queues and some or all users. For now, no prices or limits are set, so printing is fully accounted for, but not limited. That's why you'll probably want to also use edpykota once the database has been initialized."), |
| 434 | usage="pkturnkey [options] printer1 printer2 ... printerN") |
| 435 | parser.add_option("-c", "--doconf", |
| 436 | action="store_true", |
| 437 | dest="doconf", |
| 438 | help=_("Try to autodetect the best print accounting settings for existing CUPS printers. All printers must be switched ON beforehand.")) |
| 439 | parser.add_option("-d", "--dousers", |
| 440 | action="store_true", |
| 441 | dest="dousers", |
| 442 | help=_("Create accounts for users, and allocate print quota entries for them.")) |
| 443 | parser.add_option("-D", "--dogroups", |
| 444 | action="store_true", |
| 445 | dest="dogroups", |
| 446 | help=_("Create accounts for users groups, and allocate print quota entries for them.")) |
| 447 | parser.add_option("-e", "--emptygroups", |
| 448 | action="store_true", |
| 449 | dest="emptygroups", |
| 450 | help=_("Also include groups which don't have any member.")) |
| 451 | parser.add_option("-f", "--force", |
| 452 | action="store_true", |
| 453 | dest="force", |
| 454 | help=_("Modifies PyKota's database content for real, instead of faking it (for safety reasons).")) |
| 455 | parser.add_option("-u", "--uidmin", |
| 456 | dest="uidmin", |
| 457 | help=_("Only include users whose uid is greater than or equal to this parameter. If you pass an username instead, his uid will be used automatically.")) |
| 458 | parser.add_option("-U", "--uidmax", |
| 459 | dest="uidmax", |
| 460 | help=_("Only include users whose uid is lesser than or equal to this parameter. If you pass an username instead, his uid will be used automatically.")) |
| 461 | parser.add_option("-g", "--gidmin", |
| 462 | dest="gidmin", |
| 463 | help=_("Only include users groups whose gid is greater than or equal to this parameter. If you pass a groupname instead, its gid will be used automatically.")) |
| 464 | parser.add_option("-G", "--gidmax", |
| 465 | dest="gidmax", |
| 466 | help=_("Only include users groups whose gid is lesser than or equal to this parameter. If you pass a groupname instead, its gid will be used automatically.")) |
| 467 | |
| 468 | parser.add_example("--dousers --uidmin jerome HPLASER1 HPLASER2", |
| 469 | _("Would simulate the creation in PyKota's database of the printing accounts for all users whose uid is greater than or equal to 'jerome''s. Each of them would be given a print quota entry on printers 'HPLASER1' and 'HPLASER2'.")) |
| 470 | parser.add_example("--force --dousers --uidmin jerome HPLASER1 HPLASER2", |
| 471 | _("Would do the same as the example above, but for real. Please take great care when using the --force command line option.")) |
| 472 | parser.add_example("--doconf", |
| 473 | _("Would try to automatically detect the best print accounting settings for all active printers, and generate some lines for you to add into your pykota.conf")) |
| 474 | run(parser, PKTurnKey) |