Revision e587b46a lib/utils.py
b/lib/utils.py | ||
---|---|---|
1498 | 1498 |
return result |
1499 | 1499 |
|
1500 | 1500 |
|
1501 |
def ReadOneLineFile(file_name, strict=False): |
|
1502 |
"""Return the first non-empty line from a file. |
|
1503 |
|
|
1504 |
@type strict: boolean |
|
1505 |
@param strict: if True, abort if the file has more than one |
|
1506 |
non-empty line |
|
1507 |
|
|
1508 |
""" |
|
1509 |
file_lines = ReadFile(file_name).splitlines() |
|
1510 |
full_lines = filter(bool, file_lines) |
|
1511 |
if not file_lines or not full_lines: |
|
1512 |
raise errors.GenericError("No data in one-liner file %s" % file_name) |
|
1513 |
elif strict and len(full_lines) > 1: |
|
1514 |
raise errors.GenericError("Too many lines in one-liner file %s" % |
|
1515 |
file_name) |
|
1516 |
return full_lines[0] |
|
1517 |
|
|
1518 |
|
|
1501 | 1519 |
def FirstFree(seq, base=0): |
1502 | 1520 |
"""Returns the first non-existing integer from seq. |
1503 | 1521 |
|
Also available in: Unified diff