Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(152)

Side by Side Diff: client/third_party/infra_libs/utils.py

Issue 2708113002: Revert of Add field_specs to all metrics in luci-py (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « client/third_party/infra_libs/ts_mon/config.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2015 The Chromium Authors. All rights reserved. 1 # Copyright 2015 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 """Miscellaneous utility functions.""" 5 """Miscellaneous utility functions."""
6 6
7 7
8 import contextlib 8 import contextlib
9 import errno 9 import errno
10 import json 10 import json
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 68
69 Even with all this, Windows still sometimes fails to delete a file, citing 69 Even with all this, Windows still sometimes fails to delete a file, citing
70 a permission error (maybe something to do with antivirus scans or disk 70 a permission error (maybe something to do with antivirus scans or disk
71 indexing). The best suggestion any of the user forums had was to wait a 71 indexing). The best suggestion any of the user forums had was to wait a
72 bit and try again, so we do that too. It's hand-waving, but sometimes it 72 bit and try again, so we do that too. It's hand-waving, but sometimes it
73 works. :/ 73 works. :/
74 """ 74 """
75 if not os.path.exists(file_path): 75 if not os.path.exists(file_path):
76 return 76 return
77 77
78 if os.path.isfile(file_path):
79 for i in xrange(3):
80 try:
81 os.remove(file_path)
82 return
83 except OSError:
84 if i == 2:
85 raise
86 time.sleep(3)
87
88 if sys.platform == 'win32': 78 if sys.platform == 'win32':
89 # Give up and use cmd.exe's rd command. 79 # Give up and use cmd.exe's rd command.
90 file_path = os.path.normcase(file_path) 80 file_path = os.path.normcase(file_path)
91 for i in xrange(3): 81 for _ in xrange(3):
92 try: 82 if not subprocess.call(['cmd.exe', '/c', 'rd', '/q', '/s', file_path]):
93 subprocess.check_call(['cmd.exe', '/c', 'rd', '/q', '/s', file_path]) 83 break
94 return 84 time.sleep(3)
95 except subprocess.CalledProcessError: 85 return
96 if i == 2:
97 raise
98 time.sleep(3)
99 86
100 def remove_with_retry(rmfunc, path): 87 def remove_with_retry(rmfunc, path):
101 if os.path.islink(path): 88 if os.path.islink(path):
102 return os.remove(path) 89 return os.remove(path)
103 else: 90 else:
104 return rmfunc(path) 91 return rmfunc(path)
105 92
106 def rmtree_on_error(function, _, excinfo): 93 def rmtree_on_error(function, _, excinfo):
107 """This works around a problem whereby python 2.x on Windows has no ability 94 """This works around a problem whereby python 2.x on Windows has no ability
108 to check for symbolic links. os.path.islink always returns False. But 95 to check for symbolic links. os.path.islink always returns False. But
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 yield tempdir 161 yield tempdir
175 162
176 finally: 163 finally:
177 if tempdir and not keep_directory: # pragma: no branch 164 if tempdir and not keep_directory: # pragma: no branch
178 try: 165 try:
179 # TODO(pgervais,496347) Make this work reliably on Windows. 166 # TODO(pgervais,496347) Make this work reliably on Windows.
180 shutil.rmtree(tempdir, ignore_errors=True) 167 shutil.rmtree(tempdir, ignore_errors=True)
181 except OSError as ex: # pragma: no cover 168 except OSError as ex: # pragma: no cover
182 print >> sys.stderr, ( 169 print >> sys.stderr, (
183 "ERROR: {!r} while cleaning up {!r}".format(ex, tempdir)) 170 "ERROR: {!r} while cleaning up {!r}".format(ex, tempdir))
OLDNEW
« no previous file with comments | « client/third_party/infra_libs/ts_mon/config.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698