Skip to content

Commit b04a95c

Browse files
committed
changing configparser get method
1 parent 5c3db91 commit b04a95c

File tree

6 files changed

+16
-11
lines changed

6 files changed

+16
-11
lines changed

build renamed to docker_build

File renamed without changes.

lib/jnpr/jsnapy/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
from .version import __version__
22
from jnpr.jsnapy.jsnapy import SnapAdmin
3+
4+

lib/jnpr/jsnapy/check.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def generate_snap_file(self, device, prefix, cmd_rpc_name, reply_format):
2727
return prefix
2828
else:
2929
file = str(device) + '_' + prefix + '_' + cmd_rpc_name + '.' + reply_format
30-
snapfile = os.path.join((self.config['DEFAULT'].get('snapshot_path', '/etc/jsnapy/snapshots')).encode('utf-8'), file)
30+
snapfile = os.path.join((self.config.get('DEFAULT', 'snapshot_path', vars={'snapshot_path': '/etc/jsnapy/snapshots'})).encode('utf-8'), file)
3131
return snapfile
3232

3333
def get_err_mssg(self, path, ele_list):
@@ -251,7 +251,7 @@ def generate_test_files(
251251
"\nNo test file, Please mention test files !!")
252252
else:
253253
for tfiles in main_file.get('tests'):
254-
filename = os.path.join((self.config['DEFAULT'].get('test_file_path', '/etc/jsnapy/testfiles')).encode('utf-8'), tfiles)
254+
filename = os.path.join((self.config.get('DEFAULT', 'test_file_path', vars={'test_file_path':'/etc/jsnapy/testfiles'})).encode('utf-8'), tfiles)
255255
if os.path.isfile(filename):
256256
testfile = open(filename, 'r')
257257
tfiles = yaml.load(testfile)

lib/jnpr/jsnapy/jsnapy.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,9 @@ def get_hosts(self):
182182
if os.path.isfile(conf_file):
183183
config_file = open(conf_file, 'r')
184184
self.main_file = yaml.load(config_file)
185-
elif os.path.isfile(os.path.join((self.config['DEFAULT'].get('config_file_path','/etc/jsnapy')).encode('utf-8') , conf_file)):
186-
fpath= (self.config['DEFAULT'].get('config_file_path','/etc/jsnapy')).encode('utf-8')
185+
186+
elif os.path.isfile(os.path.join(self.config.get('DEFAULT', 'config_file_path', vars={'config_file_path':'/etc/jsnapy'}).encode('utf-8'), conf_file)):
187+
fpath= (self.config.get('DEFAULT', 'config_file_path', vars={'config_file_path':'/etc/jsnapy'})).encode('utf-8')
187188
config_file = open(os.path.join(fpath , conf_file), 'r')
188189
self.main_file = yaml.load(config_file)
189190
else:
@@ -271,7 +272,7 @@ def generate_rpc_reply(self, dev, output_file, hostname, username):
271272
test_files = []
272273
for tfile in self.main_file['tests']:
273274
if not os.path.isfile(tfile):
274-
tfile = os.path.join((self.config['DEFAULT'].get('test_file_path','/etc/jsnapy/testfiles')).encode('utf-8'), tfile)
275+
tfile = os.path.join(self.config.get('DEFAULT', 'test_file_path', vars={'test_file_path':'/etc/jsnapy/testfiles'}).encode('utf-8'), tfile)
275276
if os.path.isfile(tfile):
276277
test_file = open(tfile, 'r')
277278
test_files.append(yaml.load(test_file))
@@ -331,8 +332,8 @@ def login(self, output_file):
331332
file_tag = k['include']
332333
if os.path.isfile(file_tag):
333334
lfile = file_tag
334-
else:
335-
lfile = os.path.join((self.config['DEFAULT'].get('test_file_path','/etc/jsnapy/testfiles')).encode('utf-8'), file_tag)
335+
else:
336+
lfile = os.path.join((self.config.get('DEFAULT', 'test_file_path', vars={'test_file_path':'/etc/jsnapy/testfiles'})).encode('utf-8'), file_tag)
336337
login_file = open(lfile, 'r')
337338
dev_file = yaml.load(login_file)
338339
gp = k.get('group', 'all')
@@ -404,7 +405,7 @@ def connect(self, hostname, username, password, output_file):
404405
dev.close()
405406
if self.args.check is True or self.args.snapcheck is True or self.args.diff is True:
406407
if self.main_file.get("mail") and self.args.diff is not True:
407-
mfile = os.path.join((self.config['DEFAULT'].get('test_file_path','/etc/jsnapy/testfiles')).encode('utf-8'), self.main_file['mail']) \
408+
mfile = os.path.join(self.config.get('DEFAULT', 'test_file_path', vars={'test_file_path':'/etc/jsnapy/testfiles'}).encode('utf-8'), self.main_file['mail']) \
408409
if os.path.isfile(self.main_file['mail']) is False else self.main_file['mail']
409410
if os.path.isfile(mfile):
410411
mail_file = open(mfile, 'r')

lib/jnpr/jsnapy/snap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def generate_snap_file(self, output_file, hostname, name, cmd_format):
5959
return output_file
6060
else:
6161
filename = hostname + '_' + output_file + '_' + name + '.' + cmd_format
62-
output_file = os.path.join( (self.config['DEFAULT'].get('snapshot_path', '/etc/jsnapy/snapshots')).encode('utf-8'), filename)
62+
output_file = os.path.join((self.config.get('DEFAULT', 'snapshot_path', vars={'snapshot_path':'/etc/jsnapy/snapshots'})).encode('utf-8'), filename)
6363
return output_file
6464

6565
def store_in_sqlite(self, db, hostname, username, cmd_rpc_name, reply_format, rpc_reply, snap_name):

lib/jnpr/jsnapy/sqlite_get.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33
import os
44
import logging
55
import colorama
6+
import configparser
67

78

89
class SqliteExtractXml:
910

1011
def __init__(self, db_name):
1112
self.logger_sqlite = logging.getLogger(__name__)
12-
path = os.getcwd()
13-
self.db_filename = os.path.join(path, 'snapshots', db_name)
13+
self.config = configparser.ConfigParser()
14+
self.config.read(os.path.join('/etc','jsnapy','jsnapy.cfg'))
15+
self.db_filename = os.path.join((self.config.get('DEFAULT', 'snapshot_path', vars={'snapshot_path':'/etc/jsnapy/snapshots'})).encode('utf-8') ,db_name)
1416
if not os.path.isfile(self.db_filename):
1517
self.logger_sqlite.error(
1618
colorama.Fore.RED +

0 commit comments

Comments
 (0)