| 1 |
#!/usr/bin/python |
|---|
| 2 |
|
|---|
| 3 |
import rpm |
|---|
| 4 |
import os |
|---|
| 5 |
import sys |
|---|
| 6 |
import getopt |
|---|
| 7 |
import commands |
|---|
| 8 |
from rpmUtils.miscutils import stringToVersion |
|---|
| 9 |
|
|---|
| 10 |
DEFAULT_CMP="find $(pwd) -type f" |
|---|
| 11 |
PROV="/tmp/osgi-prov.txt" |
|---|
| 12 |
REQ="/tmp/osgi-req.txt" |
|---|
| 13 |
|
|---|
| 14 |
# this function was take out of rpmdev-vercmp |
|---|
| 15 |
def vercmp((e1, v1, r1), (e2, v2, r2)): |
|---|
| 16 |
rc = rpm.labelCompare((e1, v1, r1), (e2, v2, r2)) |
|---|
| 17 |
return rc |
|---|
| 18 |
|
|---|
| 19 |
def usage(): |
|---|
| 20 |
print "This script check if osgideps.pl RPM deps generator can be activate on a given list of OSGI bundles.\n" |
|---|
| 21 |
print "Usage: osgideps-check [option]" |
|---|
| 22 |
print " -h --help show this help" |
|---|
| 23 |
print " -c --command command that print a list of file to stdin (e.g find /usr/shar/java -type f)" |
|---|
| 24 |
print " -d --debug run from '/tmp/osgi-prov.txt' and '/tmp/osgi-prov.txt' pre-builded file" |
|---|
| 25 |
|
|---|
| 26 |
# parse params |
|---|
| 27 |
cmd = DEFAULT_CMP |
|---|
| 28 |
debug = False |
|---|
| 29 |
try: |
|---|
| 30 |
opts, args = getopt.getopt(sys.argv[1:], "hcd", ["help", "command=", "debug"]) |
|---|
| 31 |
except getopt.GetoptError: |
|---|
| 32 |
usage() |
|---|
| 33 |
sys.exit(2) |
|---|
| 34 |
|
|---|
| 35 |
for opt, arg in opts: |
|---|
| 36 |
if opt in ("-h", "--help"): |
|---|
| 37 |
usage() |
|---|
| 38 |
sys.exit() |
|---|
| 39 |
elif opt in ("-c", "--command"): |
|---|
| 40 |
cmd = arg |
|---|
| 41 |
elif opt in ("-d", "--debug"): |
|---|
| 42 |
debug = True |
|---|
| 43 |
|
|---|
| 44 |
if debug == False: |
|---|
| 45 |
cmd_req = "%s | /usr/lib/rpm/osgideps.pl -r | sort -u > %s" % (cmd, REQ) |
|---|
| 46 |
cmd_prov = "%s | /usr/lib/rpm/osgideps.pl -p | sort -u > %s" % (cmd, PROV) |
|---|
| 47 |
print "Running '%s'..." % cmd_req |
|---|
| 48 |
os.system(cmd_req) |
|---|
| 49 |
print "Running '%s'..." % cmd_prov |
|---|
| 50 |
os.system(cmd_prov) |
|---|
| 51 |
|
|---|
| 52 |
reqs = open(REQ, 'r') |
|---|
| 53 |
for req in reqs: |
|---|
| 54 |
isProv = False |
|---|
| 55 |
reqIsNewerThanProv = False |
|---|
| 56 |
providedBundles = "" |
|---|
| 57 |
provs = open(PROV, 'r') |
|---|
| 58 |
for prov in provs: |
|---|
| 59 |
reqBundle = str(req).strip().split(" ")[0] |
|---|
| 60 |
provBundle = str(prov).strip().split(" ")[0] |
|---|
| 61 |
reqVersion = ""; provVersion = "" |
|---|
| 62 |
if reqBundle == provBundle: |
|---|
| 63 |
# TODO: This assume that provide without version match all requires and vis versa. |
|---|
| 64 |
# (I think that rpm work like that be I'm currently not 100% sure of that) |
|---|
| 65 |
try: |
|---|
| 66 |
reqVersion = str(req).strip().split(" ")[2].strip() |
|---|
| 67 |
provVersion = str(prov).strip().split(" ")[2].strip() |
|---|
| 68 |
reqCmp = str(req).strip().split(" ")[1].strip() |
|---|
| 69 |
provCmp = str(prov).strip().split(" ")[1].strip() |
|---|
| 70 |
(e1, v1, r1) = stringToVersion(provVersion) |
|---|
| 71 |
(e2, v2, r2) = stringToVersion(reqVersion) |
|---|
| 72 |
rc = vercmp((e1, v1, r1), (e2, v2, r2)) |
|---|
| 73 |
# We stricly check version matching here. |
|---|
| 74 |
if (reqCmp == '=' and rc == 0) or (reqCmp == '>=' and rc >= 0): |
|---|
| 75 |
isProv = True |
|---|
| 76 |
exit |
|---|
| 77 |
else: |
|---|
| 78 |
isProv = False |
|---|
| 79 |
providedBundles = str(prov).strip() + " " |
|---|
| 80 |
reqIsNewerThanProv = True |
|---|
| 81 |
except: |
|---|
| 82 |
isProv = True |
|---|
| 83 |
if (reqVersion.strip() != "" and provVersion.strip() != ""): |
|---|
| 84 |
print "ERROR: This script suck for '%s' bundle req:%s - prov:%s" % (reqBundle, reqVersion, provVersion) |
|---|
| 85 |
provs.close() |
|---|
| 86 |
if isProv == False: |
|---|
| 87 |
if reqIsNewerThanProv == True: |
|---|
| 88 |
print "ERROR: req:'%s' '%s' prov:'%s'" % (req.strip(), reqCmp, providedBundles) |
|---|
| 89 |
else: |
|---|
| 90 |
# We check if the osgi bundle is provided by osgi-system-package meta rpm package |
|---|
| 91 |
(status, output) = commands.getstatusoutput("rpm -q --whatprovides '%s' | grep osgi-system-package" % reqBundle) |
|---|
| 92 |
if status != 0: |
|---|
| 93 |
print "ERROR: bundle '%s' not provided" % str(req).strip() |
|---|
| 94 |
reqs.close() |
|---|
| 95 |
|
|---|
| 96 |
|
|---|
| 97 |
|
|---|
| 98 |
|
|---|