Commit 18658a87 authored by Giorgos Korfiatis's avatar Giorgos Korfiatis
Browse files

Better handling of agkyra dir

parent 3b5e9e63
...@@ -38,8 +38,19 @@ from kamaki.cli.utils import escape_ctrl_chars ...@@ -38,8 +38,19 @@ from kamaki.cli.utils import escape_ctrl_chars
CLOUD_PREFIX = config.CLOUD_PREFIX CLOUD_PREFIX = config.CLOUD_PREFIX
config.HEADER = '# Agkyra configuration file version XXX\n' config.HEADER = '# Agkyra configuration file version XXX\n'
AGKYRA_DIR = os.environ.get('AGKYRA_DIR', os.path.expanduser('~/.agkyra'))
CONFIG_PATH = '%s%sconfig.rc' % (AGKYRA_DIR, os.path.sep) HOME_DIR = os.path.expanduser('~')
DEFAULT_AGKYRA_DIR = os.path.join(HOME_DIR, ".agkyra")
AGKYRA_DIR = os.environ.get('AGKYRA_DIR', DEFAULT_AGKYRA_DIR)
AGKYRA_DIR = os.path.abspath(AGKYRA_DIR)
if os.path.exists(AGKYRA_DIR):
if not os.path.isdir(AGKYRA_DIR):
raise Exception("Cannot create dir '%s'; file exists" % AGKYRA_DIR)
else:
os.mkdir(AGKYRA_DIR)
CONFIG_PATH = os.path.join(AGKYRA_DIR, 'config.rc')
config.CONFIG_PATH = CONFIG_PATH config.CONFIG_PATH = CONFIG_PATH
# neutralize kamaki CONFIG_ENV for this session # neutralize kamaki CONFIG_ENV for this session
config.CONFIG_ENV = '' config.CONFIG_ENV = ''
......
...@@ -19,7 +19,7 @@ import logging ...@@ -19,7 +19,7 @@ import logging
from os.path import abspath from os.path import abspath
from agkyra.syncer import ( from agkyra.syncer import (
syncer, setup, pithos_client, localfs_client, messaging) syncer, setup, pithos_client, localfs_client, messaging)
from agkyra.config import AgkyraConfig from agkyra.config import AgkyraConfig, AGKYRA_DIR
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
...@@ -209,6 +209,7 @@ class WebSocketProtocol(WebSocket): ...@@ -209,6 +209,7 @@ class WebSocketProtocol(WebSocket):
sync, sync,
self.settings['url'], self.settings['token'], self.settings['url'], self.settings['token'],
self.settings['container'], self.settings['directory'], self.settings['container'], self.settings['directory'],
agkyra_path=AGKYRA_DIR,
ignore_ssl=True) ignore_ssl=True)
master = pithos_client.PithosFileClient(syncer_settings) master = pithos_client.PithosFileClient(syncer_settings)
slave = localfs_client.LocalfsFileClient(syncer_settings) slave = localfs_client.LocalfsFileClient(syncer_settings)
......
...@@ -56,9 +56,11 @@ class SyncerSettings(): ...@@ -56,9 +56,11 @@ class SyncerSettings():
self.endpoint = self._get_pithos_client( self.endpoint = self._get_pithos_client(
auth_url, auth_token, container) auth_url, auth_token, container)
self.home_dir = os.path.expanduser('~') home_dir = os.path.expanduser('~')
self.settings_path = join_path(self.home_dir, GLOBAL_SETTINGS_NAME) default_settings_path = join_path(home_dir, GLOBAL_SETTINGS_NAME)
self.settings_path = kwargs.get("agkyra_path", default_settings_path)
self.create_dir(self.settings_path) self.create_dir(self.settings_path)
self.instance_path = join_path(self.settings_path, instance) self.instance_path = join_path(self.settings_path, instance)
self.create_dir(self.instance_path) self.create_dir(self.instance_path)
...@@ -69,7 +71,7 @@ class SyncerSettings(): ...@@ -69,7 +71,7 @@ class SyncerSettings():
self.local_root_path = local_root_path self.local_root_path = local_root_path
self.create_dir(self.local_root_path) self.create_dir(self.local_root_path)
self.cache_name = kwargs.get("cache_path", DEFAULT_CACHE_NAME) self.cache_name = kwargs.get("cache_name", DEFAULT_CACHE_NAME)
self.cache_path = join_path(self.local_root_path, self.cache_name) self.cache_path = join_path(self.local_root_path, self.cache_name)
self.create_dir(self.cache_path) self.create_dir(self.cache_path)
......
...@@ -16,10 +16,12 @@ ...@@ -16,10 +16,12 @@
# 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 os
CURPATH = os.path.dirname(os.path.abspath(__file__))
from agkyra import config
AGKYRA_DIR = config.AGKYRA_DIR
import logging import logging
logfile = os.path.join(CURPATH, 'agkyra.log') logfile = os.path.join(AGKYRA_DIR, 'agkyra.log')
logger = logging.getLogger('agkyra') logger = logging.getLogger('agkyra')
handler = logging.FileHandler(logfile) handler = logging.FileHandler(logfile)
formatter = logging.Formatter("%(levelname)s:%(asctime)s:%(message)s") formatter = logging.Formatter("%(levelname)s:%(asctime)s:%(message)s")
......
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