Commit f2babb12 authored by Julien Muchembled's avatar Julien Muchembled

Expand ~(user) construction for all paths in configuration

Before, it was only done for 'logfile'.
parent 57481c35
...@@ -5,6 +5,9 @@ ...@@ -5,6 +5,9 @@
# See SafeConfigParser at https://docs.python.org/2/library/configparser.html # See SafeConfigParser at https://docs.python.org/2/library/configparser.html
# for more information about the syntax. # for more information about the syntax.
# ~ and ~user constructions are expanded for all paths, even for those that
# may appear in 'database' option.
# Common parameters. # Common parameters.
[DEFAULT] [DEFAULT]
# The cluster name # The cluster name
...@@ -54,7 +57,7 @@ partitions: 12 ...@@ -54,7 +57,7 @@ partitions: 12
[admin] [admin]
bind: 127.0.0.1:9999 bind: 127.0.0.1:9999
# Paths to log files can be specified here, but be careful not to do it in a # Paths to log files can be specified here, but be careful not to do it in a
# common section. ~ and ~user constructions are expanded. # common section.
;logfile: ~/log/admin.log ;logfile: ~/log/admin.log
# Master nodes # Master nodes
......
...@@ -102,7 +102,7 @@ class ConfigurationManager(object): ...@@ -102,7 +102,7 @@ class ConfigurationManager(object):
return self.__get('wait') return self.__get('wait')
def getDynamicMasterList(self): def getDynamicMasterList(self):
return self.__get('dynamic_master_list', optional=True) return self.__getPath('dynamic_master_list', optional=True)
def getAdapter(self): def getAdapter(self):
return self.__get('adapter') return self.__get('adapter')
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import cPickle, pickle, time import cPickle, pickle, time
from bisect import bisect, insort from bisect import bisect, insort
from collections import deque from collections import deque
...@@ -286,7 +287,7 @@ class ImporterDatabaseManager(DatabaseManager): ...@@ -286,7 +287,7 @@ class ImporterDatabaseManager(DatabaseManager):
def _parse(self, database): def _parse(self, database):
config = SafeConfigParser() config = SafeConfigParser()
config.read(database) config.read(os.path.expanduser(database))
sections = config.sections() sections = config.sections()
# XXX: defaults copy & pasted from elsewhere - refactoring needed # XXX: defaults copy & pasted from elsewhere - refactoring needed
main = {'adapter': 'MySQL', 'wait': 0} main = {'adapter': 'MySQL', 'wait': 0}
......
...@@ -21,6 +21,7 @@ from MySQLdb.constants.CR import SERVER_GONE_ERROR, SERVER_LOST ...@@ -21,6 +21,7 @@ from MySQLdb.constants.CR import SERVER_GONE_ERROR, SERVER_LOST
from MySQLdb.constants.ER import DATA_TOO_LONG, DUP_ENTRY from MySQLdb.constants.ER import DATA_TOO_LONG, DUP_ENTRY
from array import array from array import array
from hashlib import sha1 from hashlib import sha1
import os
import re import re
import string import string
import struct import struct
...@@ -57,9 +58,9 @@ class MySQLDatabaseManager(DatabaseManager): ...@@ -57,9 +58,9 @@ class MySQLDatabaseManager(DatabaseManager):
def _parse(self, database): def _parse(self, database):
""" Get the database credentials (username, password, database) """ """ Get the database credentials (username, password, database) """
# expected pattern : [user[:password]@]database[(.|/)unix_socket] # expected pattern : [user[:password]@]database[(~|.|/)unix_socket]
self.user, self.passwd, self.db, self.socket = re.match( self.user, self.passwd, self.db, self.socket = re.match(
'(?:([^:]+)(?::(.*))?@)?([^./]+)(.+)?$', database).groups() '(?:([^:]+)(?::(.*))?@)?([^~./]+)(.+)?$', database).groups()
def close(self): def close(self):
self.conn.close() self.conn.close()
...@@ -69,7 +70,7 @@ class MySQLDatabaseManager(DatabaseManager): ...@@ -69,7 +70,7 @@ class MySQLDatabaseManager(DatabaseManager):
if self.passwd is not None: if self.passwd is not None:
kwd['passwd'] = self.passwd kwd['passwd'] = self.passwd
if self.socket: if self.socket:
kwd['unix_socket'] = self.socket kwd['unix_socket'] = os.path.expanduser(self.socket)
logging.info('connecting to MySQL on the database %s with user %s', logging.info('connecting to MySQL on the database %s with user %s',
self.db, self.user) self.db, self.user)
if self._wait < 0: if self._wait < 0:
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import sqlite3 import sqlite3
from hashlib import sha1 from hashlib import sha1
import string import string
...@@ -70,7 +71,7 @@ class SQLiteDatabaseManager(DatabaseManager): ...@@ -70,7 +71,7 @@ class SQLiteDatabaseManager(DatabaseManager):
self._connect() self._connect()
def _parse(self, database): def _parse(self, database):
self.db = database self.db = os.path.expanduser(database)
def close(self): def close(self):
self.conn.close() self.conn.close()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment