| Conditions | 7 | 
| Total Lines | 22 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 1 | ||
| Bugs | 0 | Features | 0 | 
| 1 | #!/usr/bin/python | ||
| 9 | def pfind(path, fname): | ||
| 10 | """Find fname in the closest ancestor directory. | ||
| 11 | For the purposes of this function, we are our own closest ancestor. | ||
| 12 | """ | ||
| 13 | |||
| 14 | wd = os.path.abspath(path) | ||
| 15 | assert os.path.isdir(wd) | ||
| 16 | |||
| 17 | def parents(): | ||
| 18 | parent = wd | ||
| 19 | yield parent | ||
| 20 | while 1: | ||
| 21 | parent, dirname = os.path.split(parent) | ||
| 22 | if not dirname: | ||
| 23 | return | ||
| 24 | yield parent | ||
| 25 | |||
| 26 | for d in parents(): | ||
| 27 | if fname in os.listdir(d): | ||
| 28 | return os.path.join(d, fname) | ||
| 29 | |||
| 30 | return None | ||
| 31 | |||
| 36 |