Skip to content

Commit f574b95

Browse files
authored
Fix linting warnings (sonic-net#84)
1 parent 2df4f40 commit f574b95

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

src/swsssdk/dbconnector.py

+28-28
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
"""
22
Database connection module for SwSS
33
"""
4-
from . import logger
5-
from .interface import DBInterface
64
import os
75
import json
6+
from . import logger
7+
from .interface import DBInterface
88

99
# FIXME: Convert to metaclasses when Py2 support is removed. Metaclasses have unique interfaces to Python2/Python3.
1010

@@ -28,10 +28,10 @@ def load_sonic_global_db_config(global_db_file_path=SONIC_DB_GLOBAL_CONFIG_FILE,
2828
"""
2929
Parse and load the global database config json file
3030
"""
31-
if SonicDBConfig._sonic_db_global_config_init == True:
31+
if SonicDBConfig._sonic_db_global_config_init:
3232
return
3333

34-
if os.path.isfile(global_db_file_path) == True:
34+
if os.path.isfile(global_db_file_path):
3535
global_db_config_dir = os.path.dirname(global_db_file_path)
3636
with open(global_db_file_path, "r") as read_file:
3737
all_ns_dbs = json.load(read_file)
@@ -40,15 +40,15 @@ def load_sonic_global_db_config(global_db_file_path=SONIC_DB_GLOBAL_CONFIG_FILE,
4040
# If the user already invoked load_sonic_db_config() explicitly to load the
4141
# database_config.json file for current namesapce, skip loading the file
4242
# referenced here in the global config file.
43-
if SonicDBConfig._sonic_db_config_init == True:
43+
if SonicDBConfig._sonic_db_config_init:
4444
continue
4545
ns = ''
4646
else:
4747
ns = entry['namespace']
4848

4949
# If API is called with a namespace parameter, load the json file only for that namespace.
50-
if namespace is not None and ns != namespace:
51-
continue;
50+
if namespace is not None and ns != namespace:
51+
continue
5252

5353
# Check if _sonic_db_config already have this namespace present
5454
if ns in SonicDBConfig._sonic_db_config:
@@ -59,23 +59,23 @@ def load_sonic_global_db_config(global_db_file_path=SONIC_DB_GLOBAL_CONFIG_FILE,
5959
db_include_file = os.path.join(global_db_config_dir, entry['include'])
6060

6161
# Not finding the database_config.json file for the namespace
62-
if os.path.isfile(db_include_file) == False:
62+
if not os.path.isfile(db_include_file):
6363
msg = "'{}' file is not found !!".format(db_include_file)
6464
logger.warning(msg)
6565
continue
6666

6767
# As we load the database_config.json file for current namesapce,
6868
# set the _sonic_db_config_init flag to True to prevent loading again
6969
# by the API load_sonic_db_config()
70-
if ns is '':
70+
if not ns:
7171
SonicDBConfig._sonic_db_config_init = True
7272

7373
with open(db_include_file, "r") as inc_file:
7474
SonicDBConfig._sonic_db_config[ns] = json.load(inc_file)
7575

7676
# If API is called with a namespace parameter,we break here as we loaded the json file.
77-
if namespace is not None and ns == namespace:
78-
break;
77+
if namespace is not None and ns == namespace:
78+
break
7979

8080
SonicDBConfig._sonic_db_global_config_init = True
8181

@@ -84,11 +84,11 @@ def load_sonic_db_config(sonic_db_file_path=SONIC_DB_CONFIG_FILE):
8484
"""
8585
Get multiple database config from the database_config.json
8686
"""
87-
if SonicDBConfig._sonic_db_config_init == True:
87+
if SonicDBConfig._sonic_db_config_init:
8888
return
8989

9090
try:
91-
if os.path.isfile(sonic_db_file_path) == False:
91+
if not os.path.isfile(sonic_db_file_path):
9292
msg = "'{}' is not found, it is not expected in production devices!!".format(sonic_db_file_path)
9393
logger.warning(msg)
9494
sonic_db_file_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'config', 'database_config.json')
@@ -110,12 +110,12 @@ def namespace_validation(namespace):
110110
raise RuntimeError(msg)
111111

112112
# Check if the global config is loaded entirely or for the namespace
113-
if namespace != '' and SonicDBConfig._sonic_db_global_config_init == False:
113+
if namespace != '' and not SonicDBConfig._sonic_db_global_config_init:
114114
msg = "Load the global DB config first using API load_sonic_global_db_config"
115115
logger.warning(msg)
116116
raise RuntimeError(msg)
117117

118-
if SonicDBConfig._sonic_db_config_init == False:
118+
if not SonicDBConfig._sonic_db_config_init:
119119
SonicDBConfig.load_sonic_db_config()
120120

121121
if namespace not in SonicDBConfig._sonic_db_config:
@@ -133,10 +133,10 @@ def EMPTY_NAMESPACE(ns):
133133
@staticmethod
134134
def db_name_validation(db_name, namespace=None):
135135
namespace = SonicDBConfig.EMPTY_NAMESPACE(namespace)
136-
if SonicDBConfig._sonic_db_config_init == False:
136+
if not SonicDBConfig._sonic_db_config_init:
137137
SonicDBConfig.load_sonic_db_config()
138138
SonicDBConfig.namespace_validation(namespace)
139-
db=SonicDBConfig._sonic_db_config[namespace]["DATABASES"]
139+
db = SonicDBConfig._sonic_db_config[namespace]["DATABASES"]
140140
if db_name not in db:
141141
msg = "{} is not a valid database name in configuration file".format(db_name)
142142
logger.warning(msg)
@@ -145,7 +145,7 @@ def db_name_validation(db_name, namespace=None):
145145
@staticmethod
146146
def inst_name_validation(inst_name, namespace=None):
147147
namespace = SonicDBConfig.EMPTY_NAMESPACE(namespace)
148-
if SonicDBConfig._sonic_db_config_init == False:
148+
if not SonicDBConfig._sonic_db_config_init:
149149
SonicDBConfig.load_sonic_db_config()
150150
SonicDBConfig.namespace_validation(namespace)
151151
instances = SonicDBConfig._sonic_db_config[namespace]["INSTANCES"]
@@ -157,21 +157,21 @@ def inst_name_validation(inst_name, namespace=None):
157157
@staticmethod
158158
def get_dblist(namespace=None):
159159
namespace = SonicDBConfig.EMPTY_NAMESPACE(namespace)
160-
if SonicDBConfig._sonic_db_config_init == False:
160+
if not SonicDBConfig._sonic_db_config_init:
161161
SonicDBConfig.load_sonic_db_config()
162162
SonicDBConfig.namespace_validation(namespace)
163163
return SonicDBConfig._sonic_db_config[namespace]["DATABASES"].keys()
164164

165165
@staticmethod
166166
def get_ns_list():
167-
if SonicDBConfig._sonic_db_config_init == False:
167+
if not SonicDBConfig._sonic_db_config_init:
168168
SonicDBConfig.load_sonic_db_config()
169169
return SonicDBConfig._sonic_db_config.keys()
170170

171171
@staticmethod
172172
def get_instance(db_name, namespace=None):
173173
namespace = SonicDBConfig.EMPTY_NAMESPACE(namespace)
174-
if SonicDBConfig._sonic_db_config_init == False:
174+
if not SonicDBConfig._sonic_db_config_init:
175175
SonicDBConfig.load_sonic_db_config()
176176
SonicDBConfig.db_name_validation(db_name, namespace)
177177
inst_name = SonicDBConfig._sonic_db_config[namespace]["DATABASES"][db_name]["instance"]
@@ -181,44 +181,44 @@ def get_instance(db_name, namespace=None):
181181
@staticmethod
182182
def get_instancelist(namespace=None):
183183
namespace = SonicDBConfig.EMPTY_NAMESPACE(namespace)
184-
if SonicDBConfig._sonic_db_config_init == False:
184+
if not SonicDBConfig._sonic_db_config_init:
185185
SonicDBConfig.load_sonic_db_config()
186186
SonicDBConfig.namespace_validation(namespace)
187187
return SonicDBConfig._sonic_db_config[namespace]["INSTANCES"]
188188

189189
@staticmethod
190190
def get_socket(db_name, namespace=None):
191191
namespace = SonicDBConfig.EMPTY_NAMESPACE(namespace)
192-
if SonicDBConfig._sonic_db_config_init == False:
192+
if not SonicDBConfig._sonic_db_config_init:
193193
SonicDBConfig.load_sonic_db_config()
194194
return SonicDBConfig.get_instance(db_name, namespace)["unix_socket_path"]
195195

196196
@staticmethod
197197
def get_hostname(db_name, namespace=None):
198198
namespace = SonicDBConfig.EMPTY_NAMESPACE(namespace)
199-
if SonicDBConfig._sonic_db_config_init == False:
199+
if not SonicDBConfig._sonic_db_config_init:
200200
SonicDBConfig.load_sonic_db_config()
201201
return SonicDBConfig.get_instance(db_name, namespace)["hostname"]
202202

203203
@staticmethod
204204
def get_port(db_name, namespace=None):
205205
namespace = SonicDBConfig.EMPTY_NAMESPACE(namespace)
206-
if SonicDBConfig._sonic_db_config_init == False:
206+
if not SonicDBConfig._sonic_db_config_init:
207207
SonicDBConfig.load_sonic_db_config()
208208
return SonicDBConfig.get_instance(db_name, namespace)["port"]
209209

210210
@staticmethod
211211
def get_dbid(db_name, namespace=None):
212212
namespace = SonicDBConfig.EMPTY_NAMESPACE(namespace)
213-
if SonicDBConfig._sonic_db_config_init == False:
213+
if not SonicDBConfig._sonic_db_config_init:
214214
SonicDBConfig.load_sonic_db_config()
215215
SonicDBConfig.db_name_validation(db_name, namespace)
216216
return SonicDBConfig._sonic_db_config[namespace]["DATABASES"][db_name]["id"]
217217

218218
@staticmethod
219219
def get_separator(db_name, namespace=None):
220220
namespace = SonicDBConfig.EMPTY_NAMESPACE(namespace)
221-
if SonicDBConfig._sonic_db_config_init == False:
221+
if not SonicDBConfig._sonic_db_config_init:
222222
SonicDBConfig.load_sonic_db_config()
223223
SonicDBConfig.db_name_validation(db_name, namespace)
224224
return SonicDBConfig._sonic_db_config[namespace]["DATABASES"][db_name]["separator"]
@@ -228,7 +228,7 @@ def __init__(self, use_unix_socket_path=False, namespace=None, **kwargs):
228228
self.dbintf = DBInterface(**kwargs)
229229
self.use_unix_socket_path = use_unix_socket_path
230230

231-
"""If the user don't give the namespace as input, it refers to the local namespace
231+
"""If the user don't give the namespace as input, it refers to the local namespace
232232
where this application is run. (It could be a network namespace or linux host namesapce)
233233
"""
234234
self.namespace = namespace

0 commit comments

Comments
 (0)