aboutsummaryrefslogtreecommitdiffstats
path: root/pythoneggs.py
blob: b748f60e6c5072825192174613b9a627f23f4f8b (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env python
from getopt import getopt
from os.path import basename, dirname, splitext
from sys import argv, stdin, version
from pkg_resources import PathMetadata, Distribution
from distutils.sysconfig import get_python_lib


opts, args = getopt(argv[1:], 'hPRSECO',
        ['help', 'provides', 'requires', 'suggests', 'enhances', 'conflicts', 'obsoletes'])

Provides = False
Requires = False
Suggests = False
Enhances = False
Conflicts = False
Obsoletes = False

for o, a in opts:
    if o in ('-h', '--help'):
        print '-h, --help\tPrint help'
        print '-P, --provides\tPrint Provides'
        print '-R, --requires\tPrint Requires'
        print '-S, --suggests\tPrint Suggests'
        print '-E, --enhances\tPrint Enhances (unused)'
        print '-C, --conflicts\tPrint Conflicts'
        print '-O, --obsoletes\tPrint Obsoletes (unused)'
        exit(1)
    elif o in ('-P', '--provides'):
        Provides = True
    elif o in ('-R', '--requires'):
        Requires = True
    elif o in ('-S', '--suggests'):
        Suggests = True
    elif o in ('-E', '--enhances'):
        Enhances = True
    elif o in ('-C', '--conflicts'):
        Conflicts = True
    elif o in ('-O', '--obsoletes'):
        Obsoletes = True

Version = version[:3]
for f in stdin.readlines():
    f = f.strip()
    # FIXME: get other versions as well...
    if Provides:
        if "/usr/lib/libpython%s.so" % Version in f or \
                "/usr/lib64/libpython%s.so" % Version in f:
                    print "python(abi) == %s" % Version
    if Requires:
        if get_python_lib(plat_specific=1) in f or get_python_lib() in f:
            print "python(abi) >= %s" % Version
    if f.endswith('.egg') or f.endswith('.egg-info') or f.endswith('.egg-link'):
        base_dir = dirname(f)
        metadata = PathMetadata(base_dir, f)
        dist_name = splitext(basename(f))[0]
        dist = Distribution(base_dir,project_name=dist_name,metadata=metadata)
        if Provides:
            print 'pythonegg(%s) = %s' % (dist.project_name, dist.version)
        if Requires or (Suggests and dist.extras):
            deps = dist.requires()
            if Suggests:
                depsextras = dist.requires(extras=dist.extras)
                if not Requires:
                    for dep in reversed(depsextras):
                        if dep in deps:
                            depsextras.remove(dep)
                deps = depsextras
            for dep in deps:
                if not dep.specs:
                    print 'pythonegg(%s)' % dep.project_name
                else:
                    for spec in dep.specs:
                        if spec[0] != '!=':
                            print 'pythonegg(%s) %s' % (dep.project_name, ' '.join(spec))
        if Conflicts:
            # Should we really add conflicts for extras?
            # Creating a meta package per extra with suggests on, which has
            # the requires/conflicts in stead might be a better solution...
            for dep in dist.requires(extras=dist.extras):
                for spec in dep.specs:
                    if spec[0] == '!=':
                        print 'pythonegg(%s) == %s' % (dep.project_name, spec[1])