import sys import asyncio import argparse from .config import Config from .util import term from .repo import Repo from . import server async def _update(package, args): print(" {0}: {1}".format(package.name, package.url)) await package.update() await package.makepkg(args.force) async def update(args, config): for repo in config.repos: repo = Repo(repo) print("Repo: {}".format(repo.name)) tasks = [] for package in repo.packages: tasks.append(_update(package, args)) await asyncio.gather(*tasks) async def webserver(args, config): server.start() def main(argv): # Setup argument parser parser = argparse.ArgumentParser( prog="pacman-repo", description='A tool for automating the creation and maintenance of pacman repos') parser.add_argument( '--config', '-c', default='/etc/pacman-repo.d', help="Configuration folder path" ) subparsers = parser.add_subparsers( required=True, dest='command', metavar='command') # Update command update_parser = subparsers.add_parser('update', help='Update repository') update_parser.add_argument( '--force', '-f', action="store_true", help="Force rebuild of all packages, even if they already exist" ) update_parser.set_defaults(func=update) # Daemon command webserver_parser = subparsers.add_parser('webserver', help='Run as a webserver') webserver_parser.add_argument( '--weserver', action='store_true', help='Run webserver ' ) webserver_parser.set_defaults(func=webserver) # Handle arguments args = parser.parse_args(argv) try: config = Config(args.config) asyncio.run(args.func(args, config)) except Exception: from traceback import format_exc msg = "Error encountered:\n" + format_exc().strip() print(term().red(msg)) sys.exit(1) if __name__ == '__main__': main(sys.argv[1:])