00001
00002
00003
00004
00005
00006
00007
00008
00009 import sys, os, re
00010
00011 if not len(sys.argv) == 5:
00012 sys.exit("Usage: " + sys.argv[0] + " <filename> <package> <version> <colon-delimited qualifiers>")
00013
00014
00015 def standardize_quals(qualstring):
00016 tokens = qualstring.split(":")
00017 return ":".join( sorted([ tok for tok in tokens \
00018 if tok != "prof" and tok != "debug"]) )
00019
00020 filename = sys.argv[1]
00021 target_package = sys.argv[2]
00022 target_version = sys.argv[3]
00023 target_quals = standardize_quals(sys.argv[4])
00024
00025
00026 package_version_dict = {}
00027 package_column_dict = {}
00028
00029 inf = open(filename)
00030
00031 in_dependent_list = False
00032 in_qualifier_list = False
00033
00034 found_quals = False
00035
00036 for line in inf.readlines():
00037
00038 res = re.search(r"^product[ \t]+version[ \t]+optional", line)
00039
00040 if res:
00041 in_dependent_list = True
00042 continue
00043
00044 res = re.search(r"end_product_list", line)
00045
00046 if res:
00047 in_dependent_list = False
00048 continue
00049
00050 res = re.search(r"^qualifier[ \t]+", line)
00051
00052 if res:
00053 in_qualifier_list = True
00054 for i, label in enumerate(line.split()):
00055 if label != "qualifier" and label != "notes":
00056 package_column_dict[label] = i
00057 continue
00058
00059 res = re.search(r"end_qualifier_list", line)
00060
00061 if res:
00062 in_qualifier_list = False
00063 continue
00064
00065 if in_dependent_list:
00066
00067 skip_package = False
00068
00069 line.lstrip()
00070 tokens = line.split()
00071
00072 if len(tokens) == 0:
00073 continue
00074
00075
00076
00077
00078
00079 if len(tokens) > 2:
00080 quals = tokens[2].split(":")
00081
00082 for qual in quals:
00083 if qual != "-" and qual not in target_quals :
00084 skip_package = True
00085
00086 if skip_package:
00087 continue
00088
00089 package, version = tokens[0:2]
00090
00091
00092
00093 if package not in package_version_dict:
00094 package_version_dict[ package ] = [version, "-"]
00095
00096 continue
00097
00098 if in_qualifier_list:
00099 tokens = line.split()
00100 quals = standardize_quals(tokens[0])
00101
00102
00103
00104
00105 if quals == target_quals:
00106
00107 found_quals = True
00108
00109 for package, column in package_column_dict.items():
00110 if package_version_dict[ package ][1] == "-":
00111
00112
00113
00114
00115
00116
00117
00118 possible_quals = standardize_quals( tokens[ package_column_dict[ package ] ] )
00119
00120 if possible_quals == "-":
00121 del package_version_dict[ package ]
00122 elif possible_quals != "-nq-":
00123 package_version_dict[ package ][1] = possible_quals
00124 break
00125
00126 if not found_quals:
00127 sys.stderr.write( "Error in parse_product_deps.py: unable to find qualifiers %s in product_deps file %s\n" % (target_quals, filename))
00128 sys.exit(1)
00129
00130 for package, info in package_version_dict.items():
00131 version, qualifier = info
00132 print "%s: %s %s" % (package, version, qualifier)
00133
00134
00135