def json_PlaneShift_transform_predicate(*args, **kwargs):
return True
def json_PlaneShift_transform_action(raw_crash, processor):
"""a TransformRule action function that will change the buildid of a
product.
parameters:
json_doc - the destination mapping for the rewrite
processor - a source for a logger, caching and a database connection"""
if not hasattr(processor, 'builddate_cache'):
# not very thread safe...
processor.builddate_cache = {}
try:
build_date = processor.builddate_cache[(
raw_crash['ProductName'],
raw_crash['Version']
)]
except KeyError:
try:
processor.config.logger.debug('DEBUG: product %s version %s',raw_crash['ProductName'], raw_crash['Version'])
sql = (
"select build_id "
"from product_version_builds b, product_versions v "
"where b.product_version_id=v.product_version_id and "
"product_name = %s and version_string = %s"
)
product_version_tuple = (
raw_crash['ProductName'],
raw_crash['Version']
)
build_date = processor.transaction(
single_value_sql,
sql,
(raw_crash['ProductName'],raw_crash['Version'])
)
processor.builddate_cache[product_version_tuple] = build_date
except Exception:
processor.config.logger.error(
'cannot fetch build_date for %s %s',
raw_crash['ProductName'],
raw_crash['Version'],
)
return False
raw_crash['BuildID'] = str(build_date)
processor.config.logger.debug(
'BuildID changed to %s',
build_date,
)
return True