Revision d0c8c01d lib/utils/io.py
b/lib/utils/io.py | ||
---|---|---|
362 | 362 |
(os.path.basename(file_name), TimestampForFilename())) |
363 | 363 |
dir_name = os.path.dirname(file_name) |
364 | 364 |
|
365 |
fsrc = open(file_name, 'rb')
|
|
365 |
fsrc = open(file_name, "rb")
|
|
366 | 366 |
try: |
367 | 367 |
(fd, backup_name) = tempfile.mkstemp(prefix=prefix, dir=dir_name) |
368 |
fdst = os.fdopen(fd, 'wb')
|
|
368 |
fdst = os.fdopen(fd, "wb")
|
|
369 | 369 |
try: |
370 | 370 |
logging.debug("Backing up %s at %s", file_name, backup_name) |
371 | 371 |
shutil.copyfileobj(fsrc, fdst) |
... | ... | |
632 | 632 |
key_fields = key.split() |
633 | 633 |
|
634 | 634 |
if isinstance(file_obj, basestring): |
635 |
f = open(file_obj, 'a+')
|
|
635 |
f = open(file_obj, "a+")
|
|
636 | 636 |
else: |
637 | 637 |
f = file_obj |
638 | 638 |
|
... | ... | |
642 | 642 |
# Ignore whitespace changes |
643 | 643 |
if line.split() == key_fields: |
644 | 644 |
break |
645 |
nl = line.endswith('\n')
|
|
645 |
nl = line.endswith("\n")
|
|
646 | 646 |
else: |
647 | 647 |
if not nl: |
648 | 648 |
f.write("\n") |
649 |
f.write(key.rstrip('\r\n'))
|
|
649 |
f.write(key.rstrip("\r\n"))
|
|
650 | 650 |
f.write("\n") |
651 | 651 |
f.flush() |
652 | 652 |
finally: |
... | ... | |
666 | 666 |
|
667 | 667 |
fd, tmpname = tempfile.mkstemp(dir=os.path.dirname(file_name)) |
668 | 668 |
try: |
669 |
out = os.fdopen(fd, 'w')
|
|
669 |
out = os.fdopen(fd, "w")
|
|
670 | 670 |
try: |
671 |
f = open(file_name, 'r')
|
|
671 |
f = open(file_name, "r")
|
|
672 | 672 |
try: |
673 | 673 |
for line in f: |
674 | 674 |
# Ignore whitespace changes while comparing lines |
Also available in: Unified diff