1#!/usr/bin/env python 2 3# Copyright 2019 Google LLC. All rights reserved. 4# Use of this source code is governed by a BSD-style license that can be 5# found in the LICENSE file. 6 7""" 8 Generate a Fuchsia repo capable of serving Fuchsia archives over the 9 network. 10""" 11 12import argparse 13import os 14import subprocess 15import sys 16 17def main(): 18 parser = argparse.ArgumentParser() 19 20 parser.add_argument('--pm-bin', dest='pm_bin', action='store', required=True) 21 parser.add_argument( 22 '--repo-dir', dest='repo_dir', action='store', required=True) 23 parser.add_argument( 24 '--archive', dest='archives', action='append', required=True) 25 26 args = parser.parse_args() 27 28 assert os.path.exists(args.pm_bin) 29 30 if not os.path.exists(args.repo_dir): 31 pm_newrepo_command = [args.pm_bin, 'newrepo', '-repo', args.repo_dir] 32 subprocess.check_call(pm_newrepo_command) 33 34 pm_publish_command = [ 35 args.pm_bin, 36 'publish', 37 '-C', # Remove all previous registrations. 38 '-a', # Publish archives from an archive (mode). 39 '-repo', 40 args.repo_dir 41 ] 42 43 for archive in args.archives: 44 pm_publish_command.append('-f') 45 pm_publish_command.append(archive) 46 47 print "PM Publish: " 48 print pm_publish_command 49 subprocess.check_call(pm_publish_command) 50 51 return 0 52 53 54if __name__ == '__main__': 55 sys.exit(main()) 56