Chromium Code Reviews| 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 """Gclient-specific SCM-specific operations.""" | 5 """Gclient-specific SCM-specific operations.""" | 
| 6 | 6 | 
| 7 import logging | 7 import logging | 
| 8 import os | 8 import os | 
| 9 import posixpath | 9 import posixpath | 
| 10 import re | 10 import re | 
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 69 if (url.startswith('git://') or url.startswith('ssh://') or | 69 if (url.startswith('git://') or url.startswith('ssh://') or | 
| 70 url.startswith('git+http://') or url.startswith('git+https://') or | 70 url.startswith('git+http://') or url.startswith('git+https://') or | 
| 71 url.endswith('.git')): | 71 url.endswith('.git')): | 
| 72 return 'git' | 72 return 'git' | 
| 73 elif (url.startswith('http://') or url.startswith('https://') or | 73 elif (url.startswith('http://') or url.startswith('https://') or | 
| 74 url.startswith('svn://') or url.startswith('svn+ssh://')): | 74 url.startswith('svn://') or url.startswith('svn+ssh://')): | 
| 75 return 'svn' | 75 return 'svn' | 
| 76 return None | 76 return None | 
| 77 | 77 | 
| 78 | 78 | 
| 79 def CheckCommandExecutable(cmd): | |
| 80 """Find the specified |cmd| in $PATH and checks if it's executable. | |
| 81 Raise an exception if fails. Otherwise do nothing.""" | |
| 82 paths = os.getenv('PATH').split(':') | |
| 
 
satorux1
2012/04/11 17:09:14
this fails if PATH is not set. os.getenv('PATH', '
 
Jun Mukai
2012/04/12 09:51:14
Done.
Also introduced os.pathsep instead of ':',
 
 | |
| 83 for path in paths: | |
| 84 full_path = os.path.join(path, cmd) | |
| 85 if os.path.exists(full_path): | |
| 86 if not os.path.isfile(full_path): | |
| 87 raise gclient_utils.Error('%s is not a file.' % full_path) | |
| 88 if not os.access(full_path, os.X_OK): | |
| 89 raise gclient_utils.Error('%s is not executable.' % full_path) | |
| 90 return | |
| 91 raise gclient_utils.Error('%s command is not found.' % cmd) | |
| 92 | |
| 93 | |
| 79 def CreateSCM(url, root_dir=None, relpath=None): | 94 def CreateSCM(url, root_dir=None, relpath=None): | 
| 80 SCM_MAP = { | 95 SCM_MAP = { | 
| 81 'svn' : SVNWrapper, | 96 'svn' : SVNWrapper, | 
| 82 'git' : GitWrapper, | 97 'git' : GitWrapper, | 
| 83 } | 98 } | 
| 84 | 99 | 
| 85 scm_name = GetScmName(url) | 100 scm_name = GetScmName(url) | 
| 86 if not scm_name in SCM_MAP: | 101 if not scm_name in SCM_MAP: | 
| 87 raise gclient_utils.Error('No SCM found for url %s' % url) | 102 raise gclient_utils.Error('No SCM found for url %s' % url) | 
| 103 CheckCommandExecutable(scm_name) | |
| 88 return SCM_MAP[scm_name](url, root_dir, relpath) | 104 return SCM_MAP[scm_name](url, root_dir, relpath) | 
| 89 | 105 | 
| 90 | 106 | 
| 91 # SCMWrapper base class | 107 # SCMWrapper base class | 
| 92 | 108 | 
| 93 class SCMWrapper(object): | 109 class SCMWrapper(object): | 
| 94 """Add necessary glue between all the supported SCM. | 110 """Add necessary glue between all the supported SCM. | 
| 95 | 111 | 
| 96 This is the abstraction layer to bind to different SCM. | 112 This is the abstraction layer to bind to different SCM. | 
| 97 """ | 113 """ | 
| (...skipping 1031 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1129 new_command.append('--force') | 1145 new_command.append('--force') | 
| 1130 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1146 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 
| 1131 new_command.extend(('--accept', 'theirs-conflict')) | 1147 new_command.extend(('--accept', 'theirs-conflict')) | 
| 1132 elif options.manually_grab_svn_rev: | 1148 elif options.manually_grab_svn_rev: | 
| 1133 new_command.append('--force') | 1149 new_command.append('--force') | 
| 1134 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1150 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 
| 1135 new_command.extend(('--accept', 'postpone')) | 1151 new_command.extend(('--accept', 'postpone')) | 
| 1136 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1152 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 
| 1137 new_command.extend(('--accept', 'postpone')) | 1153 new_command.extend(('--accept', 'postpone')) | 
| 1138 return new_command | 1154 return new_command | 
| OLD | NEW |