__init__.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import sys
  2. import argparse
  3. from .config import Config
  4. from .util import term
  5. from .repo import Repo
  6. from . import server
  7. def update(args, config):
  8. print(config.path)
  9. print('---')
  10. print()
  11. print(config)
  12. print()
  13. for repo in config.repos:
  14. print(repo.path)
  15. print('---')
  16. print()
  17. print(repo)
  18. print()
  19. for server in config.servers:
  20. print(server.path)
  21. print('---')
  22. print()
  23. print(server)
  24. print()
  25. repos = []
  26. for repo in config.repos:
  27. repo = Repo(repo)
  28. repos.append(repo)
  29. print("Repo: {}".format(repo.name))
  30. for package in repo.packages:
  31. package.update()
  32. print(" {0}: {1}".format(package.name, package.url))
  33. package.makepkg(args.force)
  34. def webserver(args, config):
  35. server.start()
  36. def main(argv):
  37. # Setup argument parser
  38. parser = argparse.ArgumentParser(
  39. prog="pacman-repo",
  40. description='A tool for automating the creation and maintenance of pacman repos')
  41. parser.add_argument(
  42. '--config', '-c',
  43. default='/etc/pacman-repo.d',
  44. help="Configuration folder path"
  45. )
  46. subparsers = parser.add_subparsers()
  47. # Update command
  48. update_parser = subparsers.add_parser('update', help='Update repository')
  49. update_parser.add_argument(
  50. '--force', '-f',
  51. action="store_true",
  52. help="Force rebuild of all packages, even if they already exist"
  53. )
  54. update_parser.set_defaults(func=update)
  55. # Daemon command
  56. webserver_parser = subparsers.add_parser('webserver', help='Run as a webserver')
  57. webserver_parser.add_argument(
  58. '--weserver',
  59. action='store_true',
  60. help='Run webserver '
  61. )
  62. webserver_parser.set_defaults(func=webserver)
  63. # Handle arguments
  64. args = parser.parse_args(argv)
  65. try:
  66. config = Config(args.config)
  67. args.func(args, config)
  68. except Exception:
  69. from traceback import format_exc
  70. msg = "Error encountered:\n" + format_exc().strip()
  71. print(term().red(msg))
  72. sys.exit(1)
  73. if __name__ == '__main__':
  74. main(sys.argv[1:])