1*8975f5c5SAndroid Build Coastguard Worker# Copyright 2022 The Chromium Authors 2*8975f5c5SAndroid Build Coastguard Worker# Use of this source code is governed by a BSD-style license that can be 3*8975f5c5SAndroid Build Coastguard Worker# found in the LICENSE file. 4*8975f5c5SAndroid Build Coastguard Worker"""Implements commands for managing Fuchsia repos via the ffx tool.""" 5*8975f5c5SAndroid Build Coastguard Worker 6*8975f5c5SAndroid Build Coastguard Workerimport argparse 7*8975f5c5SAndroid Build Coastguard Worker 8*8975f5c5SAndroid Build Coastguard Workerfrom typing import Iterable 9*8975f5c5SAndroid Build Coastguard Worker 10*8975f5c5SAndroid Build Coastguard Workerfrom common import run_ffx_command 11*8975f5c5SAndroid Build Coastguard Worker 12*8975f5c5SAndroid Build Coastguard Worker 13*8975f5c5SAndroid Build Coastguard Workerdef publish_packages(packages: Iterable[str], 14*8975f5c5SAndroid Build Coastguard Worker repo: str, 15*8975f5c5SAndroid Build Coastguard Worker new_repo: bool = False) -> None: 16*8975f5c5SAndroid Build Coastguard Worker """Publish packages to a repo directory, initializing it if necessary.""" 17*8975f5c5SAndroid Build Coastguard Worker if new_repo: 18*8975f5c5SAndroid Build Coastguard Worker run_ffx_command(cmd=['repository', 'create', repo]) 19*8975f5c5SAndroid Build Coastguard Worker 20*8975f5c5SAndroid Build Coastguard Worker args = ['repository', 'publish'] 21*8975f5c5SAndroid Build Coastguard Worker for package in packages: 22*8975f5c5SAndroid Build Coastguard Worker args += ['--package-archive', package] 23*8975f5c5SAndroid Build Coastguard Worker args += [repo] 24*8975f5c5SAndroid Build Coastguard Worker run_ffx_command(cmd=args) 25*8975f5c5SAndroid Build Coastguard Worker 26*8975f5c5SAndroid Build Coastguard Worker 27*8975f5c5SAndroid Build Coastguard Workerdef register_package_args(parser: argparse.ArgumentParser, 28*8975f5c5SAndroid Build Coastguard Worker allow_temp_repo: bool = False) -> None: 29*8975f5c5SAndroid Build Coastguard Worker """Register common arguments for package publishing.""" 30*8975f5c5SAndroid Build Coastguard Worker package_args = parser.add_argument_group( 31*8975f5c5SAndroid Build Coastguard Worker 'package', 'Arguments for package publishing.') 32*8975f5c5SAndroid Build Coastguard Worker package_args.add_argument('--packages', 33*8975f5c5SAndroid Build Coastguard Worker action='append', 34*8975f5c5SAndroid Build Coastguard Worker help='Paths of the package archives to install') 35*8975f5c5SAndroid Build Coastguard Worker package_args.add_argument('--repo', 36*8975f5c5SAndroid Build Coastguard Worker help='Directory packages will be published to.') 37*8975f5c5SAndroid Build Coastguard Worker package_args.add_argument('--purge-repo', 38*8975f5c5SAndroid Build Coastguard Worker action='store_true', 39*8975f5c5SAndroid Build Coastguard Worker help='If clear the content in the repo.') 40*8975f5c5SAndroid Build Coastguard Worker if allow_temp_repo: 41*8975f5c5SAndroid Build Coastguard Worker package_args.add_argument( 42*8975f5c5SAndroid Build Coastguard Worker '--no-repo-init', 43*8975f5c5SAndroid Build Coastguard Worker action='store_true', 44*8975f5c5SAndroid Build Coastguard Worker default=False, 45*8975f5c5SAndroid Build Coastguard Worker help='Do not initialize the package repository.') 46