1 | #! /usr/bin/env python |
---|
2 | # -*- coding: ISO-8859-15 -*- |
---|
3 | |
---|
4 | # $Id$ |
---|
5 | |
---|
6 | |
---|
7 | import sys |
---|
8 | import os |
---|
9 | |
---|
10 | def createBillingCodes(number) : |
---|
11 | """Creates a number of billing codes.""" |
---|
12 | sys.stdout.write("Adding %i billing codes...\n" % number) |
---|
13 | billingcodes = [ "test-billingcode-%05i" % i for i in range(number) ] |
---|
14 | argsfile = open("arguments.list", "w") |
---|
15 | argsfile.write('--add\n--reset\n--description\n"a billing code"\n') |
---|
16 | for bname in billingcodes : |
---|
17 | argsfile.write("%s\n" % bname) |
---|
18 | argsfile.close() |
---|
19 | os.system('pkbcodes --arguments arguments.list') |
---|
20 | return billingcodes |
---|
21 | |
---|
22 | def deleteBillingCodes(billingcodes) : |
---|
23 | """Deletes all test billing codes.""" |
---|
24 | sys.stdout.write("Deleting billing codes...\n") |
---|
25 | argsfile = open("arguments.list", "w") |
---|
26 | argsfile.write('--delete\n') |
---|
27 | for bname in billingcodes : |
---|
28 | argsfile.write("%s\n" % bname) |
---|
29 | argsfile.close() |
---|
30 | os.system('pkbcodes --arguments arguments.list') |
---|
31 | |
---|
32 | def createPrinters(number) : |
---|
33 | """Creates a number of printers.""" |
---|
34 | sys.stdout.write("Adding %i printers...\n" % number) |
---|
35 | printernames = [ "test-printer-%05i" % i for i in range(number) ] |
---|
36 | argsfile = open("arguments.list", "w") |
---|
37 | argsfile.write('--add\n--charge\n0.05\n--maxjobsize\n5\n--passthrough\n--description\n"a printer"\n') |
---|
38 | for pname in printernames : |
---|
39 | argsfile.write("%s\n" % pname) |
---|
40 | argsfile.close() |
---|
41 | os.system('pkprinters --arguments arguments.list') |
---|
42 | return printernames |
---|
43 | |
---|
44 | def deletePrinters(printernames) : |
---|
45 | """Deletes all test printers.""" |
---|
46 | sys.stdout.write("Deleting printers...\n") |
---|
47 | argsfile = open("arguments.list", "w") |
---|
48 | argsfile.write('--delete\n') |
---|
49 | for pname in printernames : |
---|
50 | argsfile.write("%s\n" % pname) |
---|
51 | argsfile.close() |
---|
52 | os.system('pkprinters --arguments arguments.list') |
---|
53 | |
---|
54 | def createUsers(number) : |
---|
55 | """Creates a number of users.""" |
---|
56 | sys.stdout.write("Adding %i users...\n" % number) |
---|
57 | usernames = [ "test-user-%05i" % i for i in range(number) ] |
---|
58 | argsfile = open("arguments.list", "w") |
---|
59 | argsfile.write('--add\n--limitby\nbalance\n--balance\n50.0\n--description\n"an user"\n--comment\n"fake payment"\n') |
---|
60 | for uname in usernames : |
---|
61 | argsfile.write("%s\n" % uname) |
---|
62 | argsfile.close() |
---|
63 | os.system('pkusers --arguments arguments.list') |
---|
64 | return usernames |
---|
65 | |
---|
66 | def deleteUsers(usernames) : |
---|
67 | """Deletes all test users.""" |
---|
68 | sys.stdout.write("Deleting users...\n") |
---|
69 | argsfile = open("arguments.list", "w") |
---|
70 | argsfile.write('--delete\n') |
---|
71 | for uname in usernames : |
---|
72 | argsfile.write("%s\n" % uname) |
---|
73 | argsfile.close() |
---|
74 | os.system('pkusers --arguments arguments.list') |
---|
75 | |
---|
76 | def createGroups(number) : |
---|
77 | """Creates a number of groups.""" |
---|
78 | sys.stdout.write("Adding %i groups...\n" % number) |
---|
79 | groupnames = [ "test-group-%05i" % i for i in range(number) ] |
---|
80 | argsfile = open("arguments.list", "w") |
---|
81 | argsfile.write('--groups\n--add\n--limitby\nquota\n--description\n"a group"\n') |
---|
82 | for gname in groupnames : |
---|
83 | argsfile.write("%s\n" % gname) |
---|
84 | argsfile.close() |
---|
85 | os.system('pkusers --arguments arguments.list') |
---|
86 | return groupnames |
---|
87 | |
---|
88 | def deleteGroups(groupnames) : |
---|
89 | """Deletes all test groups.""" |
---|
90 | sys.stdout.write("Deleting groups...\n") |
---|
91 | argsfile = open("arguments.list", "w") |
---|
92 | argsfile.write('--groups\n--delete\n') |
---|
93 | for gname in groupnames : |
---|
94 | argsfile.write("%s\n" % gname) |
---|
95 | argsfile.close() |
---|
96 | os.system('pkusers --arguments arguments.list') |
---|
97 | |
---|
98 | def createUserPQuotas(usernames, printernames) : |
---|
99 | """Creates a number of user print quota entries.""" |
---|
100 | number = len(usernames) * len(printernames) |
---|
101 | sys.stdout.write("Adding %i user print quota entries...\n" % number) |
---|
102 | argsfile = open("arguments.list", "w") |
---|
103 | argsfile.write('--add\n--softlimit\n100\n--hardlimit\n110\n--reset\n--hardreset\n--printer\n') |
---|
104 | argsfile.write("%s\n" % ",".join(printernames)) |
---|
105 | for uname in usernames : |
---|
106 | argsfile.write("%s\n" % uname) |
---|
107 | argsfile.close() |
---|
108 | os.system('edpykota --arguments arguments.list') |
---|
109 | |
---|
110 | def deleteUserPQuotas(usernames, printernames) : |
---|
111 | """Deletes all test user print quota entries.""" |
---|
112 | number = len(usernames) * len(printernames) |
---|
113 | sys.stdout.write("Deleting user print quota entries...\n") |
---|
114 | argsfile = open("arguments.list", "w") |
---|
115 | argsfile.write('--delete\n--printer\n') |
---|
116 | argsfile.write("%s\n" % ",".join(printernames)) |
---|
117 | for uname in usernames : |
---|
118 | argsfile.write("%s\n" % uname) |
---|
119 | argsfile.close() |
---|
120 | os.system('edpykota --arguments arguments.list') |
---|
121 | |
---|
122 | def createGroupPQuotas(groupnames, printernames) : |
---|
123 | """Creates a number of group print quota entries.""" |
---|
124 | number = len(groupnames) * len(printernames) |
---|
125 | sys.stdout.write("Adding %i group print quota entries...\n" % number) |
---|
126 | argsfile = open("arguments.list", "w") |
---|
127 | argsfile.write('--groups\n--add\n--softlimit\n100\n--hardlimit\n110\n--reset\n--hardreset\n--printer\n') |
---|
128 | argsfile.write("%s\n" % ",".join(printernames)) |
---|
129 | for gname in groupnames : |
---|
130 | argsfile.write("%s\n" % gname) |
---|
131 | argsfile.close() |
---|
132 | os.system('edpykota --arguments arguments.list') |
---|
133 | |
---|
134 | def deleteGroupPQuotas(groupnames, printernames) : |
---|
135 | """Deletes all test group print quota entries.""" |
---|
136 | number = len(groupnames) * len(printernames) |
---|
137 | sys.stdout.write("Deleting group print quota entries...\n") |
---|
138 | argsfile = open("arguments.list", "w") |
---|
139 | argsfile.write('--groups\n--delete\n--printer\n') |
---|
140 | argsfile.write("%s\n" % ",".join(printernames)) |
---|
141 | for gname in groupnames : |
---|
142 | argsfile.write("%s\n" % gname) |
---|
143 | argsfile.close() |
---|
144 | os.system('edpykota --arguments arguments.list') |
---|
145 | |
---|
146 | if __name__ == "__main__" : |
---|
147 | if len(sys.argv) == 1 : |
---|
148 | sys.stderr.write("usage : %s [--nodelete] NbBillingCodes NbPrinters NbUsers NbGroups\n" % sys.argv[0]) |
---|
149 | else : |
---|
150 | delete = True |
---|
151 | args = sys.argv[1:] |
---|
152 | if args[0] == "--nodelete" : |
---|
153 | args = args[1:] |
---|
154 | delete = False |
---|
155 | nbbillingcodes = int(args[0]) |
---|
156 | nbprinters = int(args[1]) |
---|
157 | nbusers = int(args[2]) |
---|
158 | nbgroups = int(args[3]) |
---|
159 | if nbbillingcodes : |
---|
160 | bcodes = createBillingCodes(nbbillingcodes) |
---|
161 | if nbprinters : |
---|
162 | printers = createPrinters(nbprinters) |
---|
163 | if nbusers : |
---|
164 | users = createUsers(nbusers) |
---|
165 | if nbgroups : |
---|
166 | groups = createGroups(nbgroups) |
---|
167 | |
---|
168 | if nbusers and nbprinters : |
---|
169 | createUserPQuotas(users, printers) |
---|
170 | if delete : |
---|
171 | deleteUserPQuotas(users, printers) |
---|
172 | |
---|
173 | if nbgroups and nbprinters : |
---|
174 | createGroupPQuotas(groups, printers) |
---|
175 | if delete : |
---|
176 | deleteGroupPQuotas(groups, printers) |
---|
177 | |
---|
178 | if delete : |
---|
179 | if nbbillingcodes : |
---|
180 | deleteBillingCodes(bcodes) |
---|
181 | if nbgroups : |
---|
182 | deleteGroups(groups) |
---|
183 | if nbusers : |
---|
184 | deleteUsers(users) |
---|
185 | if nbprinters : |
---|
186 | deletePrinters(printers) |
---|
187 | os.remove("arguments.list") |
---|
188 | |
---|