Changeset 1542 for pykota/trunk/bin
- Timestamp:
- 06/17/04 15:26:51 (20 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/bin/cupspykota
r1541 r1542 24 24 # 25 25 # $Log$ 26 # Revision 1.63 2004/06/17 13:26:50 jalet 27 # Better exception handling code 28 # 26 29 # Revision 1.62 2004/06/16 20:56:34 jalet 27 30 # Smarter initialisation code … … 642 645 return retcode 643 646 647 def crashed(message) : 648 """Minimal crash method.""" 649 import traceback 650 lines = [] 651 for line in traceback.format_exception(*sys.exc_info()) : 652 lines.extend([l for l in line.split("\n") if l]) 653 msg = "ERROR: ".join(["%s\n" % l for l in ([message] + lines)]) 654 sys.stderr.write(msg) 655 sys.stderr.flush() 656 644 657 if __name__ == "__main__" : 645 658 # This is a CUPS backend, we should act and die like a CUPS backend 659 retcode = 0 646 660 if len(sys.argv) == 1 : 647 661 # we will execute each existing backend in device enumeration mode … … 680 694 fullname = fullname[1:-1] 681 695 print '%s cupspykota:%s "PyKota+%s" "PyKota managed %s"' % (devicetype, device, name, fullname) 682 retcode = 0 696 retcode = 0 683 697 elif len(sys.argv) not in (6, 7) : 684 698 sys.stderr.write("ERROR: %s job-id user title copies options [file]\n" % sys.argv[0]) … … 686 700 else : 687 701 try : 688 # Initializes the backend 689 kotabackend = PyKotaBackend() 690 retcode = kotabackend.mainWork() 702 try : 703 # Initializes the backend 704 kotabackend = PyKotaBackend() 705 except SystemExit : 706 retcode = -1 707 except : 708 crashed("cupspykota backend initialization failed") 709 retcode = 1 710 else : 711 retcode = kotabackend.mainWork() 712 kotabackend.storage.close() 713 kotabackend.closeJobDataStream() 691 714 except : 692 715 try : 693 716 kotabackend.crashed("cupspykota backend failed") 694 717 except : 695 pass 696 retcode = 1 697 698 try : 699 kotabackend.storage.close() 700 except (TypeError, NameError, AttributeError) : 701 pass 702 703 try : 704 kotabackend.closeJobDataStream() 705 except NameError, msg : 706 sys.stderr.write("ERROR: PyKota's CUPS backend wrapper didn't initialize correctly : %s\n" % msg) 707 sys.stderr.flush() 708 retcode = 1 718 crashed("cupspykota backend failed") 719 retcode = 1 709 720 710 721 sys.exit(retcode)