diff --git a/rpmbuild/bin/copr-builder b/rpmbuild/bin/copr-builder index 2a1712e87..fb9bd65ce 100755 --- a/rpmbuild/bin/copr-builder +++ b/rpmbuild/bin/copr-builder @@ -2,16 +2,7 @@ """ -TODO This script will have several commands: - -- copr-builder help - - We probably don't want MOTD because of the corner-case @xsuchy mentioned - - So we will instruct people to manually run this command after logging in - - This should have full instructions for working with the builder instance - -- copr-builder prolong -- copr-builder release (or finish/end/kill/stop/destroy) - +TODO The `prolong` and `release` commands are self-explanatory but I just realized I have no idea how to implement them: - By design builder cannot send information to backend or frontend @@ -22,9 +13,140 @@ I have no idea how to implement them: """ -def main(): +import argparse + + +def cmd_help(): + """ + Print full instructions for working with the builder instance. + Ideally we would have this in MOTD but that would cause problems in cases + like `if $(ssh stroj cat foo|head -n1) == "foo"`. So instead, we instruct + users to run `copr-builder help` manually. + """ + print( + "You have been entrusted with root access to a Copr builder.\n" + "Please be responsible.\n" + "\n" + "This instance should be used only for the purposes of debugging\n" + "build failures of RPM packages. It is not a personal VPS :-).\n" + "\n" + "Please be aware that the legal restrictions for what you can build\n" + "in Copr apply here as well.\n" + "https://docs.pagure.org/copr.copr/user_documentation.html#what-i-can-build-in-copr\n" + "\n" + "You can display more information about the builder using\n" + "`copr-builder show`\n" + "\n" + "What to do next?\n" + "\n" + "By default, the builder will be destroyed after 30 minutes. Extend\n" + "this period with `copr-builder prolong`.\n" + "\n" + "The selected (in Copr web UI) build was automatically resubmitted,\n" + "you can find the process with `ps ax |grep copr-rpmbuild`.\n" + "The results are produced in `/var/lib/copr-rpmbuild/`. See the\n" + "information at the beginning of the builder-live.log on how to\n" + "reproduce the build manually.\n" + "\n" + "Once you are finished and don't need the builder anymore,\n" + "please return it using `copr-builder release`.\n" + "\n" + "Happy debugging." + ) + + +def cmd_show(): + """ + TODO + """ pass +def cmd_prolong(): + """ + TODO + """ + pass + + +def cmd_release(): + """ + TODO + """ + pass + + + +def get_parser(): + parser = argparse.ArgumentParser( + "copr-builder", + description="Control a Copr builder", + ) + subparsers = parser.add_subparsers(title="actions") + + # Help parser + + parser_help = subparsers.add_parser( + "help", + help="All users should read this", + ) + parser_help.set_defaults(command="help") + + # Show parser + + parser_show = subparsers.add_parser( + "show", + help="TODO", + ) + parser_show.set_defaults(command="show") + + # Prolong parser + # Alternativelly extend + + parser_prolong = subparsers.add_parser( + "prolong", + help="TODO", + ) + parser_prolong.add_argument( + "--hours", + type=int, + help="TODO", + ) + parser_prolong.set_defaults(command="prolong") + + # Release parser + # Alternativelly finish/end/kill/stop/destroy + + parser_release = subparsers.add_parser( + "release", + help="TODO", + ) + parser_release.set_defaults(command="release") + return parser + + +def main(): + parser = get_parser() + args = parser.parse_args() + + if "command" not in args: + parser.print_help() + + elif args.command == "help": + cmd_help() + + elif args.command == "show": + cmd_show() + + elif args.command == "prolong": + cmd_prolong() + + elif args.command == "release": + cmd_release() + + else: + parser.print_help() + + if __name__ == "__main__": main()