1 | #! /usr/bin/env python |
---|
2 | # -*- coding: ISO-8859-15 -*- |
---|
3 | |
---|
4 | # $Id$ |
---|
5 | |
---|
6 | |
---|
7 | import sys |
---|
8 | import os |
---|
9 | import time |
---|
10 | |
---|
11 | def createBillingCodes(number) : |
---|
12 | """Creates a number of billing codes.""" |
---|
13 | sys.stdout.write("Adding %i billing codes...\n" % number) |
---|
14 | billingcodes = [ "test-billingcode-%05i" % i for i in range(number) ] |
---|
15 | argsfile = open("arguments.list", "w") |
---|
16 | argsfile.write('--add\n--reset\n--description\n"a billing code"\n') |
---|
17 | for bname in billingcodes : |
---|
18 | argsfile.write("%s\n" % bname) |
---|
19 | argsfile.close() |
---|
20 | before = time.time() |
---|
21 | os.system('pkbcodes --arguments arguments.list') |
---|
22 | after = time.time() |
---|
23 | sys.stdout.write("\nTime elapsed : %.2f seconds\n\n" % (after - before)) |
---|
24 | |
---|
25 | def deleteBillingCodes() : |
---|
26 | """Deletes all test billing codes.""" |
---|
27 | sys.stdout.write("Deleting billing codes...\n") |
---|
28 | before = time.time() |
---|
29 | os.system('pkbcodes --delete "test-billingcode-*"') |
---|
30 | after = time.time() |
---|
31 | sys.stdout.write("\nTime elapsed : %.2f seconds\n\n" % (after - before)) |
---|
32 | |
---|
33 | def createPrinters(number) : |
---|
34 | """Creates a number of printers.""" |
---|
35 | sys.stdout.write("Adding %i printers...\n" % number) |
---|
36 | printernames = [ "test-printer-%05i" % i for i in range(number) ] |
---|
37 | argsfile = open("arguments.list", "w") |
---|
38 | argsfile.write('--add\n--charge\n0.05\n--maxjobsize\n5\n--passthrough\n--description\n"a printer"\n') |
---|
39 | for pname in printernames : |
---|
40 | argsfile.write("%s\n" % pname) |
---|
41 | argsfile.close() |
---|
42 | before = time.time() |
---|
43 | os.system('pkprinters --arguments arguments.list') |
---|
44 | after = time.time() |
---|
45 | sys.stdout.write("\nTime elapsed : %.2f seconds\n\n" % (after - before)) |
---|
46 | |
---|
47 | def deletePrinters() : |
---|
48 | """Deletes all test printers.""" |
---|
49 | sys.stdout.write("Deleting printers...\n") |
---|
50 | before = time.time() |
---|
51 | os.system('pkprinters --delete "test-printer-*"') |
---|
52 | after = time.time() |
---|
53 | sys.stdout.write("\nTime elapsed : %.2f seconds\n\n" % (after - before)) |
---|
54 | |
---|
55 | def createUsers(number) : |
---|
56 | """Creates a number of users.""" |
---|
57 | sys.stdout.write("Adding %i users...\n" % number) |
---|
58 | usernames = [ "test-user-%05i" % i for i in range(number) ] |
---|
59 | argsfile = open("arguments.list", "w") |
---|
60 | argsfile.write('--add\n--limitby\nbalance\n--balance\n50.0\n') |
---|
61 | for uname in usernames : |
---|
62 | argsfile.write("%s\n" % uname) |
---|
63 | argsfile.close() |
---|
64 | before = time.time() |
---|
65 | os.system('edpykota --arguments arguments.list') |
---|
66 | after = time.time() |
---|
67 | sys.stdout.write("\nTime elapsed : %.2f seconds\n\n" % (after - before)) |
---|
68 | |
---|
69 | def deleteUsers() : |
---|
70 | """Deletes all test users.""" |
---|
71 | sys.stdout.write("Deleting users...\n") |
---|
72 | before = time.time() |
---|
73 | os.system('edpykota --delete "test-user-*"') |
---|
74 | after = time.time() |
---|
75 | sys.stdout.write("\nTime elapsed : %.2f seconds\n\n" % (after - before)) |
---|
76 | |
---|
77 | if __name__ == "__main__" : |
---|
78 | if len(sys.argv) == 1 : |
---|
79 | sys.stderr.write("usage : %s NbBillingCodes NbPrinters NbUsers\n" % sys.argv[0]) |
---|
80 | else : |
---|
81 | nbbillingcodes = int(sys.argv[1]) |
---|
82 | nbprinters = int(sys.argv[2]) |
---|
83 | nbusers = int(sys.argv[3]) |
---|
84 | if nbbillingcodes : |
---|
85 | createBillingCodes(nbbillingcodes) |
---|
86 | if nbprinters : |
---|
87 | createPrinters(nbprinters) |
---|
88 | if nbusers : |
---|
89 | createUsers(nbusers) |
---|
90 | if nbbillingcodes : |
---|
91 | deleteBillingCodes() |
---|
92 | if nbusers : |
---|
93 | deleteUsers() # NB : either this one or the one below |
---|
94 | if nbprinters : |
---|
95 | deletePrinters() # also delete user print quota entries. |
---|
96 | os.remove("arguments.list") |
---|
97 | |
---|