summaryrefslogtreecommitdiff
path: root/src/backend/solverevdeps.py
blob: 0400be91024d5bbfeb7153fd8734184453d78444 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/python3

import animation
import os
import pickle
import signal
import subprocess
import sys
import sisyphus.getfs


def sigint_handler(signal, frame):
    sys.exit(0)


signal.signal(signal.SIGINT, sigint_handler)


@animation.wait('resolving reverse dependencies')
def start(pkgname=None, depclean=False, unmerge=False):
    is_needed = int(0)

    if unmerge:
        pass  # behave like portage and ignore reverse dependencies
    else:
        try:
            p_exe = subprocess.Popen(['emerge', '--depclean', '--quiet', '--pretend',
                                     '--verbose'] + list(pkgname), stdout=subprocess.PIPE, stderr=subprocess.PIPE)

            stdout, stderr = p_exe.communicate()

            for p_out in stdout.decode('utf-8').splitlines():
                if any(key in p_out for key in ["pulled in by:", "required"]):
                    is_needed = int(1)

            pickle.dump(is_needed, open(os.path.join(
                sisyphus.getfs.p_mtd_dir, "sisyphus_pkgrevdeps.pickle"), "wb"))
        except KeyboardInterrupt:
            p_exe.terminate()
            try:
                p_exe.wait(1)
            except subprocess.TimeoutExpired:
                p_exe.kill()
            sys.exit()