Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring loadConfig() #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 28 additions & 10 deletions securepass/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,38 @@
import os
import sys

DEFAULT_CONF_FILENAME = "securepass.conf"

def loadConfig():
"""loadConfig returns cassandra servers"""

conffiles = ['/etc/securepass.conf',
'/usr/local/etc/securepass.conf',
os.getcwd() + '/securepass.conf']
#conffiles.append(os.path.join(os.path.expanduser("~"), ".securepass"))
def _path_to_conffile(*path):
return os.path.join(*(path + (DEFAULT_CONF_FILENAME,)))


## Virtual Environment handling
# VIRTUAL_ENV is not reliable, switching to sys.real_prefix
def _list_conffiles_locations():
prefix = sys.prefix
venv_prefix = None
if hasattr(sys, 'real_prefix'):
conffiles.append(sys.prefix + "/securepass.conf")
conffiles.append(sys.prefix + "/etc/securepass.conf")
prefix = sys.real_prefix
venv_prefix = sys.prefix

conffiles = [
_path_to_conffile(prefix, "etc"),
_path_to_conffile(prefix, "usr", "local", "etc"),
_path_to_conffile(os.getcwd()),
]
if venv_prefix is not None:
conffiles.extend([
_path_to_conffile(venv_prefix),
_path_to_conffile(venv_prefix, "etc"),
])

return conffiles


def loadConfig():
"""loadConfig returns cassandra servers"""

conffiles = _list_conffiles_locations()

conf_found = 0

Expand Down