From 9b0a188147e96fa66b5b9bace83a610bf373424c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20=C3=98yvind=20Karlsen?= Date: Wed, 20 Oct 2010 00:45:20 +0000 Subject: improve... --- pythoneggs.py | 132 +++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 103 insertions(+), 29 deletions(-) diff --git a/pythoneggs.py b/pythoneggs.py index b748f60..4cf2245 100755 --- a/pythoneggs.py +++ b/pythoneggs.py @@ -1,20 +1,20 @@ #!/usr/bin/env python from getopt import getopt -from os.path import basename, dirname, splitext +from os.path import basename, dirname, isdir, splitext from sys import argv, stdin, version -from pkg_resources import PathMetadata, Distribution +from pkg_resources import Distribution, FileMetadata, PathMetadata from distutils.sysconfig import get_python_lib -opts, args = getopt(argv[1:], 'hPRSECO', - ['help', 'provides', 'requires', 'suggests', 'enhances', 'conflicts', 'obsoletes']) +opts, args = getopt(argv[1:], 'hPRSCOE', + ['help', 'provides', 'requires', 'suggests', 'conflicts', 'obsoletes', 'extras']) Provides = False Requires = False Suggests = False -Enhances = False Conflicts = False Obsoletes = False +Extras = False for o, a in opts: if o in ('-h', '--help'): @@ -22,9 +22,9 @@ for o, a in opts: 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)' + print '-E, --extras\tPrint Extras ' exit(1) elif o in ('-P', '--provides'): Provides = True @@ -32,32 +32,68 @@ for o, a in opts: 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 + elif o in ('-E', '--extras'): + Extras = True -Version = version[:3] -for f in stdin.readlines(): +if Requires: + py_abi = True +else: + py_abi = False +py_deps = {} +if args: + files = args +else: + files = stdin.readlines() +for f in files: 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 Requires: + # if get_python_lib(plat_specific=1) in f or get_python_lib() in f: + # print 'python(abi) >= %s' % Version + lower = f.lower() + name = 'python(abi)' + if py_abi and lower.endswith('.py'): + if not name in py_deps: + py_deps[name] = [] + if lower.endswith('.egg') or \ + lower.endswith('.egg-info') or \ + lower.endswith('.egg-link'): + dist_name = basename(f) + if isdir(f): + path_item = dirname(f) + metadata = PathMetadata(path_item, f) + else: + path_item = f + metadata = FileMetadata(f) + dist = Distribution.from_location(path_item,dist_name,metadata) if Provides: - print 'pythonegg(%s) = %s' % (dist.project_name, dist.version) + if dist.key == 'python': + name = 'python(abi)' + if not name in py_deps: + py_deps[name] = [] + py_deps[name].append(('==', dist.py_version)) + name = 'pythonegg(%s)' % dist.project_name + if not name in py_deps: + py_deps[name] = [] + if dist.version: + spec = ('==', dist.version) + if not spec in py_deps[name]: + py_deps[name].append(spec) if Requires or (Suggests and dist.extras): + name = 'python(abi)' + if dist.key == 'python': + py_abi = False + if name in py_deps: + py_deps.pop(name) + elif py_abi and dist.py_version: + if not name in py_deps: + py_deps[name] = [] + spec = ('>=', dist.py_version) + if not spec in py_deps[name]: + py_deps[name].append(spec) deps = dist.requires() if Suggests: depsextras = dist.requires(extras=dist.extras) @@ -67,17 +103,55 @@ for f in stdin.readlines(): depsextras.remove(dep) deps = depsextras for dep in deps: + name = 'pythonegg(%s)' % dep.project_name + for spec in dep.specs: + if spec[0] != '!=': + if not name in py_deps: + py_deps[name] = [] + if not spec in py_deps[name]: + py_deps[name].append(spec) if not dep.specs: - print 'pythonegg(%s)' % dep.project_name - else: + py_deps[name] = [] + if Extras: + deps = dist.requires() + extras = dist.extras + print extras + for extra in extras: + print '%%package\textras-%s' % extra + print 'Summary:\t%s extra for %s python egg' % (extra, dist.project_name) + print 'Group:\t\tDevelopment/Python' + depsextras = dist.requires(extras=[extra]) + for dep in reversed(depsextras): + if dep in deps: + depsextras.remove(dep) + deps = depsextras + for dep in deps: for spec in dep.specs: - if spec[0] != '!=': - print 'pythonegg(%s) %s' % (dep.project_name, ' '.join(spec)) + if spec[0] == '!=': + print 'Conflicts:\t%s %s %s' % (dep.project_name, '==', spec[1]) + else: + print 'Requires:\t%s %s %s' % (dep.project_name, spec[0], spec[1]) + print '%%description\t%s' % extra + print '%s extra for %s python egg' % (extra, dist.project_name) + print '%%files\t\textras-%s\n' % extra 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): + name = dep.project_name for spec in dep.specs: if spec[0] == '!=': - print 'pythonegg(%s) == %s' % (dep.project_name, spec[1]) + if not name in py_deps: + py_deps[name] = [] + spec = ('==', spec[1]) + if not spec in py_deps[name]: + py_deps[name].append(spec) +names = py_deps.keys() +names.sort() +for name in names: + if py_deps[name]: + for spec in py_deps[name]: + print '%s %s %s' % (name, spec[0], spec[1]) + else: + print name -- cgit v1.2.1