(filename)
| 30 | |
| 31 | |
| 32 | def create_unique_file(filename): |
| 33 | version = 0 |
| 34 | result_file = filename |
| 35 | # if we have to try more than 1000 times, something is seriously wrong |
| 36 | while os.path.exists(result_file) and version < 1000: |
| 37 | result_file = filename + '.' + str(version) |
| 38 | version += 1 |
| 39 | if version >= 1000: |
| 40 | raise OSError('cannot create unique file %s.[0-1000]' % filename) |
| 41 | return result_file |
| 42 | |
| 43 | |
| 44 | @contextmanager |
no outgoing calls