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

[dav] Rename config file as ~/.bdtrc

parent d3f2f407
No related branches found
No related tags found
1 merge request!99WebDAV support improvements
...@@ -2,8 +2,11 @@ ...@@ -2,8 +2,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import os import os
import re
import configparser import configparser
from distutils.version import StrictVersion
from .log import get_logger, echo_warning, echo_info from .log import get_logger, echo_warning, echo_info
from .deploy import _setup_webdav_client from .deploy import _setup_webdav_client
...@@ -13,25 +16,25 @@ logger = get_logger(__name__) ...@@ -13,25 +16,25 @@ logger = get_logger(__name__)
def _get_config(): 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 global configuration # tries to figure if we can authenticate using a configuration file
cfgs = ["~/.bdt-webdav.cfg"] cfgs = ["~/.bdt.cfg"]
cfgs = [os.path.expanduser(k) for k in cfgs] cfgs = [os.path.expanduser(k) for k in cfgs]
for k in cfgs: for k in cfgs:
if os.path.exists(k): if os.path.exists(k):
data = configparser.ConfigParser() data = configparser.ConfigParser()
data.read(k) data.read(k)
if ( if (
"global" not in data "webdav" not in data
or "server" not in data["global"] or "server" not in data["webdav"]
or "username" not in data["global"] or "username" not in data["webdav"]
or "password" not in data["global"] or "password" not in data["webdav"]
): ):
assert KeyError, ( assert KeyError, (
"The file %s should contain a single " "The file %s should contain a single "
'"global" section with 3 variables defined inside: ' '"dav" section with 3 variables defined inside: '
'"server", "username", "password".' % (k,) '"server", "username", "password".' % (k,)
) )
return data["global"] return data["dav"]
# ask the user for the information, cache credentials for future use # ask the user for the information, cache credentials for future use
retval = dict() retval = dict()
...@@ -41,7 +44,7 @@ def _get_config(): ...@@ -41,7 +44,7 @@ def _get_config():
# record file for the user # record file for the user
data = configparser.ConfigParser() data = configparser.ConfigParser()
data["global"] = retval data["webdav"] = retval
with open(cfgs[0], "w") as f: with open(cfgs[0], "w") as f:
logger.warn('Recorded "%s" configuration file for next queries') logger.warn('Recorded "%s" configuration file for next queries')
data.write(f) data.write(f)
...@@ -124,7 +127,7 @@ def remove_old_beta_packages(client, path, dry_run, pyver=True): ...@@ -124,7 +127,7 @@ def remove_old_beta_packages(client, path, dry_run, pyver=True):
if result is not None: if result is not None:
name += "/" + result.string[:4] name += "/" + result.string[:4]
target = '/'.join(path, f) target = '/'.join((path, f))
info = client.info(target) info = client.info(target)
betas.setdefault(name, []).append( betas.setdefault(name, []).append(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment