1+ import os
12from flask import Flask , request , render_template_string
23import requests
3- import os
4- import configparser
54import click
5+ from tools .confighelper import DectWIPConfig
66
7- dect_wip_ip = os .getenv ('DECT_WIP_URL' , '127.0.0.1:8080' )
8- port = int (os .getenv ('DECT_WIP_PHONEBOOK_PORT' , '8082' ))
97app = Flask (__name__ )
10- config = configparser .ConfigParser ()
118
129xsi_template = """<?xml version="1.0" encoding="UTF-8"?>
1310<Personal xmlns="http://schema.broadsoft.com/xsi">
@@ -27,7 +24,7 @@ def return_phonebook(caller):
2724 search_index = int (search_index )- 1 # let search_index start at 0 not 1
2825 search_results_count = int (request .args .get ('results' ))
2926
30- if always_search_with_contains :
27+ if config . mitelphonebook_always_search_with_contains :
3128 if not search_string .startswith ('*' ):
3229 print (f'config.ini phonebook always_search_with_contains is true --> converting { search_string } to *{ search_string } ' )
3330 search_string = f'*{ search_string } '
@@ -38,9 +35,9 @@ def return_phonebook(caller):
3835 search_string = search_string .replace ('*' ,'%' )
3936
4037 if search_string == '' :
41- names_and_extensions = requests .get (f"http://{ dect_wip_ip } /api/v1/phonebook" ).json ()
38+ names_and_extensions = requests .get (f"http://{ config . dect_wip_internal_ip } : { config . dect_wip_port } /api/v1/phonebook" ).json ()
4239 else :
43- names_and_extensions = requests .get (f"http://{ dect_wip_ip } /api/v1/phonebook?search={ search_string } " ).json ()
40+ names_and_extensions = requests .get (f"http://{ config . dect_wip_internal_ip } : { config . dect_wip_port } /api/v1/phonebook?search={ search_string } " ).json ()
4441
4542 print (f"{ caller } searched for { search_string } , index={ search_index } , results_count={ search_results_count } " )
4643
@@ -55,21 +52,18 @@ def init(config_path):
5552
5653 # setup global config
5754
58- global always_search_with_contains
55+ global config
5956
60- config .read (config_path )
61- always_search_with_contains = config .getboolean ('phonebook' , 'always_search_with_contains' )
57+ config = DectWIPConfig (config_path = config_path )
6258
6359@click .command ()
64- @click .option ('--config' , 'config_path' , envvar = 'CONFIG ' , default = '/etc/dect-wip.ini' , help = 'optional config location' )
60+ @click .option ('--config' , 'config_path' , envvar = 'CONFIG_PATH ' , default = '/etc/dect-wip.ini' , help = 'optional config location' )
6561def init_dev (config_path ):
66- # TODO: refactor config.ini and ENV
6762 init (config_path )
68- app .run (host = '0.0.0.0' , port = port , debug = False , use_reloader = True )
63+ app .run (host = config . mitelphonebook_listen_ip , port = config . mitelphonebook_port , debug = False , use_reloader = True )
6964
7065def init_wsgi ():
71- config_path = os .getenv ('CONFIG' , '/etc/dect-wip.ini' )
72- init (config_path )
66+ init (os .environ .get ('CONFIG_PATH' , '/etc/dect-wip.ini' ))
7367 return app
7468
7569if __name__ == '__main__' :
0 commit comments