[Pkg-bazaar-commits] ./bzr/unstable r779: - better quotefn for windows: use doublequotes for strings with
Martin Pool
mbp at sourcefrog.net
Fri Apr 10 08:20:59 UTC 2009
------------------------------------------------------------
revno: 779
committer: Martin Pool <mbp at sourcefrog.net>
timestamp: Fri 2005-06-24 21:04:55 +1000
message:
- better quotefn for windows: use doublequotes for strings with
strange characters, not backslashes
- new backup_file() routine
modified:
bzrlib/osutils.py
-------------- next part --------------
=== modified file 'bzrlib/osutils.py'
--- a/bzrlib/osutils.py 2005-06-24 04:48:14 +0000
+++ b/bzrlib/osutils.py 2005-06-24 11:04:55 +0000
@@ -39,12 +39,15 @@
_QUOTE_RE = re.compile(r'([^a-zA-Z0-9.,:/_~-])')
def quotefn(f):
- """Return shell-quoted filename"""
- ## We could be a bit more terse by using double-quotes etc
- f = _QUOTE_RE.sub(r'\\\1', f)
- if f[0] == '~':
- f[0:1] = r'\~'
- return f
+ """Return a quoted filename filename
+
+ This previously used backslash quoting, but that works poorly on
+ Windows."""
+ # TODO: I'm not really sure this is the best format either.x
+ if _QUOTE_RE.search(f):
+ return '"' + f + '"'
+ else:
+ return f
def file_kind(f):
@@ -71,6 +74,33 @@
+def backup_file(fn):
+ """Copy a file to a backup.
+
+ Backups are named in GNU-style, with a ~ suffix.
+
+ If the file is already a backup, it's not copied.
+ """
+ import os
+ if fn[-1] == '~':
+ return
+ bfn = fn + '~'
+
+ inf = file(fn, 'rb')
+ try:
+ content = inf.read()
+ finally:
+ inf.close()
+
+ outf = file(bfn, 'wb')
+ try:
+ outf.write(content)
+ finally:
+ outf.close()
+
+
+
+
def isdir(f):
"""True if f is an accessible directory."""
try:
More information about the Pkg-bazaar-commits
mailing list