Advertisement
Guest User

Untitled

a guest
Dec 5th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. # Copyright Contributors to the fossdriver project.
  2. # SPDX-License-Identifier: BSD-3-Clause OR MIT
  3.  
  4. import json
  5. import logging
  6.  
  7. class FossConfig(object):
  8.  
  9. def __init__(self):
  10. self.serverUrl = ""
  11. self.username = ""
  12. self.password = ""
  13.  
  14. def configure(self, configFilename):
  15. try:
  16. with open(configFilename, "r") as f:
  17. js = json.load(f)
  18.  
  19. # pull out the expected parameters
  20. self.serverUrl = js.get("serverUrl", "")
  21. self.username = js.get("username", "")
  22. self.password = js.get("password", "")
  23.  
  24. # check whether we got everything we expected
  25. isValid = True
  26. if self.serverUrl == "":
  27. logging.error(f"serverUrl not found in config file")
  28. isValid = False
  29. if self.username == "":
  30. logging.error(f"username not found in config file")
  31. isValid = False
  32. if self.password == "":
  33. logging.error(f"password not found in config file")
  34. isValid = False
  35.  
  36. return isValid
  37.  
  38. except json.decoder.JSONDecodeError as e:
  39. logging.error(f"Error loading or parsing {configFilename}: {str(e)}")
  40. return False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement