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

Side by Side Diff: git_cache.py

Issue 1156743008: Add experimental support for python in 'git cl format' (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 5 years, 6 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 | « gclient_utils.py ('k') | git_cl.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2014 The Chromium Authors. All rights reserved. 2 # Copyright 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """A git command for managing a local cache of git repositories.""" 6 """A git command for managing a local cache of git repositories."""
7 7
8 from __future__ import print_function 8 from __future__ import print_function
9 import errno 9 import errno
10 import logging 10 import logging
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 if norm_url.endswith('.git'): 178 if norm_url.endswith('.git'):
179 norm_url = norm_url[:-len('.git')] 179 norm_url = norm_url[:-len('.git')]
180 return norm_url.replace('-', '--').replace('/', '-').lower() 180 return norm_url.replace('-', '--').replace('/', '-').lower()
181 181
182 @staticmethod 182 @staticmethod
183 def CacheDirToUrl(path): 183 def CacheDirToUrl(path):
184 """Convert a cache dir path to its corresponding url.""" 184 """Convert a cache dir path to its corresponding url."""
185 netpath = re.sub(r'\b-\b', '/', os.path.basename(path)).replace('--', '-') 185 netpath = re.sub(r'\b-\b', '/', os.path.basename(path)).replace('--', '-')
186 return 'https://%s' % netpath 186 return 'https://%s' % netpath
187 187
188 @staticmethod
189 def FindExecutable(executable):
190 """This mimics the "which" utility."""
191 path_folders = os.environ.get('PATH').split(os.pathsep)
192
193 for path_folder in path_folders:
194 target = os.path.join(path_folder, executable)
195 # Just incase we have some ~/blah paths.
196 target = os.path.abspath(os.path.expanduser(target))
197 if os.path.isfile(target) and os.access(target, os.X_OK):
198 return target
199 if sys.platform.startswith('win'):
200 for suffix in ('.bat', '.cmd', '.exe'):
201 alt_target = target + suffix
202 if os.path.isfile(alt_target) and os.access(alt_target, os.X_OK):
203 return alt_target
204 return None
205
206 @classmethod 188 @classmethod
207 def SetCachePath(cls, cachepath): 189 def SetCachePath(cls, cachepath):
208 with cls.cachepath_lock: 190 with cls.cachepath_lock:
209 setattr(cls, 'cachepath', cachepath) 191 setattr(cls, 'cachepath', cachepath)
210 192
211 @classmethod 193 @classmethod
212 def GetCachePath(cls): 194 def GetCachePath(cls):
213 with cls.cachepath_lock: 195 with cls.cachepath_lock:
214 if not hasattr(cls, 'cachepath'): 196 if not hasattr(cls, 'cachepath'):
215 try: 197 try:
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 ['config', '--replace-all', 'remote.origin.fetch', refspec, regex], 248 ['config', '--replace-all', 'remote.origin.fetch', refspec, regex],
267 cwd=cwd) 249 cwd=cwd)
268 250
269 def bootstrap_repo(self, directory): 251 def bootstrap_repo(self, directory):
270 """Bootstrap the repo from Google Stroage if possible. 252 """Bootstrap the repo from Google Stroage if possible.
271 253
272 More apt-ly named bootstrap_repo_from_cloud_if_possible_else_do_nothing(). 254 More apt-ly named bootstrap_repo_from_cloud_if_possible_else_do_nothing().
273 """ 255 """
274 256
275 python_fallback = False 257 python_fallback = False
276 if sys.platform.startswith('win') and not self.FindExecutable('7z'): 258 if (sys.platform.startswith('win') and
259 not gclient_utils.FindExecutable('7z')):
277 python_fallback = True 260 python_fallback = True
278 elif sys.platform.startswith('darwin'): 261 elif sys.platform.startswith('darwin'):
279 # The OSX version of unzip doesn't support zip64. 262 # The OSX version of unzip doesn't support zip64.
280 python_fallback = True 263 python_fallback = True
281 elif not self.FindExecutable('unzip'): 264 elif not gclient_utils.FindExecutable('unzip'):
282 python_fallback = True 265 python_fallback = True
283 266
284 gs_folder = 'gs://%s/%s' % (self.bootstrap_bucket, self.basedir) 267 gs_folder = 'gs://%s/%s' % (self.bootstrap_bucket, self.basedir)
285 gsutil = Gsutil(self.gsutil_exe, boto_path=None) 268 gsutil = Gsutil(self.gsutil_exe, boto_path=None)
286 # Get the most recent version of the zipfile. 269 # Get the most recent version of the zipfile.
287 _, ls_out, _ = gsutil.check_call('ls', gs_folder) 270 _, ls_out, _ = gsutil.check_call('ls', gs_folder)
288 ls_out_sorted = sorted(ls_out.splitlines()) 271 ls_out_sorted = sorted(ls_out.splitlines())
289 if not ls_out_sorted: 272 if not ls_out_sorted:
290 # This repo is not on Google Storage. 273 # This repo is not on Google Storage.
291 return False 274 return False
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 dispatcher = subcommand.CommandDispatcher(__name__) 678 dispatcher = subcommand.CommandDispatcher(__name__)
696 return dispatcher.execute(OptionParser(), argv) 679 return dispatcher.execute(OptionParser(), argv)
697 680
698 681
699 if __name__ == '__main__': 682 if __name__ == '__main__':
700 try: 683 try:
701 sys.exit(main(sys.argv[1:])) 684 sys.exit(main(sys.argv[1:]))
702 except KeyboardInterrupt: 685 except KeyboardInterrupt:
703 sys.stderr.write('interrupted\n') 686 sys.stderr.write('interrupted\n')
704 sys.exit(1) 687 sys.exit(1)
OLDNEW
« no previous file with comments | « gclient_utils.py ('k') | git_cl.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698