aboutsummaryrefslogtreecommitdiffstats
path: root/pythoneggs.py
diff options
context:
space:
mode:
authorPer Øyvind Karlsen <peroyvind@mandriva.org>2010-10-19 02:59:57 +0000
committerPer Øyvind Karlsen <peroyvind@mandriva.org>2010-10-19 02:59:57 +0000
commit08e89dfd301dd7f92e094016a29b13f6a5c5cc6e (patch)
tree232fd9340c9f95cc0780e9ba05074036d2c0aa66 /pythoneggs.py
parentdc4bf782ae27fcdbd981f362d8ff381a47c5c793 (diff)
downloadrpm-setup-08e89dfd301dd7f92e094016a29b13f6a5c5cc6e.tar
rpm-setup-08e89dfd301dd7f92e094016a29b13f6a5c5cc6e.tar.gz
rpm-setup-08e89dfd301dd7f92e094016a29b13f6a5c5cc6e.tar.bz2
rpm-setup-08e89dfd301dd7f92e094016a29b13f6a5c5cc6e.tar.xz
rpm-setup-08e89dfd301dd7f92e094016a29b13f6a5c5cc6e.zip
add pythoneggs() dependency extractor
Diffstat (limited to 'pythoneggs.py')
-rwxr-xr-xpythoneggs.py83
1 files changed, 83 insertions, 0 deletions
diff --git a/pythoneggs.py b/pythoneggs.py
new file mode 100755
index 0000000..b748f60
--- /dev/null
+++ b/pythoneggs.py
@@ -0,0 +1,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])