Commits

Anonymous committed 6947204

Better detection of KeyboardInterrupts. (Christoph Wiedemann)

Comments (0)

Files changed (19)

 
   - Support calling a Builder when a Configure context is still open.
 
+  - Handle interrupts better by eliminating all try:-except: blocks
+    which caught any and all exceptions, including KeyboardInterrupt.
+
 
 
 RELEASE 0.92 - Wed, 20 Aug 2003 03:45:28 -0500

src/engine/SCons/Action.py

         try:
             # "self.execfunction" is a function.
             code = self.execfunction.func_code.co_code
-        except:
+        except AttributeError:
             # "self.execfunction" is a callable object.
             code = self.execfunction.__call__.im_func.func_code.co_code
         return str(code) + env.subst(string.join(map(lambda v: '${'+v+'}',

src/engine/SCons/Job.py

 
             try:
                 task.execute()
+            except KeyboardInterrupt:
+                # be explicit here for test/interrupts.py
+                ok = False
             except:
                 ok = 0
             else:

src/engine/SCons/Node/FS.py

                 self._cwd = dir
                 if change_os_dir:
                     os.chdir(dir.abspath)
-        except:
+        except OSError:
             self._cwd = curr
             raise
 
     def rfile(self):
         try:
             return self._rfile
-        except:
+        except AttributeError:
             self._rfile = self
             if not self.exists():
                 n = self.fs.Rsearch(self.path, clazz=File,

src/engine/SCons/Options.py

                         value = env[option.key]
                         try:
                             eval(repr(value))
+                        except KeyboardInterrupt:
+                            raise
                         except:
                             # Convert stuff that has a repr() that
                             # cannot be evaluated into a string

src/engine/SCons/Platform/win32.py

             try:
                 stdout.write(open( tmpFileStdout, "r" ).read())
                 os.remove( tmpFileStdout )
-            except:
+            except (IOError, OSError):
                 pass
 
         if stderr != None and stderrRedirected == 0:
             try:
                 stderr.write(open( tmpFileStderr, "r" ).read())
                 os.remove( tmpFileStderr )
-            except:
-                    pass
+            except (IOError, OSError):
+                pass
         return ret
 
 def spawn(sh, escape, cmd, args, env):
     # A resonable default if we can't read the registry
     try:
         val = os.environ['SYSTEMROOT']
-    except:
+    except KeyError:
         val = "C:/WINDOWS"
         pass
 
                 k=SCons.Util.RegOpenKeyEx(SCons.Util.hkey_mod.HKEY_LOCAL_MACHINE,
                                           'Software\\Microsoft\\Windows\\CurrentVersion')
                 val, tok = SCons.Util.RegQueryValueEx(k, 'SystemRoot')
+            except KeyboardInterrupt:
+                raise
             except:
                 pass
     return val
                                               'Software\\Microsoft\\Windows\\CurrentVersion')
                 val, tok = SCons.Util.RegQueryValueEx(k, 'SystemRoot')
                 cmd_interp = os.path.join(val, 'command.com')
+            except KeyboardInterrupt:
+                raise
             except:
                 pass
 

src/engine/SCons/SConf.py

                 sys.stderr.write("scons: *** [%s] %s\n" % (e.node, e.errstr))
                 if e.errstr == 'Exception':
                     traceback.print_exception(e.args[0], e.args[1], e.args[2])
-            except:
-                raise
 
             for n in nodes:
                 state = n.get_state()
             if cacheDesc['scons_version'] != SCons.__version__:
                 raise Exception, "version mismatch"
             self.cache = cacheDesc['data']
+        except KeyboardInterrupt:
+            raise
         except:
             self.cache = {}
 

src/engine/SCons/Script/SConscript.py

     """Return the locals and globals for the function that called
     into this module in the current callstack."""
     try: 1/0
-    except: frame = sys.exc_info()[2].tb_frame
+    except ZeroDivisionError: frame = sys.exc_info()[2].tb_frame
     
     while frame.f_globals.get("__name__") == __name__: frame = frame.f_back
 

src/engine/SCons/Script/__init__.py

                                                                   __main__.__date__,
                                                                   __main__.__developer__,
                                                                   __main__.__buildsys__))
+        except KeyboardInterrupt:
+            raise
         except:
             # On win32 there is no scons.py, so there is no __main__.__version__,
             # hence there is no script version.
         cdir = _create_path(options.directory)
         try:
             os.chdir(cdir)
-        except:
+        except OSError:
             sys.stderr.write("Could not change directory to %s\n" % cdir)
 
     xmit_args = []

src/engine/SCons/Sig/__init__.py

         """
         try:
             return self.entries[filename]
-        except:
+        except (KeyError, AttributeError):
             return SConsignEntry()
 
     def set_entry(self, filename, entry):
                 if type(self.entries) is not type({}):
                     self.entries = {}
                     raise TypeError
+            except KeyboardInterrupt:
+                raise
             except:
                 SCons.Warnings.warn(SCons.Warnings.CorruptSConsignWarning,
                                     "Ignoring corrupt sconsign entry : %s"%self.dir.path)
 
         try:
             fp = open(self.sconsign, 'rb')
-        except:
+        except IOError:
             fp = None
 
         try:
             SConsignDir.__init__(self, fp, module)
+        except KeyboardInterrupt:
+            raise
         except:
             SCons.Warnings.warn(SCons.Warnings.CorruptSConsignWarning,
                                 "Ignoring corrupt .sconsign file: %s"%self.sconsign)
             try:
                 file = open(temp, 'wb')
                 fname = temp
-            except:
+            except IOError:
                 try:
                     file = open(self.sconsign, 'wb')
                     fname = self.sconsign
-                except:
+                except IOError:
                     return
             cPickle.dump(self.entries, file, 1)
             file.close()
                     mode = os.stat(self.sconsign)[0]
                     os.chmod(self.sconsign, 0666)
                     os.unlink(self.sconsign)
-                except:
+                except OSError:
                     pass
                 try:
                     os.rename(fname, self.sconsign)
-                except:
+                except OSError:
                     open(self.sconsign, 'wb').write(open(fname, 'rb').read())
                     os.chmod(self.sconsign, mode)
             try:
                 os.unlink(temp)
-            except:
+            except OSError:
                 pass
 
 SConsignForDirectory = SConsignDirFile

src/engine/SCons/Taskmaster.py

                 self.candidates.pop()
                 self.ready = node
                 break
+            except KeyboardInterrupt:
+                raise
             except:
                 # We had a problem just trying to figure out the
                 # children (like a child couldn't be linked in to a
             try:
                 def derived_nodes(node): return node.is_derived() or node.is_pseudo_derived()
                 derived = filter(derived_nodes, children)
+            except KeyboardInterrupt:
+                raise
             except:
                 # We had a problem just trying to figure out if any of
                 # the kids are derived (like a child couldn't be linked
         task = self.tasker(self, tlist, node in self.targets, node)
         try:
             task.make_ready()
+        except KeyboardInterrupt:
+            raise
         except:
             # We had a problem just trying to get this task ready (like
             # a child couldn't be linked in to a BuildDir when deciding

src/engine/SCons/Tool/hpc++.py

 
 try:
     dirs = os.listdir('/opt')
-except:
+except OSError:
     dirs = []
 
 for dir in dirs:

src/engine/SCons/Tool/hplink.py

 
 try:
     dirs = os.listdir('/opt')
-except:
+except OSError:
     dirs = []
 
 for dir in dirs:

src/engine/SCons/Tool/javah.py

         else:
             try:
                 classdir = s.attributes.java_classdir
-            except:
+            except AttributeError:
                 classdir = '.'
     classdir = SCons.Node.FS.default_fs.Dir(classdir).rdir()
     if str(classdir) == '.':

src/engine/SCons/Tool/msvc.py

     try:
         if not version:
             version = SCons.Tool.msvs.get_visualstudio_versions()[0] #use highest version
+    except KeyboardInterrupt:
+        raise
     except:
         pass
 

src/engine/SCons/Tool/msvs.py

         try:
             datas = base64.decodestring(datas)
             data = pickle.loads(datas)
+        except KeyboardInterrupt:
+            raise
         except:
             return # unable to unpickle any data for some reason
 
         try:
             datas = base64.decodestring(datas)
             data = pickle.loads(datas)
+        except KeyboardInterrupt:
+            raise
         except:
             return # unable to unpickle any data for some reason
 
         try:
             datas = base64.decodestring(datas)
             data = pickle.loads(datas)
+        except KeyboardInterrupt:
+            raise
         except:
             return # unable to unpickle any data for some reason
 
         try:
             datas = base64.decodestring(datas)
             data = pickle.loads(datas)
+        except KeyboardInterrupt:
+            raise
         except:
             return # unable to unpickle any data for some reason
 
         try:
             datas = base64.decodestring(datas)
             data = pickle.loads(datas)
+        except KeyboardInterrupt:
+            raise
         except:
             return # unable to unpickle any data for some reason
 

src/engine/SCons/Tool/rmic.py

         else:
             try:
                 classdir = s.attributes.java_classdir
-            except:
+            except AttributeError:
                 classdir = '.'
     classdir = SCons.Node.FS.default_fs.Dir(classdir).rdir()
     if str(classdir) == '.':

src/engine/SCons/Tool/sunlink.py

 
 try:
     dirs = os.listdir('/opt')
-except:
+except OSError:
     dirs = []
 
 for dir in dirs:

src/engine/SCons/Util.py

             if os.path.isfile(f):
                 try:
                     st = os.stat(f)
-                except:
+                except OSError:
                     continue
                 if stat.S_IMODE(st[stat.ST_MODE]) & 0111:
                     return os.path.normpath(f)