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

Side by Side Diff: gclient_scm.py

Issue 10034011: Check the existence and executability of scm commands (Closed) Base URL: http://src.chromium.org/svn/trunk/tools/depot_tools/
Patch Set: use os.pathsep Created 8 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | 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 (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
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):
M-A Ruel 2012/04/12 17:37:38 This belongs to gclient_utils.
Jun Mukai 2012/04/13 06:00:53 Done.
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(os.pathsep)
M-A Ruel 2012/04/12 17:37:38 os.environ['PATH'].split(os.pathsep) You can safe
Jun Mukai 2012/04/13 06:00:53 Done.
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)
M-A Ruel 2012/04/12 17:37:38 Why raise? FWIU, 'which' would move on. You should
Jun Mukai 2012/04/13 06:00:53 Done.
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)
M-A Ruel 2012/04/12 17:37:38 I prefer this function to return the path of the c
Jun Mukai 2012/04/13 06:00:53 Done. The reason for raise was that there could be
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
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
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698