1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- import sys
- import argparse
- from .config import Config
- from .util import term
- from .repo import Repo
- from . import server
- def update(args, config):
- print(config.path)
- print('---')
- print()
- print(config)
- print()
- for repo in config.repos:
- print(repo.path)
- print('---')
- print()
- print(repo)
- print()
- for server in config.servers:
- print(server.path)
- print('---')
- print()
- print(server)
- print()
- repos = []
- for repo in config.repos:
- repo = Repo(repo)
- repos.append(repo)
- print("Repo: {}".format(repo.name))
- for package in repo.packages:
- package.update()
- print(" {0}: {1}".format(package.name, package.url))
- package.makepkg(args.force)
- 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()
- # 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)
- 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:])
|