| 1545 | |
| 1546 | |
| 1547 | def get_needs(): |
| 1548 | # This function modifies the contents of the global `outneeds` dict. |
| 1549 | res = {} |
| 1550 | for n in outneeds.keys(): |
| 1551 | out = [] |
| 1552 | saveout = copy.copy(outneeds[n]) |
| 1553 | while len(outneeds[n]) > 0: |
| 1554 | if outneeds[n][0] not in needs: |
| 1555 | out.append(outneeds[n][0]) |
| 1556 | del outneeds[n][0] |
| 1557 | else: |
| 1558 | flag = 0 |
| 1559 | for k in outneeds[n][1:]: |
| 1560 | if k in needs[outneeds[n][0]]: |
| 1561 | flag = 1 |
| 1562 | break |
| 1563 | if flag: |
| 1564 | outneeds[n] = outneeds[n][1:] + [outneeds[n][0]] |
| 1565 | else: |
| 1566 | out.append(outneeds[n][0]) |
| 1567 | del outneeds[n][0] |
| 1568 | if saveout and (0 not in map(lambda x, y: x == y, saveout, outneeds[n])) \ |
| 1569 | and outneeds[n] != []: |
| 1570 | print(n, saveout) |
| 1571 | errmess( |
| 1572 | 'get_needs: no progress in sorting needs, probably circular dependence, skipping.\n') |
| 1573 | out = out + saveout |
| 1574 | break |
| 1575 | saveout = copy.copy(outneeds[n]) |
| 1576 | if out == []: |
| 1577 | out = [n] |
| 1578 | res[n] = out |
| 1579 | return res |