Skip to content
Snippets Groups Projects
Commit 021bae58 authored by André Anjos's avatar André Anjos :speech_balloon:
Browse files

[dav] Simplify configuration handling to make it generic for other tasks

parent fea1a0b3
Branches
Tags
1 merge request!194Allows extra pip-installable packages to be installed in every newly created environment
...@@ -10,6 +10,7 @@ from distutils.version import StrictVersion ...@@ -10,6 +10,7 @@ from distutils.version import StrictVersion
import dateutil.parser import dateutil.parser
from .deploy import _setup_webdav_client from .deploy import _setup_webdav_client
from .config import read_config
from .log import echo_normal from .log import echo_normal
from .log import echo_warning from .log import echo_warning
from .log import get_logger from .log import get_logger
...@@ -21,41 +22,31 @@ def _get_config(): ...@@ -21,41 +22,31 @@ def _get_config():
"""Returns a dictionary with server parameters, or ask them to the user""" """Returns a dictionary with server parameters, or ask them to the user"""
# tries to figure if we can authenticate using a configuration file # tries to figure if we can authenticate using a configuration file
cfgs = ["~/.bdtrc"] data = read_config()
cfgs = [os.path.expanduser(k) for k in cfgs]
for k in cfgs: # this does some sort of validation for the "webdav" data...
if os.path.exists(k): if "webdav" in data:
data = configparser.ConfigParser() if ("server" not in data["webdav"]
data.read(k)
if (
"webdav" not in data
or "server" not in data["webdav"]
or "username" not in data["webdav"] or "username" not in data["webdav"]
or "password" not in data["webdav"] or "password" not in data["webdav"]
): ):
assert KeyError, ( raise KeyError(
"The file %s should contain a single " f"If the configuration file {k} contains a \"webdav\" " \
'"webdav" section with 3 variables defined inside: ' f"section, it should contain 3 variables defined inside: " \
'"server", "username", "password".' % (k,) f'"server", "username", "password".'
) )
return data["webdav"] else:
# ask the user for the information, in case nothing available
# ask the user for the information, cache credentials for future use logger.warn("Requesting server information for webDAV operation. " \
retval = dict() "(To create a configuration file, and avoid these, follow " \
retval["server"] = input("The base address of the server: ") "the Setup subsection at our Installation manual.)")
retval["username"] = input("Username: ") webdav_data = dict()
retval["password"] = input("Password: ") webdav_data["server"] = input("The base address of the server: ")
webdav_data["username"] = input("Username: ")
# record file for the user webdav_data["password"] = input("Password: ")
data = configparser.ConfigParser() data["webdav"] = webdav_data
data["webdav"] = retval
with open(cfgs[0], "w") as f: return data["webdav"]
logger.warn('Recorded "%s" configuration file for next queries')
data.write(f)
os.chmod(cfgs[0], 0o600)
logger.warn('Changed mode of "%s" to be read-only to you')
return retval
def setup_webdav_client(private): def setup_webdav_client(private):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment