324 | | self.networkInterface = CGINetworkInterface(DUMPYKOTA_URL) |
| 323 | url = None |
| 324 | try : |
| 325 | # try a file on disk first |
| 326 | u = open(configFile) |
| 327 | except IOError : |
| 328 | try : |
| 329 | # then try through the web |
| 330 | u = urllib2.urlopen(configFile) |
| 331 | except (ValueError, IOError), msg : |
| 332 | raise IOError, _("Impossible to read configuration file %s : %s") % (configFile, msg) |
| 333 | url = u.readline().strip() |
| 334 | u.close() |
| 335 | |
| 336 | if not url : |
| 337 | raise ValueError, _("Configuration file %s is incorrect.") % configFile |
| 338 | self.networkInterface = CGINetworkInterface(url) |
335 | | self.User = self.networkInterface.getUserInfo(getCurrentUserName()) |
336 | | if self.User.LimitBy == "balance" : |
337 | | if self.User.Balance <= 0.0 : |
338 | | self.SetIcon(self.redicon) |
339 | | if self.tbicon is not None : |
340 | | self.tbicon.SetIcon(self.redicon, "PyKotIcon") |
341 | | else : |
342 | | self.SetIcon(self.greenicon) |
343 | | if self.tbicon is not None : |
344 | | self.tbicon.SetIcon(self.greenicon, "PyKotIcon") |
345 | | else : |
346 | | isRed = False |
347 | | for q in self.User.Quotas.keys() : |
348 | | quota = self.User.Quotas[q] |
349 | | if quota.SoftLimit is not None : |
350 | | if quota.PageCounter >= quota.SoftLimit : |
351 | | isRed = True |
352 | | break |
353 | | elif quota.HardLimit is not None : |
354 | | if quota.PageCounter >= quota.HardLimit : |
355 | | isRed = True |
356 | | break |
357 | | if isRed is True : |
358 | | self.SetIcon(self.redicon) |
359 | | if self.tbicon is not None : |
360 | | self.tbicon.SetIcon(self.redicon, "PyKotIcon") |
361 | | else : |
362 | | self.SetIcon(self.greenicon) |
363 | | if self.tbicon is not None : |
364 | | self.tbicon.SetIcon(self.greenicon, "PyKotIcon") |
365 | | if hasattr(self, "quotasgrid") : |
366 | | self.quotasgrid.Close() |
367 | | self.quotasgrid.Destroy() |
368 | | del self.quotasgrid |
369 | | self.quotasgrid = PyKotIconGrid(self, self.User) |
| 349 | try : |
| 350 | self.User = self.networkInterface.getUserInfo(getCurrentUserName()) |
| 351 | except IOError, msg : |
| 352 | sys.stderr.write("ERROR : %s\n" % msg) |
| 353 | else : |
| 354 | if self.User.LimitBy == "balance" : |
| 355 | if self.User.Balance <= 0.0 : |
| 356 | self.SetIcon(self.redicon) |
| 357 | if self.tbicon is not None : |
| 358 | self.tbicon.SetIcon(self.redicon, "PyKotIcon") |
| 359 | else : |
| 360 | self.SetIcon(self.greenicon) |
| 361 | if self.tbicon is not None : |
| 362 | self.tbicon.SetIcon(self.greenicon, "PyKotIcon") |
| 363 | else : |
| 364 | isRed = False |
| 365 | for q in self.User.Quotas.keys() : |
| 366 | quota = self.User.Quotas[q] |
| 367 | if quota.SoftLimit is not None : |
| 368 | if quota.PageCounter >= quota.SoftLimit : |
| 369 | isRed = True |
| 370 | break |
| 371 | elif quota.HardLimit is not None : |
| 372 | if quota.PageCounter >= quota.HardLimit : |
| 373 | isRed = True |
| 374 | break |
| 375 | if isRed is True : |
| 376 | self.SetIcon(self.redicon) |
| 377 | if self.tbicon is not None : |
| 378 | self.tbicon.SetIcon(self.redicon, "PyKotIcon") |
| 379 | else : |
| 380 | self.SetIcon(self.greenicon) |
| 381 | if self.tbicon is not None : |
| 382 | self.tbicon.SetIcon(self.greenicon, "PyKotIcon") |
| 383 | isiconized = self.IsIconized() |
| 384 | if isiconized is False : |
| 385 | self.Iconize(True) |
| 386 | isshown = self.IsShown() |
| 387 | if isshown is True : |
| 388 | self.Hide() |
| 389 | if hasattr(self, "quotasgrid") : |
| 390 | self.quotasgrid.Close() |
| 391 | self.quotasgrid.Destroy() |
| 392 | del self.quotasgrid |
| 393 | self.quotasgrid = PyKotIconGrid(self, self.User) |
| 394 | if isiconized is False : |
| 395 | self.Iconize(False) |
| 396 | if isshown is True : |
| 397 | self.Show(True) |
| 398 | self.Refresh() |
440 | | def test() : |
441 | | """Runs in test mode (console).""" |
442 | | if len(sys.argv) >= 3 : |
443 | | username = sys.argv[2] |
| 473 | # def test() : |
| 474 | # """Runs in test mode (console).""" |
| 475 | # print "Configuration file is ignored." |
| 476 | # if len(sys.argv) >= 3 : |
| 477 | # username = sys.argv[2] |
| 478 | # else : |
| 479 | # username = getCurrentUserName() |
| 480 | # net = CGINetworkInterface(DUMPYKOTA_URL) |
| 481 | # user = net.getUserInfo(username) |
| 482 | # print "UserName : ", user.UserName |
| 483 | # print "LimitBy : ", user.LimitBy |
| 484 | # print "Balance : ", user.Balance |
| 485 | # for printername in user.Quotas.keys() : |
| 486 | # quota = user.Quotas[printername] |
| 487 | # print "\tPrinterName : ", printername |
| 488 | # print "\tPageCounter : ", quota.PageCounter |
| 489 | # print "\tSoftLimit : ", quota.SoftLimit |
| 490 | # print "\tHardLimit : ", quota.HardLimit |
| 491 | # print "\tDateLimit : ", quota.DateLimit |
| 492 | # print |
| 493 | # for printername in user.Printers.keys() : |
| 494 | # printer = user.Printers[printername] |
| 495 | # print "\tPrinterName : ", printername |
| 496 | # print "\tPrice per Page : ", printer.PricePerPage |
| 497 | # print "\tPrice per Job : ", printer.PricePerJob |
| 498 | # print |
| 499 | |
| 500 | if __name__ == '__main__': |
| 501 | if len(sys.argv) >= 2 : |
| 502 | arg = sys.argv[1] |
| 503 | if arg in ("-v", "--version") : |
| 504 | print "0.1" |
| 505 | elif arg in ("-h", "--help") : |
| 506 | print "usage : pykoticon configuration_file" |
| 507 | #elif arg == "--test" : |
| 508 | # test() |
| 509 | else : |
| 510 | main(arg) |
445 | | username = getCurrentUserName() |
446 | | net = CGINetworkInterface(DUMPYKOTA_URL) |
447 | | user = net.getUserInfo(username) |
448 | | print "UserName : ", user.UserName |
449 | | print "LimitBy : ", user.LimitBy |
450 | | print "Balance : ", user.Balance |
451 | | for printername in user.Quotas.keys() : |
452 | | quota = user.Quotas[printername] |
453 | | print "\tPrinterName : ", printername |
454 | | print "\tPageCounter : ", quota.PageCounter |
455 | | print "\tSoftLimit : ", quota.SoftLimit |
456 | | print "\tHardLimit : ", quota.HardLimit |
457 | | print "\tDateLimit : ", quota.DateLimit |
458 | | print |
459 | | for printername in user.Printers.keys() : |
460 | | printer = user.Printers[printername] |
461 | | print "\tPrinterName : ", printername |
462 | | print "\tPrice per Page : ", printer.PricePerPage |
463 | | print "\tPrice per Job : ", printer.PricePerJob |
464 | | print |
465 | | |
466 | | if __name__ == '__main__': |
467 | | if (len(sys.argv) >= 2) and (sys.argv[1] == "--test") : |
468 | | test() |
469 | | else : |
470 | | main() |
471 | | |
| 512 | main("pykoticon.conf") |