| OLD | NEW | 
|     1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |     1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 
|     2 # Use of this source code is governed by a BSD-style license that can be |     2 # Use of this source code is governed by a BSD-style license that can be | 
|     3 # found in the LICENSE file. |     3 # found in the LICENSE file. | 
|     4  |     4  | 
|     5 """Generic utils.""" |     5 """Generic utils.""" | 
|     6  |     6  | 
|     7 import codecs |     7 import codecs | 
|     8 import cStringIO |     8 import cStringIO | 
|     9 import datetime |     9 import datetime | 
|    10 import logging |    10 import logging | 
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   172   else: |   172   else: | 
|   173     rmtree(path) |   173     rmtree(path) | 
|   174  |   174  | 
|   175  |   175  | 
|   176 def rmtree(path): |   176 def rmtree(path): | 
|   177   """shutil.rmtree() on steroids. |   177   """shutil.rmtree() on steroids. | 
|   178  |   178  | 
|   179   Recursively removes a directory, even if it's marked read-only. |   179   Recursively removes a directory, even if it's marked read-only. | 
|   180  |   180  | 
|   181   shutil.rmtree() doesn't work on Windows if any of the files or directories |   181   shutil.rmtree() doesn't work on Windows if any of the files or directories | 
|   182   are read-only, which svn repositories and some .svn files are.  We need to |   182   are read-only. We need to be able to force the files to be writable (i.e., | 
|   183   be able to force the files to be writable (i.e., deletable) as we traverse |   183   deletable) as we traverse the tree. | 
|   184   the tree. |  | 
|   185  |   184  | 
|   186   Even with all this, Windows still sometimes fails to delete a file, citing |   185   Even with all this, Windows still sometimes fails to delete a file, citing | 
|   187   a permission error (maybe something to do with antivirus scans or disk |   186   a permission error (maybe something to do with antivirus scans or disk | 
|   188   indexing).  The best suggestion any of the user forums had was to wait a |   187   indexing).  The best suggestion any of the user forums had was to wait a | 
|   189   bit and try again, so we do that too.  It's hand-waving, but sometimes it |   188   bit and try again, so we do that too.  It's hand-waving, but sometimes it | 
|   190   works. :/ |   189   works. :/ | 
|   191  |   190  | 
|   192   On POSIX systems, things are a little bit simpler.  The modes of the files |   191   On POSIX systems, things are a little bit simpler.  The modes of the files | 
|   193   to be deleted doesn't matter, only the modes of the directories containing |   192   to be deleted doesn't matter, only the modes of the directories containing | 
|   194   them are significant.  As the directory tree is traversed, each directory |   193   them are significant.  As the directory tree is traversed, each directory | 
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   487         args, bufsize=0, stdout=subprocess2.PIPE, stderr=subprocess2.STDOUT, |   486         args, bufsize=0, stdout=subprocess2.PIPE, stderr=subprocess2.STDOUT, | 
|   488         **kwargs) |   487         **kwargs) | 
|   489  |   488  | 
|   490     GClientChildren.add(kid) |   489     GClientChildren.add(kid) | 
|   491  |   490  | 
|   492     # Do a flush of stdout before we begin reading from the subprocess2's stdout |   491     # Do a flush of stdout before we begin reading from the subprocess2's stdout | 
|   493     stdout.flush() |   492     stdout.flush() | 
|   494  |   493  | 
|   495     # Also, we need to forward stdout to prevent weird re-ordering of output. |   494     # Also, we need to forward stdout to prevent weird re-ordering of output. | 
|   496     # This has to be done on a per byte basis to make sure it is not buffered: |   495     # This has to be done on a per byte basis to make sure it is not buffered: | 
|   497     # normally buffering is done for each line, but if svn requests input, no |   496     # normally buffering is done for each line, but if the process requests | 
|   498     # end-of-line character is output after the prompt and it would not show up. |   497     # input, no end-of-line character is output after the prompt and it would | 
 |   498     # not show up. | 
|   499     try: |   499     try: | 
|   500       in_byte = kid.stdout.read(1) |   500       in_byte = kid.stdout.read(1) | 
|   501       if in_byte: |   501       if in_byte: | 
|   502         if call_filter_on_first_line: |   502         if call_filter_on_first_line: | 
|   503           filter_fn(None) |   503           filter_fn(None) | 
|   504         in_line = '' |   504         in_line = '' | 
|   505         while in_byte: |   505         while in_byte: | 
|   506           output.write(in_byte) |   506           output.write(in_byte) | 
|   507           if print_stdout: |   507           if print_stdout: | 
|   508             stdout.write(in_byte) |   508             stdout.write(in_byte) | 
| (...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1053         try: |  1053         try: | 
|  1054           work_queue.ready_cond.notifyAll() |  1054           work_queue.ready_cond.notifyAll() | 
|  1055         finally: |  1055         finally: | 
|  1056           work_queue.ready_cond.release() |  1056           work_queue.ready_cond.release() | 
|  1057  |  1057  | 
|  1058  |  1058  | 
|  1059 def GetEditor(git_editor=None): |  1059 def GetEditor(git_editor=None): | 
|  1060   """Returns the most plausible editor to use. |  1060   """Returns the most plausible editor to use. | 
|  1061  |  1061  | 
|  1062   In order of preference: |  1062   In order of preference: | 
|  1063   - GIT_EDITOR/SVN_EDITOR environment variable |  1063   - GIT_EDITOR environment variable | 
|  1064   - core.editor git configuration variable (if supplied by git-cl) |  1064   - core.editor git configuration variable (if supplied by git-cl) | 
|  1065   - VISUAL environment variable |  1065   - VISUAL environment variable | 
|  1066   - EDITOR environment variable |  1066   - EDITOR environment variable | 
|  1067   - vi (non-Windows) or notepad (Windows) |  1067   - vi (non-Windows) or notepad (Windows) | 
|  1068  |  1068  | 
|  1069   In the case of git-cl, this matches git's behaviour, except that it does not |  1069   In the case of git-cl, this matches git's behaviour, except that it does not | 
|  1070   include dumb terminal detection. |  1070   include dumb terminal detection. | 
|  1071   """ |  1071   """ | 
|  1072   editor = os.environ.get('GIT_EDITOR') or git_editor |  1072   editor = os.environ.get('GIT_EDITOR') or git_editor | 
|  1073   if not editor: |  1073   if not editor: | 
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1219     # Just incase we have some ~/blah paths. |  1219     # Just incase we have some ~/blah paths. | 
|  1220     target = os.path.abspath(os.path.expanduser(target)) |  1220     target = os.path.abspath(os.path.expanduser(target)) | 
|  1221     if os.path.isfile(target) and os.access(target, os.X_OK): |  1221     if os.path.isfile(target) and os.access(target, os.X_OK): | 
|  1222       return target |  1222       return target | 
|  1223     if sys.platform.startswith('win'): |  1223     if sys.platform.startswith('win'): | 
|  1224       for suffix in ('.bat', '.cmd', '.exe'): |  1224       for suffix in ('.bat', '.cmd', '.exe'): | 
|  1225         alt_target = target + suffix |  1225         alt_target = target + suffix | 
|  1226         if os.path.isfile(alt_target) and os.access(alt_target, os.X_OK): |  1226         if os.path.isfile(alt_target) and os.access(alt_target, os.X_OK): | 
|  1227           return alt_target |  1227           return alt_target | 
|  1228   return None |  1228   return None | 
| OLD | NEW |