forked from locustio/locust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e017da6
commit 681d22d
Showing
3 changed files
with
51 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,57 @@ | ||
import os, json, logging | ||
|
||
logger = logging.getLogger(__name__) | ||
config_path = '/tests/settings/config.json' | ||
|
||
def read_file(): | ||
""" | ||
Will read the file and return it as a string with tree view. | ||
""" | ||
try: | ||
with open((os.environ['PYTHONPATH'].split(os.pathsep))[-1] + '/tests/settings/config.json', "r") as data_file: | ||
datas = data_file.read() | ||
with open((os.environ['PYTHONPATH'].split(os.pathsep))[-1] + config_path, "r") as data_file: | ||
data = data_file.read() | ||
data_file.close() | ||
return datas | ||
except Exception as err: | ||
logger.info(err) | ||
return "{}" | ||
data = "{}" | ||
return data | ||
|
||
def write_file(stringJSON): | ||
def write_file(string_json): | ||
""" | ||
The `string_json` will overwrite existing configuration. | ||
If the previous configuration doesn't exist, then it will create the file. | ||
""" | ||
status, message = None, None | ||
try: | ||
with open((os.environ['PYTHONPATH'].split(os.pathsep))[-1] + '/tests/settings/config.json', "w") as data_file: | ||
datas = data_file.write(stringJSON) | ||
return True, 'JSON saved' | ||
with open((os.environ['PYTHONPATH'].split(os.pathsep))[-1] + config_path, "w") as data_file: | ||
data_file.write(string_json) | ||
status = True | ||
message = 'Configuration has been saved' | ||
except Exception as err: | ||
logger.info(err) | ||
return False, err | ||
status = False | ||
message = "Can't save the configuration :" + err | ||
return status, message | ||
|
||
class ClientConfiguration: | ||
""" | ||
This class is a handler for data configuration with JSON data structure. | ||
""" | ||
|
||
config_data = None | ||
|
||
def read_json(self): | ||
""" | ||
Will get the data of configuration as JSON. | ||
It reads configuration file once. | ||
""" | ||
if self.config_data is None: | ||
try: | ||
with open((os.environ['PYTHONPATH'].split(os.pathsep))[-1] + config_path, "r") as data_file: | ||
self.config_data = json.load(data_file) | ||
data_file.close() | ||
except Exception as err: | ||
logger.info(err) | ||
self.config_data = json.load({}) | ||
return self.config_data | ||
|
||
def read_JSON(): | ||
try: | ||
with open((os.environ['PYTHONPATH'].split(os.pathsep))[-1] + '/tests/settings/config.json', "r") as data_file: | ||
datas = json.load(data_file) | ||
data_file.close() | ||
return datas | ||
except Exception as err: | ||
logger.info(err) | ||
return "{}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters