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