- Timestamp:
- 09/19/05 23:35:20 (19 years ago)
- Location:
- pykota/trunk
- Files:
-
- 15 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/bin/pkturnkey
r2466 r2467 29 29 import pwd 30 30 import grp 31 import socket 31 32 32 33 from pykota.tool import Tool, PyKotaToolError, crashed, N_ … … 47 48 -v | --version Prints pkturnkey version number then exits. 48 49 -h | --help Prints this message then exits. 50 51 -c | --doconf Give hints about what to put into pykota.conf 49 52 50 53 -d | --dousers Manages users accounts as well. … … 170 173 if users : 171 174 printersnames = [p[0] for p in printers] 172 command = "edpykota --add --noquota --printer %s %s" % (",".join(['"%s"' % p for p in printersnames]), \ 173 " ".join(['"%s"' % u for u in users])) 175 command = "edpykota --add --noquota --printer %s %s" \ 176 % (",".join(['"%s"' % p for p in printersnames]), \ 177 " ".join(['"%s"' % u for u in users])) 174 178 self.runCommand(command, dryrun) 175 179 … … 178 182 if groups : 179 183 printersnames = [p[0] for p in printers] 180 commands = ["edpykota --add --groups --noquota --printer %s %s" % (",".join(['"%s"' % p for p in printersnames]), \ 181 " ".join(['"%s"' % g for g in groups.keys()]))] 184 commands = ["edpykota --add --groups --noquota --printer %s %s" \ 185 % (",".join(['"%s"' % p for p in printersnames]), \ 186 " ".join(['"%s"' % g for g in groups.keys()]))] 182 187 revmembership = {} 183 188 for (groupname, usernames) in groups.items() : … … 185 190 revmembership.setdefault(username, []).append(groupname) 186 191 for (username, groupnames) in revmembership.items() : 187 commands.append('edpykota --ingroups %s "%s"' % (",".join(['"%s"' % g for g in groupnames]), username)) 192 commands.append('edpykota --ingroups %s "%s"' \ 193 % (",".join(['"%s"' % g for g in groupnames]), username)) 188 194 for command in commands : 189 195 self.runCommand(command, dryrun) 196 197 def hintConfig(self, printers) : 198 """Gives some hints about what to put into pykota.conf""" 199 if not printers : 200 return 201 sys.stderr.flush() # ensure outputs don't mix 202 print 203 print "--- CUT ---" 204 print "# Here are some lines that we suggest you add at the end" 205 print "# of the pykota.conf file. These lines gives possible" 206 print "# values for the way print jobs' size will be computed." 207 print "# NB : it is possible that a manual configuration gives" 208 print "# better results for you. As always, your mileage may vary." 209 print "#" 210 for (name, uri) in printers : 211 print "[%s]" % name 212 accounter = "software()" 213 try : 214 uri = uri.split("cupspykota:", 2)[-1] 215 except (ValueError, IndexError) : 216 pass 217 else : 218 while uri and uri.startswith("/") : 219 uri = uri[1:] 220 try : 221 (backend, destination) = uri.split(":", 1) 222 if backend not in ("ipp", "http", "https", "lpd", "socket") : 223 raise ValueError 224 except ValueError : 225 pass 226 else : 227 while destination.startswith("/") : 228 destination = destination[1:] 229 checkauth = destination.split("@", 1) 230 if len(checkauth) == 2 : 231 destination = checkauth[1] 232 parts = destination.split("/")[0].split(":") 233 if len(parts) == 2 : 234 (hostname, port) = parts 235 try : 236 port = int(port) 237 except ValueError : 238 port = 9100 239 else : 240 (hostname, port) = parts[0], 9100 241 242 # check udp/161 (SNMP) 243 # TODO : this doesn't work as expected if the host 244 # TODO : is down, I must find another solution. 245 trysnmp = 0 246 s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) 247 try : 248 s.connect((hostname, socket.getservbyname("snmp", "udp"))) 249 for i in range(2) : 250 s.send("") 251 except : 252 pass 253 else : 254 trysnmp = 1 255 s.close() 256 257 # check tcp/9100 258 trypjl = 0 259 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 260 try : 261 s.connect((hostname, port)) 262 except : 263 pass 264 else : 265 trypjl = 1 266 s.close() 267 268 if trysnmp : 269 accounter = "hardware(snmp)" 270 elif trypjl : 271 if port != 9100 : 272 accounter = "hardware(pjl:%s)" % port 273 else : 274 accounter = "hardware(pjl)" % port 275 276 print "accounter : %s" % accounter 277 print 278 print "--- CUT ---" 190 279 191 280 def main(self, names, options) : 192 281 """Intializes PyKota's database.""" 193 282 if not self.config.isAdmin : 194 raise PyKotaToolError, "%s : %s" % (pwd.getpwuid(os.geteuid())[0], _("You're not allowed to use this command.")) 283 raise PyKotaToolError, "%s : %s" % (pwd.getpwuid(os.geteuid())[0],\ 284 _("You're not allowed to use this command.")) 195 285 196 286 if not names : … … 215 305 uidmin = pwd.getpwnam(options["uidmin"])[2] 216 306 except KeyError, msg : 217 raise PyKotaToolError, _("Unknown username %s : %s") % (options["uidmin"], msg) 307 raise PyKotaToolError, _("Unknown username %s : %s") \ 308 % (options["uidmin"], msg) 218 309 219 310 if not options["uidmax"] : … … 226 317 uidmax = pwd.getpwnam(options["uidmax"])[2] 227 318 except KeyError, msg : 228 raise PyKotaToolError, _("Unknown username %s : %s") % (options["uidmax"], msg) 319 raise PyKotaToolError, _("Unknown username %s : %s") \ 320 % (options["uidmax"], msg) 229 321 230 322 if uidmin > uidmax : … … 245 337 gidmin = grp.getgrnam(options["gidmin"])[2] 246 338 except KeyError, msg : 247 raise PyKotaToolError, _("Unknown groupname %s : %s") % (options["gidmin"], msg) 339 raise PyKotaToolError, _("Unknown groupname %s : %s") \ 340 % (options["gidmin"], msg) 248 341 249 342 if not options["gidmax"] : … … 256 349 gidmax = grp.getgrnam(options["gidmax"])[2] 257 350 except KeyError, msg : 258 raise PyKotaToolError, _("Unknown groupname %s : %s") % (options["gidmax"], msg) 351 raise PyKotaToolError, _("Unknown groupname %s : %s") \ 352 % (options["gidmax"], msg) 259 353 260 354 if gidmin > gidmax : … … 278 372 else : 279 373 self.printInfo(_("Database initialized !")) 374 375 if options["doconf"] : 376 self.hintConfig(printers) 280 377 281 378 … … 283 380 retcode = 0 284 381 try : 285 short_options = "hvdDefu:U:g:G: "382 short_options = "hvdDefu:U:g:G:c" 286 383 long_options = ["help", "version", "dousers", "dogroups", \ 287 384 "emptygroups", "force", "uidmin=", "uidmax=", \ 288 "gidmin=", "gidmax=" ]385 "gidmin=", "gidmax=", "doconf"] 289 386 290 387 # Initializes the command line tool … … 309 406 options["gidmin"] = options["g"] or options["gidmin"] 310 407 options["gidmax"] = options["G"] or options["gidmax"] 408 options["doconf"] = options["c"] or options["doconf"] 311 409 312 410 if options["uidmin"] or options["uidmax"] : -
pykota/trunk/man/de/pkturnkey.1
r2466 r2467 22 22 \fB\-h\fR | \fB\-\-help\fR 23 23 Prints this message then exits. 24 .TP 25 \fB\-c\fR | \fB\-\-doconf\fR 26 Give hints about what to put into pykota.conf 24 27 .TP 25 28 \fB\-d\fR | \fB\-\-dousers\fR -
pykota/trunk/man/el_GR/pkturnkey.1
r2466 r2467 22 22 \fB\-h\fR | \fB\-\-help\fR 23 23 Prints this message then exits. 24 .TP 25 \fB\-c\fR | \fB\-\-doconf\fR 26 Give hints about what to put into pykota.conf 24 27 .TP 25 28 \fB\-d\fR | \fB\-\-dousers\fR -
pykota/trunk/man/es/pkturnkey.1
r2466 r2467 22 22 \fB\-h\fR | \fB\-\-help\fR 23 23 Prints this message then exits. 24 .TP 25 \fB\-c\fR | \fB\-\-doconf\fR 26 Give hints about what to put into pykota.conf 24 27 .TP 25 28 \fB\-d\fR | \fB\-\-dousers\fR -
pykota/trunk/man/fr/pkturnkey.1
r2466 r2467 22 22 \fB\-h\fR | \fB\-\-help\fR 23 23 Prints this message then exits. 24 .TP 25 \fB\-c\fR | \fB\-\-doconf\fR 26 Give hints about what to put into pykota.conf 24 27 .TP 25 28 \fB\-d\fR | \fB\-\-dousers\fR -
pykota/trunk/man/it/pkturnkey.1
r2466 r2467 22 22 \fB\-h\fR | \fB\-\-help\fR 23 23 Prints this message then exits. 24 .TP 25 \fB\-c\fR | \fB\-\-doconf\fR 26 Give hints about what to put into pykota.conf 24 27 .TP 25 28 \fB\-d\fR | \fB\-\-dousers\fR -
pykota/trunk/man/nb_NO/pkturnkey.1
r2466 r2467 22 22 \fB\-h\fR | \fB\-\-help\fR 23 23 Prints this message then exits. 24 .TP 25 \fB\-c\fR | \fB\-\-doconf\fR 26 Give hints about what to put into pykota.conf 24 27 .TP 25 28 \fB\-d\fR | \fB\-\-dousers\fR -
pykota/trunk/man/pkturnkey.1
r2466 r2467 22 22 \fB\-h\fR | \fB\-\-help\fR 23 23 Prints this message then exits. 24 .TP 25 \fB\-c\fR | \fB\-\-doconf\fR 26 Give hints about what to put into pykota.conf 24 27 .TP 25 28 \fB\-d\fR | \fB\-\-dousers\fR -
pykota/trunk/man/pt_BR/pkturnkey.1
r2466 r2467 22 22 \fB\-h\fR | \fB\-\-help\fR 23 23 Prints this message then exits. 24 .TP 25 \fB\-c\fR | \fB\-\-doconf\fR 26 Give hints about what to put into pykota.conf 24 27 .TP 25 28 \fB\-d\fR | \fB\-\-dousers\fR -
pykota/trunk/man/pt/pkturnkey.1
r2466 r2467 22 22 \fB\-h\fR | \fB\-\-help\fR 23 23 Prints this message then exits. 24 .TP 25 \fB\-c\fR | \fB\-\-doconf\fR 26 Give hints about what to put into pykota.conf 24 27 .TP 25 28 \fB\-d\fR | \fB\-\-dousers\fR -
pykota/trunk/man/sv_SE/pkturnkey.1
r2466 r2467 22 22 \fB\-h\fR | \fB\-\-help\fR 23 23 Prints this message then exits. 24 .TP 25 \fB\-c\fR | \fB\-\-doconf\fR 26 Give hints about what to put into pykota.conf 24 27 .TP 25 28 \fB\-d\fR | \fB\-\-dousers\fR -
pykota/trunk/man/th/pkturnkey.1
r2466 r2467 22 22 \fB\-h\fR | \fB\-\-help\fR 23 23 Prints this message then exits. 24 .TP 25 \fB\-c\fR | \fB\-\-doconf\fR 26 Give hints about what to put into pykota.conf 24 27 .TP 25 28 \fB\-d\fR | \fB\-\-dousers\fR -
pykota/trunk/man/tr/pkturnkey.1
r2466 r2467 22 22 \fB\-h\fR | \fB\-\-help\fR 23 23 Prints this message then exits. 24 .TP 25 \fB\-c\fR | \fB\-\-doconf\fR 26 Give hints about what to put into pykota.conf 24 27 .TP 25 28 \fB\-d\fR | \fB\-\-dousers\fR -
pykota/trunk/man/zh_TW/pkturnkey.1
r2466 r2467 22 22 \fB\-h\fR | \fB\-\-help\fR 23 23 Prints this message then exits. 24 .TP 25 \fB\-c\fR | \fB\-\-doconf\fR 26 Give hints about what to put into pykota.conf 24 27 .TP 25 28 \fB\-d\fR | \fB\-\-dousers\fR -
pykota/trunk/NEWS
r2466 r2467 31 31 arguments on pkturnkey's command line. 32 32 33 - pkturnkey now supersedes pkhint with the help of the -c | --doconf 34 command line option. 35 33 36 - 1.23alpha30 : 34 37