artdaq_utilities  v1_02_03a
 All Classes Namespaces Functions Variables Typedefs
parse_product_deps.py
1 #!/bin/env python
2 
3 # JCF, 5/26/15
4 
5 # The purpose of this script is to parse a product_deps file for a
6 # given package, and determine the immediate packages on which is
7 # depends given its qualifier list
8 
9 import sys, os, re
10 
11 if not len(sys.argv) == 5:
12  sys.exit("Usage: " + sys.argv[0] + " <filename> <package> <version> <colon-delimited qualifiers>")
13 
14 
15 def standardize_quals(qualstring):
16  tokens = qualstring.split(":")
17  return ":".join( sorted([ tok for tok in tokens \
18  if tok != "prof" and tok != "debug"]) )
19 
20 filename = sys.argv[1]
21 target_package = sys.argv[2]
22 target_version = sys.argv[3]
23 target_quals = standardize_quals(sys.argv[4])
24 
25 
26 package_version_dict = {}
27 package_column_dict = {}
28 
29 inf = open(filename)
30 
31 in_dependent_list = False
32 in_qualifier_list = False
33 
34 found_quals = False
35 
36 for line in inf.readlines():
37 
38  res = re.search(r"^product[ \t]+version[ \t]+optional", line)
39 
40  if res:
41  in_dependent_list = True
42  continue
43 
44  res = re.search(r"end_product_list", line)
45 
46  if res:
47  in_dependent_list = False
48  continue
49 
50  res = re.search(r"^qualifier[ \t]+", line)
51 
52  if res:
53  in_qualifier_list = True
54  for i, label in enumerate(line.split()):
55  if label != "qualifier" and label != "notes":
56  package_column_dict[label] = i
57  continue
58 
59  res = re.search(r"end_qualifier_list", line)
60 
61  if res:
62  in_qualifier_list = False
63  continue
64 
65  if in_dependent_list:
66 
67  skip_package = False
68 
69  line.lstrip()
70  tokens = line.split()
71 
72  if len(tokens) == 0:
73  continue # Blank line
74 
75  # If the version of a package the target package depends
76  # corresponds to a different qualifier than the target
77  # package's qualifiers, skip the line
78 
79  if len(tokens) > 2:
80  quals = tokens[2].split(":")
81 
82  for qual in quals:
83  if qual != "-" and qual not in target_quals :
84  skip_package = True
85 
86  if skip_package:
87  continue
88 
89  package, version = tokens[0:2]
90 
91  # Since we don't yet know the qualifier set, assign it a "-"
92 
93  if package not in package_version_dict:
94  package_version_dict[ package ] = [version, "-"]
95 
96  continue
97 
98  if in_qualifier_list:
99  tokens = line.split()
100  quals = standardize_quals(tokens[0])
101 
102  # We have the line we want, so now figure out the qualifiers
103  # of the packages on which the target package depends
104 
105  if quals == target_quals:
106 
107  found_quals = True
108 
109  for package, column in package_column_dict.items():
110  if package_version_dict[ package ][1] == "-":
111 
112  # In the qualifier section of the product_deps
113  # file, a "-" means "this package isn't used", a
114  # "-nq-" means "this package IS used, but has no
115  # qualifiers, and anything else is to be taken as
116  # a typical qualifier list
117 
118  possible_quals = standardize_quals( tokens[ package_column_dict[ package ] ] )
119 
120  if possible_quals == "-":
121  del package_version_dict[ package ]
122  elif possible_quals != "-nq-":
123  package_version_dict[ package ][1] = possible_quals
124  break
125 
126 if not found_quals:
127  sys.stderr.write( "Error in parse_product_deps.py: unable to find qualifiers %s in product_deps file %s\n" % (target_quals, filename))
128  sys.exit(1)
129 
130 for package, info in package_version_dict.items():
131  version, qualifier = info
132  print "%s: %s %s" % (package, version, qualifier)
133 
134 
135