Commit c74ecf34 authored by Guillaume Seguin's avatar Guillaume Seguin

Fix #504: save config to rc_filename + "~new" and copy it on success

parent 2b00ea6a
...@@ -20,6 +20,7 @@ import glob ...@@ -20,6 +20,7 @@ import glob
import os import os
import time import time
import sys import sys
import shutil
import subprocess import subprocess
import codecs import codecs
import argparse import argparse
...@@ -932,10 +933,9 @@ class pronsole(cmd.Cmd): ...@@ -932,10 +933,9 @@ class pronsole(cmd.Cmd):
try: try:
written = False written = False
if os.path.exists(self.rc_filename): if os.path.exists(self.rc_filename):
import shutil
shutil.copy(self.rc_filename, self.rc_filename + "~bak") shutil.copy(self.rc_filename, self.rc_filename + "~bak")
rci = codecs.open(self.rc_filename + "~bak", "r", "utf-8") rci = codecs.open(self.rc_filename + "~bak", "r", "utf-8")
rco = codecs.open(self.rc_filename, "w", "utf-8") rco = codecs.open(self.rc_filename + "~new", "w", "utf-8")
if rci is not None: if rci is not None:
overwriting = False overwriting = False
for rc_cmd in rci: for rc_cmd in rci:
...@@ -956,6 +956,7 @@ class pronsole(cmd.Cmd): ...@@ -956,6 +956,7 @@ class pronsole(cmd.Cmd):
if rci is not None: if rci is not None:
rci.close() rci.close()
rco.close() rco.close()
shutil.move(self.rc_filename + "~new", self.rc_filename)
# if definition != "": # if definition != "":
# self.log("Saved '"+key+"' to '"+self.rc_filename+"'") # self.log("Saved '"+key+"' to '"+self.rc_filename+"'")
# else: # else:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment