svn-safe-append.py
28 lines
| 562 B
| text/x-python
|
PythonLexer
/ tests / svn-safe-append.py
|
r6439 | #!/usr/bin/env python | ||
|
r29195 | from __future__ import absolute_import | ||
|
r6439 | __doc__ = """Same as `echo a >> b`, but ensures a changed mtime of b. | ||
Without this svn will not detect workspace changes.""" | ||||
|
r29195 | import os | ||
|
r36799 | import stat | ||
|
r29195 | import sys | ||
|
r6439 | |||
text = sys.argv[1] | ||||
fname = sys.argv[2] | ||||
f = open(fname, "ab") | ||||
try: | ||||
|
r36799 | before = os.fstat(f.fileno())[stat.ST_MTIME] | ||
|
r6439 | f.write(text) | ||
f.write("\n") | ||||
finally: | ||||
f.close() | ||||
inc = 1 | ||||
|
r36799 | now = os.stat(fname)[stat.ST_MTIME] | ||
|
r6439 | while now == before: | ||
t = now + inc | ||||
inc += 1 | ||||
os.utime(fname, (t, t)) | ||||
|
r36799 | now = os.stat(fname)[stat.ST_MTIME] | ||