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 atexit | |
7 import codecs | 8 import codecs |
8 import cStringIO | 9 import cStringIO |
9 import logging | 10 import logging |
10 import os | 11 import os |
11 import pipes | 12 import pipes |
12 import platform | 13 import platform |
13 import Queue | 14 import Queue |
14 import re | 15 import re |
15 import stat | 16 import stat |
16 import subprocess | 17 import subprocess |
17 import sys | 18 import sys |
18 import tempfile | 19 import tempfile |
19 import threading | 20 import threading |
20 import time | 21 import time |
21 import urlparse | 22 import urlparse |
22 | 23 |
23 import subprocess2 | 24 import subprocess2 |
24 | 25 |
25 | 26 |
26 RETRY_MAX = 3 | 27 RETRY_MAX = 3 |
27 RETRY_INITIAL_SLEEP = 0.5 | 28 RETRY_INITIAL_SLEEP = 0.5 |
28 | 29 |
29 | 30 |
31 _WARNINGS = [] | |
32 | |
33 | |
30 class Error(Exception): | 34 class Error(Exception): |
31 """gclient exception class.""" | 35 """gclient exception class.""" |
32 def __init__(self, msg, *args, **kwargs): | 36 def __init__(self, msg, *args, **kwargs): |
33 index = getattr(threading.currentThread(), 'index', 0) | 37 index = getattr(threading.currentThread(), 'index', 0) |
34 if index: | 38 if index: |
35 msg = '\n'.join('%d> %s' % (index, l) for l in msg.splitlines()) | 39 msg = '\n'.join('%d> %s' % (index, l) for l in msg.splitlines()) |
36 super(Error, self).__init__(msg, *args, **kwargs) | 40 super(Error, self).__init__(msg, *args, **kwargs) |
37 | 41 |
38 | 42 |
43 def _DisplayWarningsAtExit(): | |
44 """Display any stored warnings when the program exits.""" | |
45 if _WARNINGS: | |
46 print >> sys.stderr, '\n\nWarnings:' | |
47 for warning in _WARNINGS: | |
48 print >> sys.stderr, warning | |
49 | |
50 atexit.register(_DisplayWarningsAtExit) | |
M-A Ruel
2014/03/24 16:25:30
I'd prefer something more formal, a try/finally in
| |
51 | |
52 | |
53 def WarnOnExit(msg): | |
54 """Display the given warning when the program exits.""" | |
55 _WARNINGS.append(msg) | |
56 | |
57 | |
39 def SplitUrlRevision(url): | 58 def SplitUrlRevision(url): |
40 """Splits url and returns a two-tuple: url, rev""" | 59 """Splits url and returns a two-tuple: url, rev""" |
41 if url.startswith('ssh:'): | 60 if url.startswith('ssh:'): |
42 # Make sure ssh://user-name@example.com/~/test.git@stable works | 61 # Make sure ssh://user-name@example.com/~/test.git@stable works |
43 regex = r'(ssh://(?:[-.\w]+@)?[-\w:\.]+/[-~\w\./]+)(?:@(.+))?' | 62 regex = r'(ssh://(?:[-.\w]+@)?[-\w:\.]+/[-~\w\./]+)(?:@(.+))?' |
44 components = re.search(regex, url).groups() | 63 components = re.search(regex, url).groups() |
45 else: | 64 else: |
46 components = url.split('@', 1) | 65 components = url.split('@', 1) |
47 if len(components) == 1: | 66 if len(components) == 1: |
48 components += [None] | 67 components += [None] |
(...skipping 925 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
974 else: | 993 else: |
975 return '512m' | 994 return '512m' |
976 | 995 |
977 def DefaultIndexPackConfig(): | 996 def DefaultIndexPackConfig(): |
978 """Return reasonable default values for configuring git-index-pack. | 997 """Return reasonable default values for configuring git-index-pack. |
979 | 998 |
980 Experiments suggest that higher values for pack.threads don't improve | 999 Experiments suggest that higher values for pack.threads don't improve |
981 performance.""" | 1000 performance.""" |
982 return ['-c', 'pack.threads=5', '-c', | 1001 return ['-c', 'pack.threads=5', '-c', |
983 'core.deltaBaseCacheLimit=%s' % DefaultDeltaBaseCacheLimit()] | 1002 'core.deltaBaseCacheLimit=%s' % DefaultDeltaBaseCacheLimit()] |
OLD | NEW |