Skip to content
Snippets Groups Projects
Commit e44dd3b4 authored by Alexandre Savard's avatar Alexandre Savard
Browse files

[#4116] Make account enabled by default ini migration script (IP2IP account)

parent 4381c0fe
Branches
Tags
No related merge requests found
...@@ -2,16 +2,16 @@ import os ...@@ -2,16 +2,16 @@ import os
import yaml import yaml
from ConfigParser import ConfigParser as cp from ConfigParser import ConfigParser as cp
# path = os.environ['HOME'] + "/.config/sflphone/sflphonedrc" path = os.environ['HOME'] + "/.config/sflphone/sflphonedrc"
path = "sflphonedrc" # path = "sflphonedrc"
c = cp() c = cp()
c.read(path) c.read(path)
accnodes = ['srtp', 'tls', 'zrtp'] accnodes = ['srtp', 'tls', 'zrtp']
auxnodes = ['alsa', 'pulse', 'dtmf'] auxnodes = ['alsa', 'pulse', 'dtmf']
dico = {} dico = {}
dico['Accounts'] = [] dico['accounts'] = []
# Dictionary used to convert string used in prior configuration file to new one.
conversion = { conversion = {
# addressbook # addressbook
...@@ -69,6 +69,7 @@ conversion = { ...@@ -69,6 +69,7 @@ conversion = {
'zidfile': 'zidFile', 'zidfile': 'zidFile',
# account # account
'accounts': 'accounts',
'ip2ip': 'IP2IP', 'ip2ip': 'IP2IP',
'alias': 'alias', 'alias': 'alias',
'displayname': 'displayName', 'displayname': 'displayName',
...@@ -109,64 +110,85 @@ conversion = { ...@@ -109,64 +110,85 @@ conversion = {
# to be removed # to be removed
'listenerport': 'port', 'listenerport': 'port',
} }
# parcourt des sections du fichier d'origine
# Dictionary to convert sections string
section_conversion = {
'Accounts': 'accounts',
'Addressbook': 'addressbook',
'Audio': 'audio',
'Hooks': 'hooks',
'Preferences': 'preferences',
'VoIPLink': 'voipPreferences',
'Shortcuts': 'shortcuts'
}
# run over every sections in original file
for sec in c.sections(): for sec in c.sections():
# les comptes sont maintenant dans une liste de comptes # accounts are now stored in an account list
if 'Account' in sec or sec == 'IP2IP': if 'Account' in sec or sec == 'IP2IP':
dsec = 'Accounts' dsec = 'accounts'
# dict temporaire pour insertion ulterieure des comptes dans le dictionnaire # temporary account dictionary to be inserted in main dictionary
daccount = {} daccount = {}
daccount['id'] = sec daccount['id'] = sec
# dict temporaire pour insertion ulterieure des nodes dans le compte # temporary account dictionary to be inserted in account nodes
subdic = {} subdic = {}
# preparation du dictionnaire pour les nodes du compte # preparing account dictionary
for x in accnodes: for x in accnodes:
subdic[x] = {} subdic[x] = {}
# parcourt des options # run over every options
for opt in c.options(sec): for opt in c.options(sec):
spl = opt.split('.') spl = opt.split('.')
# si nous avons affaire a un node # if this is an account node
if spl[0] in accnodes: if spl[0] in accnodes:
# on ajoute dans le sous dict du compte # add into the account dictionary
print spl[1] print spl[1]
subdic[spl[0]][conversion[spl[1]]] = c.get(sec, opt) subdic[spl[0]][conversion[spl[1]]] = c.get(sec, opt)
# sinon l'option est attachee au compte # else, the options is attached to the primary dictionary
else: else:
daccount[spl[len(spl) -1]] = c.get(sec, opt) daccount[spl[len(spl) -1]] = c.get(sec, opt)
# insertion des nodes dans le compte # insert account nodes in account dictionary
for x in accnodes: for x in accnodes:
daccount[x] = subdic[x] daccount[x] = subdic[x]
#insertion du compte dans le dictionnaire principal # insert account dictionary in main dictionary
dico[dsec].append(daccount) dico[dsec].append(daccount)
else: else:
dsec = sec dsec = section_conversion[sec]
dico[dsec] = {} dico[dsec] = {}
#print dsec
#for opt in c.options(sec):
# dico[dsec][opt] = c.get(sec, opt)
# print opt
subdic = {} subdic = {}
# preparation du dictionnaire pour les nodes de la section # prepare dictionary for section's node
for x in auxnodes: for x in auxnodes:
subdic[x] = {} subdic[x] = {}
# parcourt des options # run over all fields
for opt in c.options(sec): for opt in c.options(sec):
spl = opt.split('.') spl = opt.split('.')
# si nous avons affaire a un node # if this is a node
if spl[0] in auxnodes: if spl[0] in auxnodes:
# on ajoute dans le sous dict du compte # add into sections dictionary
print spl[1] print spl[1]
subdic[spl[0]][conversion[spl[1]]] = c.get(sec, opt) subdic[spl[0]][conversion[spl[1]]] = c.get(sec, opt)
# sinon l'option est attachee au compte # else if this option is attached to an accout
else: else:
dico[sec][spl[len(spl) -1 ]] = c.get(sec, opt) dico[section_conversion[sec]][spl[len(spl) -1 ]] = c.get(sec, opt)
# insertion des nodes dans le compte # inserting the node into the account
for x in auxnodes: for x in auxnodes:
if subdic[x]: if subdic[x]:
dico[sec][x] = subdic[x] dico[section_conversion[sec]][x] = subdic[x]
# Make sure all accunt are enabled (especially IP2IP)
for acc in dico['accounts']:
acc['enable'] = 'true'
# Save in new configuration file
newPath = os.environ['HOME'] + "/.config/sflphone/sflphonedrc"
# newPath = 'blah.yml'
f = open('blah.yml', 'wr') # Save new configuration file
f = open(newPath, 'wr')
f.write(yaml.dump(dico, default_flow_style=False)) f.write(yaml.dump(dico, default_flow_style=False))
f.close() f.close()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment