| OLD | NEW |
| 1 # Copyright 2016 The LUCI Authors. All rights reserved. | 1 # Copyright 2016 The LUCI Authors. All rights reserved. |
| 2 # Use of this source code is governed under the Apache License, Version 2.0 | 2 # Use of this source code is governed under the Apache License, Version 2.0 |
| 3 # that can be found in the LICENSE file. | 3 # that can be found in the LICENSE file. |
| 4 | 4 |
| 5 from __future__ import print_function | 5 from __future__ import print_function |
| 6 | 6 |
| 7 import contextlib | 7 import contextlib |
| 8 import logging | 8 import logging |
| 9 import os | 9 import os |
| 10 import shutil | 10 import shutil |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 args.workdir = tempfile.mkdtemp(prefix='recipe_engine_remote_') | 25 args.workdir = tempfile.mkdtemp(prefix='recipe_engine_remote_') |
| 26 logging.info('Created temporary workdir %s', args.workdir) | 26 logging.info('Created temporary workdir %s', args.workdir) |
| 27 | 27 |
| 28 try: | 28 try: |
| 29 yield | 29 yield |
| 30 finally: | 30 finally: |
| 31 if workdir_tempdir: | 31 if workdir_tempdir: |
| 32 shutil.rmtree(args.workdir, ignore_errors=True) | 32 shutil.rmtree(args.workdir, ignore_errors=True) |
| 33 | 33 |
| 34 | 34 |
| 35 def main(args): | 35 def add_subparser(parser): |
| 36 remote_p = parser.add_parser( |
| 37 'remote', |
| 38 description='Invoke a recipe command from specified repo and revision') |
| 39 remote_p.add_argument( |
| 40 '--repository', required=True, |
| 41 help='URL of a git repository to fetch') |
| 42 remote_p.add_argument( |
| 43 '--revision', |
| 44 help=( |
| 45 'Git commit hash to check out; defaults to latest revision on master' |
| 46 ' (refs/heads/master)' |
| 47 )) |
| 48 remote_p.add_argument( |
| 49 '--workdir', |
| 50 type=os.path.abspath, |
| 51 help='The working directory of repo checkout') |
| 52 remote_p.add_argument( |
| 53 '--use-gitiles', action='store_true', |
| 54 help='Use Gitiles-specific way to fetch repo (potentially cheaper for ' |
| 55 'large repos)') |
| 56 remote_p.add_argument( |
| 57 'remote_args', nargs='*', |
| 58 help='Arguments to pass to fetched repo\'s recipes.py') |
| 59 |
| 60 remote_p.set_defaults( |
| 61 command='remote', |
| 62 bare_command=True, |
| 63 func=main, |
| 64 ) |
| 65 |
| 66 |
| 67 def main(_package_deps, args): |
| 36 with ensure_workdir(args): | 68 with ensure_workdir(args): |
| 37 checkout_dir = os.path.join(args.workdir, 'checkout') | 69 checkout_dir = os.path.join(args.workdir, 'checkout') |
| 38 revision = args.revision or 'refs/heads/master' | 70 revision = args.revision or 'refs/heads/master' |
| 39 if args.use_gitiles: | 71 if args.use_gitiles: |
| 40 backend_class = fetch.GitilesBackend | 72 backend_class = fetch.GitilesBackend |
| 41 else: | 73 else: |
| 42 backend_class = fetch.GitBackend | 74 backend_class = fetch.GitBackend |
| 43 backend = backend_class(checkout_dir, args.repository, True) | 75 backend = backend_class(checkout_dir, args.repository, True) |
| 44 backend.checkout(revision) | 76 backend.checkout(revision) |
| 45 recipes_cfg = package_io.PackageFile( | 77 recipes_cfg = package_io.PackageFile( |
| 46 package.InfraRepoConfig().to_recipes_cfg(checkout_dir)) | 78 package.InfraRepoConfig().to_recipes_cfg(checkout_dir)) |
| 47 cmd = [ | 79 cmd = [ |
| 48 sys.executable, | 80 sys.executable, |
| 49 os.path.join( | 81 os.path.join( |
| 50 checkout_dir, | 82 checkout_dir, |
| 51 recipes_cfg.read().recipes_path, | 83 recipes_cfg.read().recipes_path, |
| 52 'recipes.py'), | 84 'recipes.py'), |
| 53 ] + args.remote_args | 85 ] + args.remote_args |
| 54 logging.info('Running %r', cmd) | 86 logging.info('Running %r', cmd) |
| 55 return subprocess.call(cmd) | 87 return subprocess.call(cmd) |
| OLD | NEW |