generate-manifest.py
Go to the documentation of this file.
1 import pandas as pd
2 from io import StringIO
3 import re,sys,getopt
4 
5 sl7_only_packages=('caendigitizer','pqxx','epics','jsoncpp','redis','zmq')
6 
8  def __init__(self, name):
9  self.name=name
10 
11 
12  def read(self, header,trailer, usecols=None):
13  lines=StringIO()
14  with open(self.name) as input_data:
15  for line in input_data:
16  if line.strip().startswith(header):
17  break
18  lines.write(line)
19 
20  for line in input_data:
21  if line.strip().startswith(trailer):
22  break
23  lines.write(line)
24 
25  lines.seek(0)
26 
27  return pd.read_csv(lines, delimiter=r"\s+",usecols=usecols)
28 
29 
30  def read_qualifiers(self):
31  return self.read('qualifier','end_qualifier_list')
32 
33 
34  def read_products(self):
35  return self.read('product','end_product_list',range(3))
36 
37 
38 class Product:
39  def __init__(self,product,qualifiers):
40  self.product=product
41  self.qualifiers=qualifiers
42 
43  def manifest_entry(self):
44  name=self.product[0]
45  version=self.product[1]
46  optional=self.product[2]
47 
48  qualifiers=self.qualifiers.split(':')
49  rqual=list(filter(re.compile(r'(e[0-9]{2}|c[0-9]{1})').search , qualifiers))
50  bqual=list(filter(re.compile(r'(debug|prof)').search , qualifiers))
51  aqual=list(filter(re.compile(r'(noarch|slf7-x86_64)').search , qualifiers))
52 
53  arch='slf7-x86_64' if not aqual else aqual[0]
54 
55  if name in sl7_only_packages and arch.startswith('slf'):
56  arch=arch.replace('slf','sl')
57 
58  tarball='{0:s}-{1:s}-{2:s}'.format(name,version.replace('_', '.').replace('v','') ,arch)
59 
60  if rqual:
61  tarball += '-{0:s}'.format(rqual[0])
62  if bqual:
63  tarball += '-{0:s}'.format(bqual[0])
64 
65  tarball +='.tar.bz2'
66  entry = '{0:20s} {1:10s} {2:70s}'.format(name,version,tarball)
67  entry += ' -f {0:20s}'.format('Linux64bit+3.10-2.17' if arch == 'slf7-x86_64' else 'NULL')
68 
69  if self.qualifiers !='-nq-' and self.qualifiers != '-' and self.qualifiers != 'noarch':
70  entry += ' -q {0:20s}'.format(self.qualifiers)
71 
72  entry += '\n'
73 
74  return entry
75 
76 
77 
79  def __init__(self,name,qualifiers):
80  self.name=name
81  self.qualifiers=qualifiers
82  self.df_products=ProductDepsReader(self.name).read_products()
83  self.df_qualifiers=ProductDepsReader(self.name).read_qualifiers()
84  self.manifest=StringIO()
85 
86 
88  for index, row in self.df_qualifiers.iterrows():
89  if row[0] == self.qualifiers:
90  return row
91 
92  candidate=row[0].split(':')
93  reference=self.qualifiers.split(':')
94  if len(candidate) != len(reference):
95  continue
96 
97  if set(candidate) == set(reference):
98  return row
99 
100 
101  def build_manifest(self):
102  manifest=StringIO()
103  product_qualifiers=self.match_product_qualifiers()
104 
105  for index,product in self.df_products.iterrows():
106  qualifiers='noarch' if product[0] not in product_qualifiers else product_qualifiers[product[0]]
107  product=Product(product,qualifiers)
108  manifest.write(product.manifest_entry())
109 
110  manifest.seek(0)
111 
112  return manifest
113 
114 
115 def main(argv):
116  product_deps_file = 'product_deps'
117  manifest_file = 'manifest.txt'
118  qualifiers=None
119 
120  try:
121  opts, args = getopt.getopt(argv,"hp:m:q:",["product_deps=","manifest=","qualifiers="])
122  except getopt.GetoptError:
123  print('generate-manifest.py -p <product_deps> -p <manifest> -q <qualifiers>')
124  sys.exit(2)
125 
126  for opt, arg in opts:
127  if opt == '-h':
128  print('generate-manifest.py -p <product_deps> -m <manifest> -q <qualifiers>')
129  sys.exit()
130  elif opt in ("-p", "--product_deps"):
131  product_deps_file = arg
132  elif opt in ("-m", "--manifest"):
133  manifest_file = arg
134  elif opt in ("-q", "--qualifiers"):
135  qualifiers = arg
136 
137  builder = ManifestBuilder(product_deps_file,qualifiers)
138  manifest = builder.build_manifest()
139 
140  with open(manifest_file, mode='w') as f:
141  print(manifest.getvalue().strip(), file=f)
142 
143 if __name__ == "__main__":
144  main(sys.argv[1:])
145 
146 
147 
148 
def __init__(self, product, qualifiers)
def __init__(self, name, qualifiers)
int open(const char *, int)
Opens a file descriptor.
static bool format(QChar::Decomposition tag, QString &str, int index, int len)
Definition: qstring.cpp:11496
def read(self, header, trailer, usecols=None)
void split(std::string const &s, char c, OutIter dest)
Definition: split.h:35