Coverage for runmacs/processor/missingdata.py : 20%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# -*- coding: utf-8 -*-
sio.seek(0) for line in sio: log.write(spaces+'(stdout)>> '+line.replace('<', '<').replace('>', '>')) sio.seek(0) sio.truncate(0)
""" Finds product classes which might be used to build a derived product of the product instance ``p``.
:param p: Instance of a product. :returns: Generator over (<component name>, <derived product class>) """ except AttributeError: print "Cannot work on %s"%prototype.canonicalName continue spaces = u' '*logLevel _stdout = sys.stdout try: sio = StringIO.StringIO() sys.stdout = sio missingComponents = [cn for cn in sorted(prototype.componentNames) if cn not in prototype.components] if prototype.building: log.write(spaces+u'missing components are now: %s\r\n'%missingComponents) if len(missingComponents) == 0 or prototype.building == False: log.write(spaces+u'<b>FOUND RESULT:</b> %s\r\n'%prototype.hash) yield prototype else: for componentName in missingComponents: log.write(spaces+'searching for matching %s\r\n'%componentName) try: needed = prototype.whatIsNeeded(componentName) except ValueError: log.write(spaces+'whatIsNeeded failed!\r\n') continue except NeedOtherComponent as e: log.write(spaces+'whatIsNeeded failed (%s)!\r\n'%e) continue query = needed['query'] sort = None limit = None if isinstance(query, tuple): query, queryModifiers = query if 'sortBy' in queryModifiers: sort = queryModifiers['sortBy'] if 'limit' in queryModifiers: limit = queryModifiers['limit'] log.write(spaces+'using query: %s\r\n'%str(query)) log.write(spaces+'limit: %s, sort: %s\r\n'%(str(limit), str(sort))) cn = needed['componentName'] if cn != componentName: log.write(spaces+'missmatched need %s != %s\r\n'%(cn, componentName)) continue if needed['representation'] != 'single': log.write(spaces+'need single representation!\r\n') continue foundSometing = False for prod in accessor.query(query, limit=limit, sort=sort): foundSometing = True flushSIO(sio, log, spaces) for sub in QueryResolutionIterator(prototype, componentName, prod, accessor): flushSIO(sio, log, spaces) log.write(spaces+'found %s\r\n'%sub.canonicalName) for res in self._traceBuild(accessor, p, sub, log, logLevel+1): yield res flushSIO(sio, log, spaces)
if not foundSometing: log.write(spaces+u'no result found for query: %s\r\n'%unicode(query)) except: traceback.print_exc(file=sio) flushSIO(sio,log,spaces) finally: sys.stdout = _stdout
""" Try to build a new product based on der from p, writing actions to log. """ _stdout = sys.stdout try: sio = StringIO.StringIO() sys.stdout = sio componentName, dp = der prototype = dp.build() log.write(u'trying to add base component\r\n') for sub in QueryResolutionIterator(prototype, componentName, p, accessor): flushSIO(sio, log) log.write(u'found %s\r\n'%sub.canonicalName) for res in self._traceBuild(accessor, p, sub, log): yield res flushSIO(sio, log)
except: traceback.print_exc(file=sio) flushSIO(sio, log) finally: sys.stdout = _stdout |