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

Side by Side Diff: scripts/slave/git_setup.py

Issue 15270004: Add step generator protocol, remove annotated_checkout, remove script. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/build
Patch Set: Address comments and change expected json output format Created 7 years, 7 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 | « scripts/slave/annotated_run.py ('k') | scripts/slave/recipe_util.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 """This script ensures that a given directory is an initialized git repo."""
6
7 import argparse
8 import logging
9 import os
10 import subprocess
11 import sys
12
13
14 def run_git(*args, **kwargs):
15 """Runs git with given arguments.
16
17 kwargs are passed through to subprocess.
18
19 If the kwarg 'throw' is provided, this behaves as check_call, otherwise will
20 return git's return value.
21 """
22 logging.info('Running: git %s %s', args, kwargs)
23 func = subprocess.check_call if kwargs.pop('throw', True) else subprocess.call
24 return func(('git',)+args, **kwargs)
25
26
27 def main():
28 parser = argparse.ArgumentParser()
29 parser.add_argument('path', help='Path to prospective git repo.',
30 required=True)
31 parser.add_argument('url', help='URL of remote to make origin.',
32 required=True)
33 parser.add_argument('verbose', action='store_true')
34 opts = parser.parse_args()
35
36 path = opts.path
37 url = opts.url
38
39 logging.getLogger().setLevel(logging.DEBUG if opts.verbose else logging.WARN)
40
41 if not os.path.exists(path):
42 os.makedirs(path)
43
44 exists = run_git('branch', cwd=path, throw=False) == 0
45 if exists:
46 run_git('remote', 'rm', 'origin', cwd=path)
47 else:
48 run_git('init', cwd=path)
49 run_git('remote', 'add', 'origin', url, cwd=path)
50 return 0
51
52
53 if __name__ == '__main__':
54 sys.exit(main())
OLDNEW
« no previous file with comments | « scripts/slave/annotated_run.py ('k') | scripts/slave/recipe_util.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698