| 1 |
#!/usr/bin/python3 |
| 2 |
import logging |
| 3 |
import os |
| 4 |
import tempfile |
| 5 |
|
| 6 |
from mini_buildd import changes, cli, config, sbuild |
| 7 |
|
| 8 |
LOG = logging.getLogger("mini_buildd") |
| 9 |
|
| 10 |
#: Needed for man page hack in setup.py |
| 11 |
DESCRIPTION = "Enter sbuild environment for given buildrequest changes file (manually debug failed builds)." |
| 12 |
|
| 13 |
|
| 14 |
class CLI(cli.CLI): |
| 15 |
SBUILD_HOOKS = ["chroot-setup", "chroot-update-failed", "build-deps-failed", "starting-build", "build-failed", "finished-build", "chroot-cleanup"] |
| 16 |
|
| 17 |
def __init__(self): |
| 18 |
super().__init__("mini-buildd-debug-build", |
| 19 |
DESCRIPTION, |
| 20 |
run_as_mini_buildd=True) |
| 21 |
self.parser.add_argument("-s", "--sbuild-hook", default="starting-build", choices=self.SBUILD_HOOKS, action="store", help="Sbuild hook to drop for shell (see ``man sbuild``)") |
| 22 |
self.parser.add_argument("-u", "--user", default="mini-buildd", action="store", help="User to use for post-build shell") |
| 23 |
self.parser.add_argument("-p", "--extra-package", default=[], action="append", help="Extra package to install (may be given multiple times)") |
| 24 |
self.parser.add_argument("buildrequest", action="store", metavar="BUILDREQUEST", help="Buildrequest changes file path") |
| 25 |
|
| 26 |
def runcli(self): |
| 27 |
config.ROUTES = config.Routes(os.path.expanduser("~")) |
| 28 |
|
| 29 |
breq = changes.Buildrequest(self.args.buildrequest) |
| 30 |
with tempfile.TemporaryDirectory(dir=config.ROUTES["debug"].path.full) as tmpdir: |
| 31 |
breq.copy_to(tmpdir) |
| 32 |
sbuild.SBuild(breq, [ |
| 33 |
"--add-depends", ",".join(self.args.extra_package), |
| 34 |
f"--{self.args.sbuild_hook}-commands", f"TERM={os.getenv('TERM', 'xterm')} runuser -u {self.args.user} -- %SBUILD_SHELL", |
| 35 |
]).run() |
| 36 |
|
| 37 |
|
| 38 |
if __name__ == "__main__": |
| 39 |
CLI().run() |