migrate ignored directories from old config file to new configparser format

This commit is contained in:
Alan Hamlett 2013-12-13 15:30:21 +01:00
parent 256aaf5dc3
commit 1f8f6f8781

View file

@ -69,9 +69,29 @@ def upgradeConfigFile(configFile):
oldConfig = os.path.join(os.path.expanduser('~'), '.wakatime.conf')
try:
with open(oldConfig) as infile:
with open(configFile, 'w') as outfile:
outfile.write("[settings]\n%s" % infile.read().strip())
configs = {
'ignore': [],
}
with open(oldConfig) as fh:
for line in fh.readlines():
line = line.split('=', 1)
if len(line) == 2 and line[0].strip() and line[1].strip():
if line[0].strip() == 'ignore':
configs['ignore'].append(line[1].strip())
else:
configs[line[0].strip()] = line[1].strip()
with open(configFile, 'w') as fh:
fh.write("[settings]\n")
for name, value in configs.items():
if isinstance(value, list):
fh.write("%s=\n" % name)
for item in value:
fh.write(" %s\n" % item)
else:
fh.write("%s = %s\n" % (name, value))
os.remove(oldConfig)
except IOError:
pass