new commit
This commit is contained in:
37
readjson.py
37
readjson.py
@@ -4,12 +4,7 @@ import argparse
|
||||
import json
|
||||
import os
|
||||
|
||||
from qtpy.QtCore import PYQT_VERSION_STR, QFile, QIODevice, QTemporaryDir
|
||||
from qtpy.QtGui import QColor
|
||||
|
||||
#from pyqtacc.bdbase.enumkind import MsgSeverity
|
||||
#import pyqtacc.bdbase.pyrcc5.qrc_resources
|
||||
|
||||
from qtpy.QtCore import QFile, QTemporaryDir
|
||||
|
||||
class ReadJSON(object):
|
||||
""" Reads three json configuration files.
|
||||
@@ -23,7 +18,7 @@ class ReadJSON(object):
|
||||
json_qrc = ["style", "base", self.appname]
|
||||
|
||||
parser = argparse.ArgumentParser(description="configuration")
|
||||
parser.add_argument("-c", "--config", action="store", dest="style")
|
||||
parser.add_argument("-s", "--style", action="store", dest="style")
|
||||
parser.add_argument("-f", "--facility", action="store", dest="facility")
|
||||
parser.add_argument("-u", "--user", action="store", dest="user")
|
||||
parser.add_argument("-q", "--qss", action="store")
|
||||
@@ -32,7 +27,7 @@ class ReadJSON(object):
|
||||
temp_file = {}
|
||||
self.data = {}
|
||||
|
||||
#Extract style adn facility config files from qrc_resources
|
||||
#Extract style and facility config files from qrc_resources
|
||||
temp_dir = QTemporaryDir()
|
||||
if temp_dir.isValid():
|
||||
for dest in json_qrc[0:2]:
|
||||
@@ -45,6 +40,7 @@ class ReadJSON(object):
|
||||
format(dest))
|
||||
else:
|
||||
print("Invalid temporary directory: {0}".format(temp_dir))
|
||||
|
||||
|
||||
#Overriding config files in qrc_resources with any supplied by user
|
||||
if result.style:
|
||||
@@ -84,15 +80,26 @@ class ReadJSON(object):
|
||||
|
||||
try:
|
||||
with open(temp_file[json_qrc[1]]) as data_file:
|
||||
print(temp_file[json_qrc[1]])
|
||||
self.data_facility = json.load(data_file)
|
||||
for key, val in self.data_facility.items():
|
||||
self.data[key] = val
|
||||
if key in self.data.keys():
|
||||
if hasattr(val, 'items'):
|
||||
for k, v in val.items():
|
||||
#print(key, k, v, type(k), type(v))
|
||||
self.data[key][k] = v
|
||||
else:
|
||||
self.data[key] = val
|
||||
#print(key, val, "////")
|
||||
else:
|
||||
self.data[key] = val
|
||||
#print(key, self.data[key])
|
||||
except IOError:
|
||||
print("Config file: {0} not found".format(
|
||||
temp_file[json_qrc[1]]))
|
||||
|
||||
#Now open user supplied config files
|
||||
|
||||
#Now open user supplied config files
|
||||
json_file = self.appname + ".json"
|
||||
if result.user is not None:
|
||||
if os.path.isfile(result.user):
|
||||
@@ -114,9 +121,13 @@ class ReadJSON(object):
|
||||
#print("======", key, val, type(key), type(val))
|
||||
|
||||
if key in self.data.keys():
|
||||
for k, v in val.items():
|
||||
#print(key, k, v, type(k), type(v))
|
||||
self.data[key][k] = v
|
||||
if hasattr(val, 'items'):
|
||||
for k, v in val.items():
|
||||
#print(key, k, v, type(k), type(v))
|
||||
self.data[key][k] = v
|
||||
else:
|
||||
self.data[key] = val
|
||||
#print(key, val, "////")
|
||||
else:
|
||||
self.data[key] = val
|
||||
except IOError:
|
||||
|
||||
Reference in New Issue
Block a user