Permalink
Browse files

Merge pull request #2 from bbeirut/master

Works on 3.4.3
  • Loading branch information...
2 parents e9ae5d9 + 2c0fa99 commit c5b2c197b966948a3565a896b2cea1b54a5bf6c5 @flying-sheep committed Sep 2, 2015
Showing with 11 additions and 3 deletions.
  1. +11 −3 reindent.py
View
@@ -100,9 +100,17 @@ def check(file, options=parser.parse_args([])):
else:
if options.backup:
bak = file + '.bak'
+ # do not overwrite another backup file
+ if os.path.exists(bak):
+ n = 1
+ bak += str(n)
+ while os.path.exists(bak):
+ bak = '{}{}'.format(bak[:-1], n)
+ n += 1
+
copyfile(file, bak)
logging.info('backed up %s to %s.', file, bak)
- with open(file, encoding=encoding) as f:
+ with open(file, 'w', encoding=encoding) as f:
indenter.write(f)
logging.info('wrote new %s.', file)
return True
@@ -143,7 +151,7 @@ def __call__(self):
self.after.append(line)
sym = '×' if l == lineno - 1 else ' '
- logging.debug("{}{:3} {:31} |{!r}".format(sym, l, stat, line))
+ logging.debug("{}{:3} {!r:31} |{}".format(sym, l, stat, line))
last_stat_on = l+1
@@ -205,4 +213,4 @@ def parse_tokens(self, tokens):
yield (lineno, indent)
if __name__ == '__main__':
- main(sys.argv[1:])
+ main(sys.argv[1:])

0 comments on commit c5b2c19

Please sign in to comment.