Package ClusterShell :: Package CLI :: Module Error
[hide private]
[frames] | no frames]

Source Code for Module ClusterShell.CLI.Error

 1  #!/usr/bin/env python 
 2  # 
 3  # Copyright (C) 2010-2012 CEA/DAM 
 4  # 
 5  # This file is part of ClusterShell. 
 6  # 
 7  # ClusterShell is free software; you can redistribute it and/or 
 8  # modify it under the terms of the GNU Lesser General Public 
 9  # License as published by the Free Software Foundation; either 
10  # version 2.1 of the License, or (at your option) any later version. 
11  # 
12  # ClusterShell is distributed in the hope that it will be useful, 
13  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
15  # Lesser General Public License for more details. 
16  # 
17  # You should have received a copy of the GNU Lesser General Public 
18  # License along with ClusterShell; if not, write to the Free Software 
19  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 
20   
21  """ 
22  CLI error handling helper functions 
23  """ 
24   
25  import os.path 
26  import signal 
27  import sys 
28   
29  from ClusterShell.Engine.Engine import EngineNotSupportedError 
30  from ClusterShell.CLI.Utils import GroupResolverConfigError  # dummy but safe 
31  from ClusterShell.NodeUtils import GroupResolverIllegalCharError 
32  from ClusterShell.NodeUtils import GroupResolverSourceError 
33  from ClusterShell.NodeUtils import GroupSourceError 
34  from ClusterShell.NodeUtils import GroupSourceNoUpcall 
35  from ClusterShell.NodeSet import NodeSetExternalError, NodeSetParseError 
36  from ClusterShell.NodeSet import RangeSetParseError 
37  from ClusterShell.Topology import TopologyError 
38  from ClusterShell.Worker.EngineClient import EngineClientError 
39  from ClusterShell.Worker.Worker import WorkerError 
40   
41  GENERIC_ERRORS = (EngineNotSupportedError, 
42                    EngineClientError, 
43                    NodeSetExternalError, 
44                    NodeSetParseError, 
45                    RangeSetParseError, 
46                    GroupResolverIllegalCharError, 
47                    GroupResolverSourceError, 
48                    GroupSourceError, 
49                    GroupSourceNoUpcall, 
50                    TopologyError, 
51                    TypeError, 
52                    IOError, 
53                    KeyboardInterrupt, 
54                    WorkerError) 
55   
56 -def handle_generic_error(excobj, prog=os.path.basename(sys.argv[0])):
57 """handle error given `excobj' generic script exception""" 58 try: 59 raise excobj 60 except EngineNotSupportedError, exc: 61 msgfmt = "%s: I/O events engine '%s' not supported on this host" 62 print >> sys.stderr, msgfmt % (prog, exc.engineid) 63 except EngineClientError, exc: 64 print >> sys.stderr, "%s: EngineClientError: %s" % (prog, exc) 65 except NodeSetExternalError, exc: 66 print >> sys.stderr, "%s: External error:" % prog, exc 67 except (NodeSetParseError, RangeSetParseError), exc: 68 print >> sys.stderr, "%s: Parse error:" % prog, exc 69 except GroupResolverIllegalCharError, exc: 70 print >> sys.stderr, '%s: Illegal group character: "%s"' % (prog, exc) 71 except GroupResolverSourceError, exc: 72 print >> sys.stderr, '%s: Unknown group source: "%s"' % (prog, exc) 73 except GroupSourceNoUpcall, exc: 74 msgfmt = '%s: No %s upcall defined for group source "%s"' 75 print >> sys.stderr, msgfmt % (prog, exc, exc.group_source.name) 76 except GroupSourceError, exc: 77 print >> sys.stderr, "%s: Group error:" % prog, exc 78 except TopologyError, exc: 79 print >> sys.stderr, "%s: TREE MODE:" % prog, exc 80 except (TypeError, WorkerError), exc: 81 print >> sys.stderr, "%s: %s" % (prog, exc) 82 except IOError: 83 # ignore broken pipe 84 pass 85 except KeyboardInterrupt, exc: 86 return 128 + signal.SIGINT 87 except: 88 assert False, "wrong GENERIC_ERRORS" 89 90 # Exit with error code 1 (generic failure) 91 return 1
92